IN PROGRESS - BATCH-929: Deferrable Constraints cause unrecoverable errors
count non-fatal commit failure as rollback
This commit is contained in:
@@ -297,9 +297,7 @@ public class TaskletStep extends AbstractStep {
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (nonFatalCommitExceptions.classify(e)) {
|
||||
stepExecution.setExecutionContext(getJobRepository().getExecutionContext(stepExecution));
|
||||
JobExecution jobExecution = stepExecution.getJobExecution();
|
||||
jobExecution.setExecutionContext(getJobRepository().getExecutionContext(jobExecution));
|
||||
rollbackExecutionContext(stepExecution);
|
||||
throw new CommitException("non-fatal commit failure", e);
|
||||
}
|
||||
else {
|
||||
@@ -326,10 +324,15 @@ public class TaskletStep extends AbstractStep {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
// if commit failed, calling rollback on tx manager would cause exception
|
||||
// if commit failed, calling rollback on tx manager would
|
||||
// cause exception
|
||||
if (!(e instanceof CommitException)) {
|
||||
processRollback(stepExecution, fatalException, transaction);
|
||||
}
|
||||
else {
|
||||
// assume the failed commit caused rollback
|
||||
stepExecution.rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
@@ -348,6 +351,15 @@ public class TaskletStep extends AbstractStep {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the saved value of ExecutionContext from repository.
|
||||
*/
|
||||
private void rollbackExecutionContext(StepExecution stepExecution) {
|
||||
stepExecution.setExecutionContext(getJobRepository().getExecutionContext(stepExecution));
|
||||
JobExecution jobExecution = stepExecution.getJobExecution();
|
||||
jobExecution.setExecutionContext(getJobRepository().getExecutionContext(jobExecution));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ public class TaskletStepExceptionTests {
|
||||
* status and execution context should be rolled back.
|
||||
*/
|
||||
@Test
|
||||
public void testSkippableCommitError() throws Exception {
|
||||
public void testNonFatalCommitError() throws Exception {
|
||||
|
||||
class TestItemStream extends ItemStreamSupport {
|
||||
private boolean called = false;
|
||||
@@ -240,6 +240,7 @@ public class TaskletStepExceptionTests {
|
||||
assertEquals("step won't refuse to restart", FAILED, stepExecution.getStatus());
|
||||
assertTrue("execution context modified", stream.called);
|
||||
assertTrue("execution context rolled back", stepExecution.getExecutionContext().isEmpty());
|
||||
assertEquals("failed commit counted as rollback", 1, stepExecution.getRollbackCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep
|
||||
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.JobRestartException;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -87,4 +88,12 @@ public class JobRepositorySupport implements JobRepository {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ExecutionContext getExecutionContext(StepExecution stepExecution) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ExecutionContext getExecutionContext(JobExecution jobExecution) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user