Repository: spring-projects/spring-batch

Issue #1826: OptimisticLockingFailureException updating step execution after commit failure
Created: 2011-07-07T11:15:42Z
Quinton McCombs opened BATCH-1767 and commented
It appears that if the commit fails, spring batch will get an OptimisticLockingFailureException when it tries to revert the changes to the step execution.  In my particular case, I have a callback through EclipseLink to update history tables before a transaction is committed.  If a failure occurs during this callback, the commit fails.
From looking through the code and the attached log file, the step execution is updated and committed before the main transaction is committed.  When the commit fails, the old values for the step execution (including version) are updated to the values before the chuck started.  When control returns to AbstractStep.execute(), the OptimisticLockingFailureException is thrown when the step execution is updated with the failed status because the new version had already been committed to the database.
2011-07-06 17:40:29,494 ERROR SimpleAsyncTaskExecutor-1 [org.springframework.batch.core.step.AbstractStep] Encountered an error saving batch meta data. This job is now in an unknown state and should not be restarted.
org.springframework.dao.OptimisticLockingFailureException: Attempt to update step execution id=3225 with wrong version (35), where current version is 36
   at org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.updateStepExecution(JdbcStepExecutionDao.java:185)
   at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:171)
   at sun.reflect.GeneratedMethodAccessor130.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy77.update(Unknown Source)
   at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:244)
   at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
   at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
   at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
   at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
   at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
   at org.springframework.batch.core.job.flow.support.state.SplitState$1.call(SplitState.java:91)
   at org.springframework.batch.core.job.flow.support.state.SplitState$1.call(SplitState.java:89)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
   at java.util.concurrent.FutureTask.run(FutureTask.java:138)
   at java.lang.Thread.run(Thread.java:662)


Affects: 2.1.7
Attachments:

BATCH-1767.log.gz (16.78 kB)
log-1.txt (43.41 kB)
scenario.txt (2.96 kB)
spring-batch-bug.zip (11.15 kB)

Referenced from: pull request #591
23 votes, 31 watchers

Duplicate issue #1732: Met OptimisticLockingFailureException when updating a step execution [BATCH-1857]
Created: 2012-05-10T20:02:05Z
benjamin xi opened BATCH-1857 and commented
This excepton didn't appear every time.It seems that Spring was updating the step's version after step finished.According to below logs,the current step's version was 548(want to update to 549) and its version was also 548 in DB.So the update should success.But we met below exception.
05 May 2012 10:21:27 [WAPIBatchScheduler_Worker-1] ERROR org.springframework.batch.core.step.AbstractStep  - Encountered an error saving batch meta data.This job is now in an unknown state and should not be restarted.
org.springframework.dao.OptimisticLockingFailureException: Attempt to update step execution id=1065721 with wrong version (548), where current version is 548
at org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.updateStepExecution(JdbcStepExecutionDao.java:334)
at org.springframework.batch.core.repository.support.SimpleJobRepository.saveOrUpdate(SimpleJobRepository.java:239)
at org.springframework.batch.core.repository.support.SimpleJobRepository.saveOrUpdateExecutionContext(SimpleJobRepository.java:248)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:172)
at org.springframework.batch.core.job.SimpleJob.execute(SimpleJob.java:125)
at com.webex.webapp.wbxconnect.batch.ClassPathXmlApplicationContextJobLocator$ContextClosingJob.execute(ClassPathXmlApplicationContextJobLocator.java:174)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:86)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:81)
at com.webex.webapp.wbxconnect.batch.ClassPathXmlApplicationContextJobLocator.run(ClassPathXmlApplicationContextJobLocator.java:100)
at com.webex.webapp.wbxconnect.executeplugin.batch.SubmitJob.submitJobExecution(SubmitJob.java:420)
at com.webex.webapp.wbxconnect.executeplugin.batch.SubmitJob.submitClusterJobExecution(SubmitJob.java:333)
at com.webex.webapp.wbxconnect.batch.SpringBatchJobInvoker.execute(SpringBatchJobInvoker.java:77)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
05 May 2012 10:21:28 [WAPIBatchScheduler_Worker-1] ERROR com.webex.webapp.wbxconnect.batch.WapiGlobalJobStepListener  - [Z2PJ8VTTIR8XSUTXJJ8BW2EWT9] [dirGrpIntegration] [] An error occurred in Job Execution
org.springframework.batch.core.UnexpectedJobExecutionException: Encountered an error saving batch meta data.
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:218)
at org.springframework.batch.core.job.SimpleJob.execute(SimpleJob.java:125)
at com.webex.webapp.wbxconnect.batch.ClassPathXmlApplicationContextJobLocator$ContextClosingJob.execute(ClassPathXmlApplicationContextJobLocator.java:174)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:86)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:81)
at com.webex.webapp.wbxconnect.batch.ClassPathXmlApplicationContextJobLocator.run(ClassPathXmlApplicationContextJobLocator.java:100)
at com.webex.webapp.wbxconnect.executeplugin.batch.SubmitJob.submitJobExecution(SubmitJob.java:420)
at com.webex.webapp.wbxconnect.executeplugin.batch.SubmitJob.submitClusterJobExecution(SubmitJob.java:333)
at com.webex.webapp.wbxconnect.batch.SpringBatchJobInvoker.execute(SpringBatchJobInvoker.java:77)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)


No further details from BATCH-1857

Closing comment (2021-03-12T19:12:53Z): This is a duplicate of #1826 .