Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-53722

JdbcSQLException Unique index or primary key violation

      In some edge cases

      ERROR: [withMaven] WARNING Exception executing Maven reporter 'Pipeline Graph Publisher' / org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher. Please report a bug associated for the component 'pipeline-maven-plugin' at https://issues.jenkins-ci.org 
      org.jenkinsci.plugins.pipeline.maven.util.RuntimeSqlException: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "IDX_JENKINS_JOB ON PUBLIC.JENKINS_JOB(JENKINS_MASTER_ID, FULL_NAME) VALUES (1, 'maven-jar-with-flatten-pom/master', 147)"; SQL statement:
      INSERT INTO JENKINS_JOB(FULL_NAME, JENKINS_MASTER_ID) VALUES (?, ?) [23505-196]
      	at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
      	at org.h2.message.DbException.get(DbException.java:179)
      	at org.h2.message.DbException.get(DbException.java:155)
      	at org.h2.index.BaseIndex.getDuplicateKeyException(BaseIndex.java:103)
      	at org.h2.mvstore.db.MVSecondaryIndex.checkUnique(MVSecondaryIndex.java:231)
      	at org.h2.mvstore.db.MVSecondaryIndex.add(MVSecondaryIndex.java:190)
      	at org.h2.mvstore.db.MVTable.addRow(MVTable.java:705)
      	at org.h2.command.dml.Insert.insertRows(Insert.java:156)
      	at org.h2.command.dml.Insert.update(Insert.java:114)
      	at org.h2.command.CommandContainer.update(CommandContainer.java:101)
      	at org.h2.command.Command.executeUpdate(Command.java:260)
      	at org.h2.server.TcpServerThread.process(TcpServerThread.java:354)
      	at org.h2.server.TcpServerThread.run(TcpServerThread.java:158)
      	at java.lang.Thread.run(Thread.java:748)
      
      	at org.jenkinsci.plugins.pipeline.maven.dao.PipelineMavenPluginH2Dao.getOrCreateBuildPrimaryKey(PipelineMavenPluginH2Dao.java:424)
      	at org.jenkinsci.plugins.pipeline.maven.dao.PipelineMavenPluginH2Dao.recordGeneratedArtifact(PipelineMavenPluginH2Dao.java:198)
      	at org.jenkinsci.plugins.pipeline.maven.dao.PipelineMavenPluginMonitoringDao.recordGeneratedArtifact(PipelineMavenPluginMonitoringDao.java:57)
      	at org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher.recordGeneratedArtifacts(PipelineGraphPublisher.java:229)
      	at org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher.process(PipelineGraphPublisher.java:94)
      	at org.jenkinsci.plugins.pipeline.maven.MavenSpyLogProcessor.processMavenSpyLogs(MavenSpyLogProcessor.java:118)
      	at org.jenkinsci.plugins.pipeline.maven.WithMavenStepExecution$WithMavenStepExecutionCallBack.finished(WithMavenStepExecution.java:1050)
      	at org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback$TailCall.onSuccess(BodyExecutionCallback.java:114)
      	at org.jenkinsci.plugins.workflow.cps.CpsBodyExecution$SuccessAdapter.receive(CpsBodyExecution.java:362)
      	at com.cloudbees.groovy.cps.Outcome.resumeFrom(Outcome.java:73)
      	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:166)
      	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
      	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
      	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
      	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:35)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32)
      	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:330)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:242)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:230)
      	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
      	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
      	at java.util.concurrent.FutureTask.run(FutureTask.java)
      	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
      	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
      	at java.util.concurrent.FutureTask.run(FutureTask.java)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      	at java.lang.Thread.run(Thread.java:748)
      Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "IDX_JENKINS_JOB ON PUBLIC.JENKINS_JOB(JENKINS_MASTER_ID, FULL_NAME) VALUES (1, 'maven-jar-with-flatten-pom/master', 147)"; SQL statement:
      INSERT INTO JENKINS_JOB(FULL_NAME, JENKINS_MASTER_ID) VALUES (?, ?) [23505-196]
      	at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
      	at org.h2.message.DbException.get(DbException.java:179)
      	at org.h2.message.DbException.get(DbException.java:155)
      	at org.h2.index.BaseIndex.getDuplicateKeyException(BaseIndex.java:103)
      	at org.h2.mvstore.db.MVSecondaryIndex.checkUnique(MVSecondaryIndex.java:231)
      	at org.h2.mvstore.db.MVSecondaryIndex.add(MVSecondaryIndex.java:190)
      	at org.h2.mvstore.db.MVTable.addRow(MVTable.java:705)
      	at org.h2.command.dml.Insert.insertRows(Insert.java:156)
      	at org.h2.command.dml.Insert.update(Insert.java:114)
      	at org.h2.command.CommandContainer.update(CommandContainer.java:101)
      	at org.h2.command.Command.executeUpdate(Command.java:260)
      	at org.h2.server.TcpServerThread.process(TcpServerThread.java:354)
      	at org.h2.server.TcpServerThread.run(TcpServerThread.java:158)
      	at java.lang.Thread.run(Thread.java:748)
      
      	at org.h2.engine.SessionRemote.done(SessionRemote.java:629)
      	at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:209)
      	at org.h2.jdbc.JdbcPreparedStatement.execute(JdbcPreparedStatement.java:207)
      	at org.jenkinsci.plugins.pipeline.maven.dao.PipelineMavenPluginH2Dao.getOrCreateBuildPrimaryKey(PipelineMavenPluginH2Dao.java:386)
      	... 35 more
      

          [JENKINS-53722] JdbcSQLException Unique index or primary key violation

          benoit guerin added a comment -

          I just get this with the PostGreSQL backend

          09:08:06  org.jenkinsci.plugins.pipeline.maven.util.RuntimeSqlException: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "maven_artifact_pkey"
          09:08:06    Detail: Key (id)=(2151) already exists.
          09:08:06  	at org.jenkinsci.plugins.pipeline.maven.dao.AbstractPipelineMavenPluginDao.getOrCreateArtifactPrimaryKey(AbstractPipelineMavenPluginDao.java:464)
          09:08:06  	at org.jenkinsci.plugins.pipeline.maven.dao.AbstractPipelineMavenPluginDao.recordGeneratedArtifact(AbstractPipelineMavenPluginDao.java:185)
          09:08:06  	at org.jenkinsci.plugins.pipeline.maven.dao.PipelineMavenPluginMonitoringDao.recordGeneratedArtifact(PipelineMavenPluginMonitoringDao.java:61)
          09:08:06  	at org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher.recordGeneratedArtifacts(PipelineGraphPublisher.java:215)
          09:08:06  	at org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher.process(PipelineGraphPublisher.java:94)
          09:08:06  	at org.jenkinsci.plugins.pipeline.maven.MavenSpyLogProcessor.processMavenSpyLogs(MavenSpyLogProcessor.java:154)
          09:08:06  	at org.jenkinsci.plugins.pipeline.maven.WithMavenStepExecution2$WithMavenStepExecutionCallBack.finished(WithMavenStepExecution2.java:1108)
          09:08:06  	at org.jenkinsci.plugins.pipeline.maven.fix.jenkins49337.GeneralNonBlockingStepExecution$TailCall.lambda$onSuccess$0(GeneralNonBlockingStepExecution.java:142)
          09:08:06  	at org.jenkinsci.plugins.pipeline.maven.fix.jenkins49337.GeneralNonBlockingStepExecution.lambda$run$0(GeneralNonBlockingStepExecution.java:85)
          09:08:06  	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
          09:08:06  	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
          09:08:06  	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
          09:08:06  	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
          09:08:06  	at java.base/java.lang.Thread.run(Thread.java:834)
          09:08:06  Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "maven_artifact_pkey"
          09:08:06    Detail: Key (id)=(2151) already exists.
          09:08:06  	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
          09:08:06  	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
          09:08:06  	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
          09:08:06  	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
          09:08:06  	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
          09:08:06  	at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
          09:08:06  	at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:132)
          09:08:06  	at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
          09:08:06  	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
          09:08:06  	at org.jenkinsci.plugins.pipeline.maven.dao.AbstractPipelineMavenPluginDao.getOrCreateArtifactPrimaryKey(AbstractPipelineMavenPluginDao.java:457)
          09:08:06  	... 13 more
          09:08:06  [withMaven] Publishers: Pipeline Graph Publisher: 1 ms
          

          It happened during a release, done "by hand" :

          withMaven {
            sh 'mvn versions:set ...'
            sh 'git commit ...'
            sh 'mvn clean deploy'
            sh 'git tag ...'
            sh 'mvn versions:set ...'
            sh 'git commit ...'
          }

          benoit guerin added a comment - I just get this with the PostGreSQL backend 09:08:06 org.jenkinsci.plugins.pipeline.maven.util.RuntimeSqlException: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "maven_artifact_pkey" 09:08:06 Detail: Key (id)=(2151) already exists. 09:08:06 at org.jenkinsci.plugins.pipeline.maven.dao.AbstractPipelineMavenPluginDao.getOrCreateArtifactPrimaryKey(AbstractPipelineMavenPluginDao.java:464) 09:08:06 at org.jenkinsci.plugins.pipeline.maven.dao.AbstractPipelineMavenPluginDao.recordGeneratedArtifact(AbstractPipelineMavenPluginDao.java:185) 09:08:06 at org.jenkinsci.plugins.pipeline.maven.dao.PipelineMavenPluginMonitoringDao.recordGeneratedArtifact(PipelineMavenPluginMonitoringDao.java:61) 09:08:06 at org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher.recordGeneratedArtifacts(PipelineGraphPublisher.java:215) 09:08:06 at org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher.process(PipelineGraphPublisher.java:94) 09:08:06 at org.jenkinsci.plugins.pipeline.maven.MavenSpyLogProcessor.processMavenSpyLogs(MavenSpyLogProcessor.java:154) 09:08:06 at org.jenkinsci.plugins.pipeline.maven.WithMavenStepExecution2$WithMavenStepExecutionCallBack.finished(WithMavenStepExecution2.java:1108) 09:08:06 at org.jenkinsci.plugins.pipeline.maven.fix.jenkins49337.GeneralNonBlockingStepExecution$TailCall.lambda$onSuccess$0(GeneralNonBlockingStepExecution.java:142) 09:08:06 at org.jenkinsci.plugins.pipeline.maven.fix.jenkins49337.GeneralNonBlockingStepExecution.lambda$run$0(GeneralNonBlockingStepExecution.java:85) 09:08:06 at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) 09:08:06 at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) 09:08:06 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) 09:08:06 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 09:08:06 at java.base/java.lang. Thread .run( Thread .java:834) 09:08:06 Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "maven_artifact_pkey" 09:08:06 Detail: Key (id)=(2151) already exists. 09:08:06 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) 09:08:06 at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) 09:08:06 at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) 09:08:06 at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441) 09:08:06 at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365) 09:08:06 at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143) 09:08:06 at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:132) 09:08:06 at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44) 09:08:06 at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java) 09:08:06 at org.jenkinsci.plugins.pipeline.maven.dao.AbstractPipelineMavenPluginDao.getOrCreateArtifactPrimaryKey(AbstractPipelineMavenPluginDao.java:457) 09:08:06 ... 13 more 09:08:06 [withMaven] Publishers: Pipeline Graph Publisher: 1 ms It happened during a release, done "by hand" : withMaven { sh 'mvn versions:set ...' sh 'git commit ...' sh 'mvn clean deploy' sh 'git tag ...' sh 'mvn versions:set ...' sh 'git commit ...' }

          benoit guerin added a comment -

          Ignore my comment, it was because of a H2 -> PostGreSQL migration. I had jenkins_build (old) entries with id greather than the value of the jenkins_build_sequence sequence

          benoit guerin added a comment - Ignore my comment, it was because of a H2 -> PostGreSQL migration. I had jenkins_build (old) entries with id greather than the value of the jenkins_build_sequence sequence

            Unassigned Unassigned
            cleclerc Cyrille Le Clerc
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: