Scheduling the DefaultLicensedUserCountCache from multiples node in a cluster causes a unique constraint violation on the pk_bb_clusteredjob constraint

XMLWordPrintable

    • Type: Bug
    • Resolution: Not a bug
    • Priority: High
    • None
    • Affects Version/s: 5.3.3, 5.14.1
    • Component/s: None
    • 21
    • Severity 3 - Minor
    • 19

      Summary

      The DefaultLicensedUserCountCache job is scheduled by multiple nodes concurrently, causing Bitbucket to throw a PK_BB_CLUSTEREDJOB unique constraint violated error in the logs.

      Since it is expected that multiple nodes will schedule the job at the same time, the error should not be logged.

      While waiting for this fix, it is safe to ignore this error since there are no impacts on the functionalities.

      Steps to Reproduce

      1. Bitbucket receives an event that triggers the job to be scheduled

      the move to a new delegated user directory can increase the frequency of these errors. In fact, the DefaultLicensedUserCountCache job will be triggered at every login that causes a new user to be created/authorized to access Bitbucket.

      Expected Results

      No errors are returned.

      Actual Results

      The below exception is thrown in the atlassian-bitbucket.log file

      In case of an Oracle database:

      DEBUG [topic-dispatcher:thread-1]  c.a.s.i.l.DefaultLicensedUserCountCache Received cache update 100 from cluster node <node ip> 750 ms since the last recalculation, recalculating in 60000 ms
      INFO  [topic-dispatcher:thread-1]  o.h.e.j.b.internal.AbstractBatchImpl HHH000010: On release of batch it still contained JDBC statements
      ERROR [topic-dispatcher:thread-1]  o.h.e.j.batch.internal.BatchingBatch HHH000315: Exception executing batch [java.sql.BatchUpdateException: ORA-00001: unique constraint (BITBUCKET.PK_BB_CLUSTEREDJOB) violated
      ], SQL: insert into bb_clusteredjob (job_runner_key, next_run, parameters, version, first_run, interval_millis, sched_type, job_id) values (?, ?, ?, ?, ?, ?, 1, ?)
      WARN  [topic-dispatcher:thread-1]  o.h.e.jdbc.spi.SqlExceptionHelper SQL Error: 1, SQLState: 23000
      ERROR [topic-dispatcher:thread-1]  o.h.e.jdbc.spi.SqlExceptionHelper ORA-00001: unique constraint (BITBUCKET.PK_BB_CLUSTEREDJOB) violated
      

      In case of a PostgreSQL database:

      ERROR [hz.hazelcast.event-4]  o.h.e.jdbc.spi.SqlExceptionHelper Batch entry 0 insert into bb_clusteredjob (job_runner_key, next_run, parameters, version, first_run, interval_millis, sched_type, job_id) values ('com.atlassian.stash.internal.license.DefaultLicensedUserCountCache', '2018-01-01 00:00:01.000000+00'::timestamp with time zone, NULL, 1, '2018-01-01 00:00:01.000000+00'::timestamp with time zone, 0, 1, 'DefaultLicensedUserCountCache') was aborted: ERROR: duplicate key value violates unique constraint "pk_bb_clusteredjob"
        Detail: Key (job_id)=(DefaultLicensedUserCountCache) already exists.  Call getNextException to see other errors in the batch.
      WARN  [hz.hazelcast.event-4]  o.h.e.jdbc.spi.SqlExceptionHelper SQL Error: 0, SQLState: 23505
      ERROR [hz.hazelcast.event-4]  o.h.e.jdbc.spi.SqlExceptionHelper ERROR: duplicate key value violates unique constraint "pk_bb_clusteredjob"
        Detail: Key (job_id)=(DefaultLicensedUserCountCache) already exists.
      

      Notes

      When this error occurs, there are no issues with the cluster itself or with nodes unexpectedly leaving the cluster.

      Workaround

      Not available.

            Assignee:
            Unassigned
            Reporter:
            Caterina Curti
            Votes:
            5 Vote for this issue
            Watchers:
            22 Start watching this issue

              Created:
              Updated:
              Resolved: