问题
My Spring batch application getting stuck when multiple batches run on same time with huge data. Getting the below exception
Blocked resource ridlock fileid=1 pageid=69265493 dbid=6 id=lock2a36e0c00 mode=X associatedObjectId=72057594039631872
Blocked database *****
Blocking Host (User) ZNAPCDP1842V (myuser)
Blocking application jTDS
Blocking statement N/A
Blocking batch/sp delete from BATCH_STEP_EXECUTION_SEQ where ID < 145678
I am using spring boot version - 1.2.5, Hibernate 4.3.5 I am NOT using XML based configurations
I have the approach described in below link
Multiple Spring Batch jobs executing concurrently causing deadlocks in the Spring Batch metadata tables
As I am using Java based configurations, I have done it as follows
@Configuration
@EnableBatchProcessing(modular=true)
public class AppConfig extends DefaultBatchConfigurer{
@Autowired
DataSource datasource;
@Autowired
PlatformTransactionManager transactionManager;
@Autowired
public void setDataSource(DataSource datasource) {
this.transactionManager = new DataSourceTransactionManager(datasource);
}
@Override
public JobRepository createJobRepository() throws Exception{
setDataSource(this.datasource);
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(datasource);
factory.setTransactionManager(transactionManager);
factory.setIsolationLevelForCreate("ISOLATION_REPEATABLE_READ");
factory.setTablePrefix("BATCH_");
factory.setDatabaseType("SQLSERVER");
factory.setMaxVarCharLength(1000);
return factory.getObject();
}
//Registering my job configuration beans
}
It works till some point and fetches data from most of the hibernate queries, but throws below exception at some point "java.lang.ClassCastException: org.hibernate.action.internal.DelayedPostInsertIdentifier cannot be cast to java.lang.Long"
This time it tries to read data from the below query
@Query("SELECT tb FROM TBodyPart tb " +
"WHERE tb.tPlan=?1 and LTRIM(RTRIM(tb.iBodyPart)) = LTRIM(RTRIM(?2)) and LTRIM(RTRIM(tb.iName))=LTRIM(RTRIM(?3)) and (LTRIM(RTRIM(tb.iOrientation))=LTRIM(RTRIM(?4)) OR tb.iOrientation=?4 )")
public TBodyPart findDetailsMethod(TPlan tPlanId,String bpName,String iName,String iOrientation);
What could be going wrong here?? Why it fetches all other queries fine but throws exception with this one only??
NB: The above query works fine if I remove what I have added in the AppConfig Class to avoid batch stuck issue. (factory.setIsolationLevelForCreate("ISOLATION_REPEATABLE_READ");). I have tried other isolation levels as well
Configuration file before edit
@Configuration
@EnableBatchProcessing(modular=true)
public class AppConfig{
@Bean
public ApplicationContextFactory myJobContext(){
return new GenericApplicationContextFactory(MyJobConfiguration.class);
}
}
After edit
@Autowired
DataSource datasource;
@Autowired
PlatformTransactionManager transactionManager;
@Autowired
public void setDataSource(DataSource datasource) {
this.transactionManager = new DataSourceTransactionManager(datasource);
}
@Override
public JobRepository createJobRepository() throws Exception{
setDataSource(this.datasource);
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(datasource);
factory.setTransactionManager(transactionManager);
factory.setIsolationLevelForCreate("ISOLATION_REPEATABLE_READ");
factory.setTablePrefix("BATCH_");
factory.setDatabaseType("SQLSERVER");
factory.setMaxVarCharLength(10000);
return factory.getObject();
}
}
来源:https://stackoverflow.com/questions/56481045/batch-stuck-due-to-metadata-table-value-deletion