Skip to content

Commit 187a809

Browse files
committed
apply suggestions
1 parent 6d25841 commit 187a809

File tree

1 file changed

+18
-18
lines changed
  • data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataimport/processor

1 file changed

+18
-18
lines changed

data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataimport/processor/ImportProcessor.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,7 @@ private ImportTransactionBatchResult processTransactionBatch(
323323
dataChunkId,
324324
e.getMessage(),
325325
e);
326-
try {
327-
if (transaction != null) {
328-
transaction.abort(); // Ensure transaction is aborted
329-
}
330-
} catch (TransactionException abortException) {
331-
logger.error(
332-
"Failed to abort transaction: {}", abortException.getMessage(), abortException);
333-
}
326+
abortTransactionSafely(transaction);
334327
error = e.getMessage();
335328
} catch (Exception e) {
336329
// Catch unchecked exceptions
@@ -340,16 +333,7 @@ private ImportTransactionBatchResult processTransactionBatch(
340333
transactionBatch.getTransactionBatchId(),
341334
dataChunkId,
342335
e);
343-
try {
344-
if (transaction != null) {
345-
transaction.abort(); // Ensure transaction is aborted
346-
}
347-
} catch (Exception abortException) {
348-
logger.error(
349-
"Failed to abort transaction after unexpected error: {}",
350-
abortException.getMessage(),
351-
abortException);
352-
}
336+
abortTransactionSafely(transaction);
353337
error = "Unexpected error: " + e.getClass().getSimpleName() + " - " + e.getMessage();
354338
}
355339
ImportTransactionBatchResult importTransactionBatchResult =
@@ -364,6 +348,22 @@ private ImportTransactionBatchResult processTransactionBatch(
364348
return importTransactionBatchResult;
365349
}
366350

351+
/**
352+
* Safely aborts the provided distributed transaction. If the transaction is null, this method
353+
* takes no action. If an exception occurs during the abort operation, it is logged as an error.
354+
*
355+
* @param transaction the {@link DistributedTransaction} to be aborted, may be null
356+
*/
357+
private void abortTransactionSafely(DistributedTransaction transaction) {
358+
try {
359+
if (transaction != null) {
360+
transaction.abort();
361+
}
362+
} catch (Exception e) {
363+
logger.error("Failed to abort transaction: {}", e.getMessage(), e);
364+
}
365+
}
366+
367367
/**
368368
* Processes a single record in storage mode (non-transactional). Each record is processed
369369
* independently without transaction guarantees.

0 commit comments

Comments
 (0)