Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation says retry limit is item-based, but it behaves as if the limit is chunk-based. #4321

Open
fxpaquette opened this issue Mar 6, 2023 · 2 comments
Labels
status: feedback-provided Issues for which the feedback requested from the reporter was provided

Comments

@fxpaquette
Copy link

fxpaquette commented Mar 6, 2023

Regarding the retry() and retryLimit() method that can be added to a faultTolerantStepBuilder.
Example:

@Bean
public Step step1(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
	return new StepBuilder("step1", jobRepository)
				.<String, String>chunk(2, transactionManager)
				.reader(itemReader())
				.writer(itemWriter())
				.faultTolerant()
				.retryLimit(3)
				.retry(Exception.class)
				.build();
}

The official documentation here specifies that

The Step allows a limit for the number of times an individual item can be retried

First, the retry limit is not actually the number of retries but rather the maximum number of failed tries, since a limit of 1 one will yield no retries.
Second, in the example above, imagine the following scenario (notice the chunk size is 2 and the retry limit is 3):
An error is thrown on the two first tries for item A.
On the third attempt, item A is written succesfully.
Then, an error is thrown for item B.
Observed result: The step fails immediately for having reached the retry limit of 3.

Is the documentation misleading or there is something I am missing here ?

@fxpaquette fxpaquette added the status: waiting-for-triage Issues that we did not analyse yet label Mar 6, 2023
@fmbenhassine
Copy link
Contributor

Thank you for opening this issue. We do not exclude that this could be a bug in Spring Batch. However, we are not sure to reproduce your specific problem by piecing things together from code snippets.

If you would like us to spend some time investigating, please spend some time providing a complete yet minimal example that reproduces the problem. To help you in reporting your issue, we have prepared a project template that you can use as a starting point. Please check the Issue Reporting Guidelines for more details about this. You can also check the chunk-scanning sample here (you might need to adapt it to retry items).

Thank you for your collaboration.

@fmbenhassine fmbenhassine added status: waiting-for-reporter Issues for which we are waiting for feedback from the reporter and removed status: waiting-for-triage Issues that we did not analyse yet labels Apr 3, 2023
@fxpaquette
Copy link
Author

Hi, sorry for the late response. I've included a minimal example to reproduce the observed behavior.

What I am trying to highlight is the fact that the retry limit (3 in my example) is actually chunk-based, rather than item-based as the docs says here

Also, a retry limit of n yields only n-1 retries.

Here is the output of my spring-batch-mcve.zip example:

[main] INFO org.springframework.batch.core.configuration.annotation.BatchRegistrar - Finished Spring Batch infrastructure beans configuration in 18 ms.
[main] INFO org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory - Starting embedded database: url='jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'
[main] INFO org.springframework.batch.core.repository.support.JobRepositoryFactoryBean - No database type set, using meta data indicating: H2
[main] INFO org.springframework.batch.core.configuration.annotation.BatchObservabilityBeanPostProcessor - No Micrometer observation registry found, defaulting to ObservationRegistry.NOOP
[main] INFO org.springframework.batch.core.configuration.annotation.BatchObservabilityBeanPostProcessor - No Micrometer observation registry found, defaulting to ObservationRegistry.NOOP
[main] INFO org.springframework.batch.core.launch.support.SimpleJobLauncher - No TaskExecutor has been set, defaulting to synchronous executor.
[main] INFO org.springframework.batch.core.launch.support.SimpleJobLauncher - Job: [SimpleJob: [name=job]] launched with the following parameters: [{}]
[main] INFO org.springframework.batch.core.job.SimpleStepHandler - Executing step: [step]
reading item = 1
reading item = 2
processing item = 1
processing item = 2
About to write chunk: [items=[1, 2], skips=[]]
About to write item: 1
Throwing exception on item 1 Total: 1 exceptions
processing item = 1
processing item = 2
About to write chunk: [items=[1, 2], skips=[]]
About to write item: 1
Throwing exception on item 1 Total: 2 exceptions
processing item = 1
processing item = 2
About to write chunk: [items=[1, 2], skips=[]]
About to write item: 1
writing item = 1
About to write item: 2
Throwing exception on item 2 Total: 3 exceptions
processing item = 1
[main] ERROR org.springframework.batch.core.step.AbstractStep - Encountered an error executing step step in job job
org.springframework.retry.ExhaustedRetryException: Retry exhausted after last attempt in recovery path, but exception is not skippable. ...
FAILED

@fmbenhassine fmbenhassine added status: feedback-provided Issues for which the feedback requested from the reporter was provided and removed status: waiting-for-reporter Issues for which we are waiting for feedback from the reporter labels May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Issues for which the feedback requested from the reporter was provided
Projects
None yet
Development

No branches or pull requests

2 participants