Tables for JDBC Batch repository are created twice
--------------------------------------------------
Key: WFLY-5061
URL:
https://issues.jboss.org/browse/WFLY-5061
Project: WildFly
Issue Type: Bug
Components: Batch
Reporter: Jan Martiska
Assignee: Jan Martiska
Priority: Critical
Fix For: 10.0.0.Beta1
The constructor of
org.wildfly.extension.batch.jberet.job.repository.JdbcJobRepositoryService is called
twice:
https://github.com/wildfly/wildfly/blob/80247ada8e7daa46660c732c4fc927e26...
(both lines 56 and 69 typically get executed). Two threads then race to create the tables.
Some databases can deal with it (those which support IF NOT EXISTS clause in the CREATE
TABLE query). But where this is not used, creating a JDBC Batch repository fails with
{noformat}
15:21:31,526 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 29)
MSC000001: Failed to start service org.wildfy.batch.job.repository.jdbc:
org.jboss.msc.service.StartException in service org.wildfy.batch.job.repository.jdbc:
WFLYBATCH000011: Failed to create JDBC job repository.
at
org.wildfly.extension.batch.jberet.job.repository.JdbcJobRepositoryService.lambda$start$1(JdbcJobRepositoryService.java:59)
at
org.wildfly.extension.batch.jberet.job.repository.JdbcJobRepositoryService$$Lambda$12/1223050080.run(Unknown
Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: javax.batch.operations.BatchRuntimeException: JBERET000624: Failed to create
tables for batch job repository database product name Adaptive Server Enterprise with DDL
sql/jberet-sybase.ddl
at org.jberet.repository.JdbcRepository.createTables(JdbcRepository.java:281)
at org.jberet.repository.JdbcRepository.<init>(JdbcRepository.java:205)
at org.jberet.repository.JdbcRepository.<init>(JdbcRepository.java:167)
at
org.wildfly.extension.batch.jberet.job.repository.JdbcJobRepositoryService.lambda$start$1(JdbcJobRepositoryService.java:56)
... 5 more
Caused by: java.sql.BatchUpdateException: JZ0BE: BatchUpdateException: Error occurred
while executing batch statement: There is already an object named 'JOB_INSTANCE'
in the database.
at com.sybase.jdbc4.jdbc.ErrorMessage.raiseBatchUpdateException(ErrorMessage.java:1300)
at com.sybase.jdbc4.jdbc.SybStatement.batchLoop(SybStatement.java:2134)
at com.sybase.jdbc4.jdbc.SybStatement.sendBatch(SybStatement.java:1924)
at com.sybase.jdbc4.jdbc.SybStatement.executeBatch(SybStatement.java:1882)
at com.sybase.jdbc4.jdbc.SybStatement.executeBatch(SybStatement.java:1691)
at
org.jboss.jca.adapters.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:1174)
at org.jberet.repository.JdbcRepository.createTables(JdbcRepository.java:279)
... 8 more
{noformat}