From cecb4099bb90bcf80d5e1adb50492089e9155e89 Mon Sep 17 00:00:00 2001 From: Cheng Fang Date: Tue, 10 Oct 2023 18:28:11 -0400 Subject: [PATCH] JBERET-597 skippable exception thrown in ItemWriter triggers new chunk within the old transaction --- .../java/org/jberet/runtime/runner/ChunkRunner.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/jberet-core/src/main/java/org/jberet/runtime/runner/ChunkRunner.java b/jberet-core/src/main/java/org/jberet/runtime/runner/ChunkRunner.java index ad89bb1c9..948babd18 100644 --- a/jberet-core/src/main/java/org/jberet/runtime/runner/ChunkRunner.java +++ b/jberet-core/src/main/java/org/jberet/runtime/runner/ChunkRunner.java @@ -640,9 +640,13 @@ private void doCheckpoint(final ProcessingInfo processingInfo) throws Exception stepOrPartitionExecution.setReaderCheckpointInfo(itemReader.checkpointInfo()); stepOrPartitionExecution.setWriterCheckpointInfo(itemWriter.checkpointInfo()); - //usually the transaction should not be rolled back upon skippable exception, but if the transaction - //is marked rollback only by other parties, it's no longer usable and so roll it back. - if (tm.getStatus() == Status.STATUS_MARKED_ROLLBACK || tm.getStatus() == Status.STATUS_ROLLEDBACK) { + //If the transaction is marked rollback only by other parties, it's no longer usable so roll it back. + // + //JBERET-597 (skippable exception thrown in ItemWriter triggers new chunk within the old transaction) + //The skippable exception is from ItemWriter so the current chunk will be skipped. + //There is no reason to keep active transactions as they may linger around after this skipped chunk. + if (tm.getStatus() == Status.STATUS_ACTIVE || + tm.getStatus() == Status.STATUS_MARKED_ROLLBACK || tm.getStatus() == Status.STATUS_ROLLEDBACK) { tm.rollback(); }