spring-projects / spring-projects/spring-batch
Unable to execute again a step that allowStartIfComplete if the status of previous execution is ABANDONED
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 2.5k
- Avg merge
- 6d 53m
- Merged PRs (30d)
- 3
Description
Hi,
I have a job restartable with all step restartable (allowStartIfComplete(true) because i want to be able to re-run from beginning a failed job.
If i raise an exception inside a tasklet in order to fail a step, spring batch save in BATCH_STEP_EXECUTION the step exec with status ABANDONED and exit code FAILED. The job correctly fail.
When i try to launch again a job with that identity params, spring correctly launch again a job but skip the job in ABANDONED status. From my perspective if i raise an exception in tasklet the step status should be FAILED and not ABANDONED.
In this way i m blocked because i m not able to execute again this step when i re-run the job.
In the log i found
`2020-09-14 16:21:55.543 INFO 10504 --- [ scheduling-1] o.s.batch.core.job.SimpleStepHandler : Step already complete or not restartable, so no action to execute: StepExecution: id=208, version=3, name=checkDbConnectionStep, status=ABANDONED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=1, exitDescription=java.lang.RuntimeException: ciaso
`
Checking the source code of spring batch core
org.springframework.batch.core.job.SimpleStepHandler
i found this function
protected boolean shouldStart(StepExecution lastStepExecution, JobExecution jobExecution, Step step) throws JobRestartException, StartLimitExceededException {
BatchStatus stepStatus;
if (lastStepExecution == null) {
stepStatus = BatchStatus.STARTING;
} else {
stepStatus = lastStepExecution.getStatus();
}
if (stepStatus == BatchStatus.UNKNOWN) {
throw new JobRestartException("Cannot restart step from UNKNOWN status. The last execution ended with a failure that could not be rolled back, so it may be dangerous to proceed. Manual intervention is probably necessary.");
} else if ((stepStatus != BatchStatus.COMPLETED || step.isAllowStartIfComplete()) && stepStatus != BatchStatus.ABANDONED) {
if (this.jobRepository.getStepExecutionCount(jobExecution.getJobInstance(), step.getName()) < step.getStartLimit()) {
return true;
} else {
throw new StartLimitExceededException("Maximum start limit exceeded for step: " + step.getName() + "StartMax: " + step.getStartLimit());
}
} else {
logger.info("Step already complete or not restartable, so no action to execute: " + lastStepExecution);
return false;
}
}
from my perspective the condition stepStatus != BatchStatus.ABANDONED should be removed
Environment
Sprin batch 4.2.4 using spring boot 2.3.3.RELEASE
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review org.springframework.batch.core.job.SimpleStepHandler and its shouldStart method, focusing on how ABANDONED and FAILED statuses are assigned and handled during restart. Reproduce the reported Spring Batch 4.2.4 scenario, then establish the intended restart behavior and add regression coverage showing whether an allowStartIfComplete step should execute after an abandoned execution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100