Spring Batch Partitioned Approach: Multiple batches if triggered together-serialize access due to read/write dependencies among transactions error #4693
-
When multiple batches are getting triggered together getting below error, rg.springframework.dao.CannotAcquireLockException: JDBC commit; ERROR: could not serialize access due to read/write dependencies among transactions Detail: Reason code: Canceled on identification as a pivot, during commit attempt. Hint: The transaction might succeed if retried. at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:115) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79) at org.springframework.jdbc.support.JdbcTransactionManager.translateException(JdbcTransactionManager.java:178) at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:340) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:743) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:660) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:410) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean$1.invoke(AbstractJobRepositoryFactoryBean.java:207) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:244) at jdk.proxy2/jdk.proxy2.$Proxy238.createJobExecution(Unknown Source) at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:145) at org.springframework.batch.core.launch.support.TaskExecutorJobLauncher.run(TaskExecutorJobLauncher.java:59) at com.finastra.retailbanking.essence.febp.service.impl.FebpApplicationJobServiceImpl.triggerApplicationBatchJob(FebpApplicationJobServiceImpl.java:165)
And error is at jobExecution = jobLauncher.run(appJob, appJobParams); |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hi Team, Can someone help here? |
Beta Was this translation helpful? Give feedback.
-
I remember working with you on StackOverflow and did my best to answer your questions in details and with complete working examples (answers that you have accepted):
However, I see you are still struggling with other aspects, which to me, are the same or similar issues that we discussed already. To help you more efficiently, I propose a Zoom session where you can ask your questions live. Is that ok for you? This will be way more efficient than what we have done so far with text on StackOverflow.. Happy to help you move forward on this, because restarting a failed partitioned step should not be that hard (and in my experience, it works pretty well). |
Beta Was this translation helpful? Give feedback.
-
This is similar to Spring Batch - could not serialize access due to read/write dependencies among transactions. You need to lower the isolation level of the transaction at the job repository to Edit: based on previous comments
no, you set it on the job repository factory bean: see setIsolationLevelForCreate Here is an example: @Bean(name = "febpBatchJobRepository")
public JobRepository jobRepository(@Qualifier("febpDataSource") DataSource batchDataSource,
@Qualifier("transactionManager") JdbcTransactionManager batchTransactionManager) throws Exception {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(batchDataSource);
factory.setTransactionManager(batchTransactionManager);
factory.setIsolationLevelForCreate("ISOLATION_REPEATABLE_READ");
factory.afterPropertiesSet();
return factory.getObject();
} |
Beta Was this translation helpful? Give feedback.
This is similar to Spring Batch - could not serialize access due to read/write dependencies among transactions.
You need to lower the isolation level of the transaction at the job repository to
ISOLATION_READ_COMMITTED
(or lower if needed). The reason is that the default value ofISOLATION_SERIALIZABLE
is aggressive for setups where multiple jobs are launched simultaneously (or at a very high frequency).Edit: based on previous comments
no, you set it on the job repository factory bean: see setIsolationLevelForCreate
H…