spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

Inaccurate error message when using ResourcelessJobRepository with a partitioned step

Open monnetchr opened this issue 11 months ago • 3 comments

Bug description The ResourcelessJobRepository cannot be used with a Partitioner:

[main] ERROR org.springframework.batch.core.step.AbstractStep - Encountered an error executing step step in job partitionJob
org.springframework.batch.core.JobExecutionException: Cannot restart step from STARTING status.  The old execution may still be executing, so you may need to verify manually that this is the case.

Steps to reproduce Simply change spring-batch-samples/src/main/resources/simple-job-launcher-context.xml to use ResourcelessJobRepository and then run spring-batch-samples/src/test/java/org/springframework/batch/samples/partition/file/PartitionFileJobFunctionalTests.java

monnetchr avatar Dec 10 '24 09:12 monnetchr

The resourceless job repository does not support features involving the execution context (including partitioned steps). This is mentioned in the javadocs of the class: https://docs.spring.io/spring-batch/docs/current/api/org/springframework/batch/core/repository/support/ResourcelessJobRepository.html and in the reference docs here: https://docs.spring.io/spring-batch/reference/whatsnew.html#new-resourceless-job-repository

You need to configure another job repository implementation that supports batch-metadata. I am closing this issue now as I believe it answers your concern, but please add a comment if you need more support on this. Thank you.

fmbenhassine avatar Dec 10 '24 09:12 fmbenhassine

I must admit the error message is confusing, there is no restart in that sample yet the message is mentioning restart. I will re-open this issue and change it into an enhancement.

fmbenhassine avatar Dec 10 '24 11:12 fmbenhassine

Hi @fmbenhassine, I would like to contribute to this issue.

To improve clarity, would it make sense to explicitly prevent the use of ResourcelessJobRepository with partitioned steps by throwing an exception?

Proposed change:

@Override
public Set<StepExecution> split(StepExecution stepExecution, int gridSize) throws JobExecutionException {
    if (jobRepository instanceof ResourcelessJobRepository) {
        throw new JobExecutionException("ResourcelessJobRepository cannot be used with partitioned steps "
                                        + "as it does not support execution context.");
    }
    ...

kwondh5217 avatar Mar 18 '25 12:03 kwondh5217