Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-5061

Tables for JDBC Batch repository are created twice

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 10.0.0.Beta1
    • None
    • Batch
    • None
    • Hide

      Create a data source to a sybase, oracle, or db2 database and create a JDBC job repository out of it.

      You can also use any other DB where this doesn't cause a failure - in that case, observe these two logs proving that two threads are trying to create the tables:
      15:21:29,508 INFO [org.jberet] (MSC service thread 1-6) JBERET000021: About to initialize batch job repository with ddl-file: sql/jberet-sybase.ddl for database Adaptive Server Enterprise
      15:21:29,508 INFO [org.jberet] (ServerService Thread Pool – 29) JBERET000021: About to initialize batch job repository with ddl-file: sql/jberet-sybase.ddl for database Adaptive Server Enterprise

      Show
      Create a data source to a sybase, oracle, or db2 database and create a JDBC job repository out of it. You can also use any other DB where this doesn't cause a failure - in that case, observe these two logs proving that two threads are trying to create the tables: 15:21:29,508 INFO [org.jberet] (MSC service thread 1-6) JBERET000021: About to initialize batch job repository with ddl-file: sql/jberet-sybase.ddl for database Adaptive Server Enterprise 15:21:29,508 INFO [org.jberet] (ServerService Thread Pool – 29) JBERET000021: About to initialize batch job repository with ddl-file: sql/jberet-sybase.ddl for database Adaptive Server Enterprise

      The constructor of org.wildfly.extension.batch.jberet.job.repository.JdbcJobRepositoryService is called twice: https://github.com/wildfly/wildfly/blob/80247ada8e7daa46660c732c4fc927e26f055d76/batch/extension-jberet/src/main/java/org/wildfly/extension/batch/jberet/job/repository/JdbcJobRepositoryService.java#L69 (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

      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
      

            jmartisk@redhat.com Jan Martiska
            jmartisk@redhat.com Jan Martiska
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: