Issue Summary

      While clustering is enabled, restarting Crowd logs an error since it tries to insert a row that already exists and is unique.

      This is reproducible on Data Center: yes

      Steps to Reproduce

      1. Verify that clustering is enabled from, crowd-home/shared/crowd.cfg.xml
      2. Restart Crowd

      Expected Results

      No errors were written on the logs.

      Actual Results

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

      .2023-11-17 10:06:06,825 Caesium-2-4 ERROR [engine.jdbc.spi.SqlExceptionHelper] Batch entry 0 insert into cwd_cluster_lock (lock_timestamp, node_id, lock_name) values (1700215566819, NULL, 'com.atlassian.crowd.manager.directory.monitor.DirectoryMonitorRefresherJob-lock') was aborted: ERROR: duplicate key value violates unique constraint "cwd_cluster_lock_pkey"
        Detail: Key (lock_name)=(com.atlassian.crowd.manager.directory.monitor.DirectoryMonitorRefresherJob-lock) already exists.  Call getNextException to see other errors in the batch.
      2023-11-17 10:06:06,825 Caesium-2-4 ERROR [engine.jdbc.spi.SqlExceptionHelper] ERROR: duplicate key value violates unique constraint "cwd_cluster_lock_pkey"
        Detail: Key (lock_name)=(com.atlassian.crowd.manager.directory.monitor.DirectoryMonitorRefresherJob-lock) already exists.
      

      Workaround

      When the debug log is enabled we can see that after the above error, it updates the existing entry:

      2023-11-17 10:06:06,840 Caesium-2-4 TRACE [resource.jdbc.internal.ResourceRegistryStandardImpl] Registering statement [com.mchange.v2.c3p0.impl.NewProxyPreparedStatement@bd6c7f3 [wrapping: update cwd_cluster_lock set node_id=?, lock_timestamp=? where lock_name=? and (node_id is null or node_id in (select clusterhea1_.node_id from cwd_cluster_heartbeat clusterhea1_ where clusterhea1_.hearbeat_timestamp<?) or node_id=?)]]
      2023-11-17 10:06:06,840 Caesium-2-4 TRACE [type.descriptor.sql.BasicBinder] binding parameter [1] as [VARCHAR] - [c0092599-9e79-4e5a-9c8c-41cc29468c00]
      2023-11-17 10:06:06,840 Caesium-2-4 TRACE [type.descriptor.sql.BasicBinder] binding parameter [2] as [BIGINT] - [1700215566840]
      2023-11-17 10:06:06,840 Caesium-2-4 TRACE [type.descriptor.sql.BasicBinder] binding parameter [3] as [VARCHAR] - [com.atlassian.crowd.manager.directory.monitor.DirectoryMonitorRefresherJob-lock]
      2023-11-17 10:06:06,840 Caesium-2-4 TRACE [type.descriptor.sql.BasicBinder] binding parameter [4] as [BIGINT] - [1700215266840]
      2023-11-17 10:06:06,840 Caesium-2-4 TRACE [type.descriptor.sql.BasicBinder] binding parameter [5] as [VARCHAR] - [c0092599-9e79-4e5a-9c8c-41cc29468c00]
      

      So we can ignore the error since it's able to update the entry successfully.

            [CWD-6172] Restarting Crowd logs a DB duplicate key error

            Juwin Zam made changes -
            Affects Version/s New: 5.2.3 [ 106529 ]
            Ozhan Aydar made changes -
            Affects Version/s New: 6.0.0 [ 108019 ]
            aanastasov made changes -
            Assignee New: aanastasov [ 8df7baf53f92 ]
            aanastasov made changes -
            Resolution New: Fixed [ 1 ]
            Status Original: Waiting for Release [ 12075 ] New: Closed [ 6 ]
            aanastasov made changes -
            Status Original: In Progress [ 3 ] New: Waiting for Release [ 12075 ]
            aanastasov made changes -
            Fix Version/s New: 5.2.6 [ 108807 ]
            Fix Version/s New: 6.0.1 [ 108891 ]
            Fix Version/s New: 5.3.2 [ 108291 ]
            aanastasov made changes -
            Status Original: Short Term Backlog [ 12074 ] New: In Progress [ 3 ]
            aanastasov made changes -
            Remote Link Original: This issue links to "KRAK-5987 (Bulldog)" [ 924599 ] New: This issue links to "KRAK-5987 (JIRA Server (Bulldog))" [ 924599 ]
            aanastasov made changes -
            Remote Link New: This issue links to "KRAK-5987 (Bulldog)" [ 924599 ]
            SET Analytics Bot made changes -
            UIS Original: 177 New: 155

              8df7baf53f92 aanastasov
              cf398590ce2c Cihan
              Affected customers:
              8 This affects my team
              Watchers:
              19 Start watching this issue

                Created:
                Updated:
                Resolved: