3232import java .util .concurrent .Semaphore ;
3333import java .util .concurrent .TimeUnit ;
3434import java .util .concurrent .atomic .AtomicInteger ;
35+ import javax .annotation .Nullable ;
3536import lombok .RequiredArgsConstructor ;
3637import org .slf4j .Logger ;
3738import org .slf4j .LoggerFactory ;
@@ -317,16 +318,24 @@ private ImportTransactionBatchResult processTransactionBatch(
317318
318319 } catch (TransactionException e ) {
319320 isSuccess = false ;
320- logger .error (e .getMessage ());
321- try {
322- if (transaction != null ) {
323- transaction .abort (); // Ensure transaction is aborted
324- }
325- } catch (TransactionException abortException ) {
326- logger .error (
327- "Failed to abort transaction: {}" , abortException .getMessage (), abortException );
328- }
321+ logger .error (
322+ "Transaction failed for batch {} in data chunk {}: {}" ,
323+ transactionBatch .getTransactionBatchId (),
324+ dataChunkId ,
325+ e .getMessage (),
326+ e );
327+ abortTransactionSafely (transaction );
329328 error = e .getMessage ();
329+ } catch (Exception e ) {
330+ // Catch unchecked exceptions
331+ isSuccess = false ;
332+ logger .error (
333+ "Unexpected exception occurred while processing transaction batch {} in data chunk {}." ,
334+ transactionBatch .getTransactionBatchId (),
335+ dataChunkId ,
336+ e );
337+ abortTransactionSafely (transaction );
338+ error = "Unexpected error: " + e .getClass ().getSimpleName () + " - " + e .getMessage ();
330339 }
331340 ImportTransactionBatchResult importTransactionBatchResult =
332341 ImportTransactionBatchResult .builder ()
@@ -340,6 +349,22 @@ private ImportTransactionBatchResult processTransactionBatch(
340349 return importTransactionBatchResult ;
341350 }
342351
352+ /**
353+ * Safely aborts the provided distributed transaction. If the transaction is null, this method
354+ * takes no action. If an exception occurs during the abort operation, it is logged as an error.
355+ *
356+ * @param transaction the {@link DistributedTransaction} to be aborted, may be null
357+ */
358+ private void abortTransactionSafely (@ Nullable DistributedTransaction transaction ) {
359+ try {
360+ if (transaction != null ) {
361+ transaction .abort ();
362+ }
363+ } catch (Exception e ) {
364+ logger .error ("Failed to abort transaction: {}" , e .getMessage (), e );
365+ }
366+ }
367+
343368 /**
344369 * Processes a single record in storage mode (non-transactional). Each record is processed
345370 * independently without transaction guarantees.
0 commit comments