Uploaded image for project: 'Bitbucket Data Center'
  1. Bitbucket Data Center
  2. BSERV-13415

Full Active Directory sync fails with constraint violation error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium
    • None
    • 7.21.3
    • Crowd

      Issue Summary

      Active Directory full sync fails with duplicate key error.

      Steps to Reproduce

      1. Use MS AD directory
      2. Incremental synchronization disabled (enable full synchronisation)
      3. New user added to AD
      4. New user has a membership to a group present in AD
      5. Start full synchronisation

      Expected Results

      Synchronisation completes without errors.

      Actual Results

      Synchronisation completes successfully but the below exception is thrown:

      2022-07-21 07:02:33,124 ERROR [Caesium-1-1]  o.h.e.j.batch.internal.BatchingBatch HHH000315: Exception executing batch [java.sql.BatchUpdateException: Batch entry 0 insert into cwd_membership (parent_id, child_id, membership_type, group_type, parent_name, lower_parent_name, child_name, lower_child_name, created_date, directory_id, id) values (7244073, 7407775, 'GROUP_USER', 'GROUP', 'galaxyuser', 'galaxyuser', 'slacadie', 'slacadie', '2022-07-21 07:02:33.117+02'::timestamp, 7340033, 20709378) was aborted: ERROR: duplicate key value violates unique constraint "sys_idx_sys_ct_10168_10170"
        Detail: Key (parent_id, child_id, membership_type)=(7244073, 7407775, GROUP_USER) already exists.  Call getNextException to see other errors in the batch.], SQL: insert into cwd_membership (parent_id, child_id, membership_type, group_type, parent_name, lower_parent_name, child_name, lower_child_name, created_date, directory_id, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
      2022-07-21 07:02:33,125 WARN  [Caesium-1-1]  o.h.e.jdbc.spi.SqlExceptionHelper SQL Error: 0, SQLState: 23505
      2022-07-21 07:02:33,125 ERROR [Caesium-1-1]  o.h.e.jdbc.spi.SqlExceptionHelper Batch entry 0 insert into cwd_membership (parent_id, child_id, membership_type, group_type, parent_name, lower_parent_name, child_name, lower_child_name, created_date, directory_id, id) values (7244073, 7407775, 'GROUP_USER', 'GROUP', 'testuser', 'testuser', 'test1', 'test1', '2022-07-21 07:02:33.117+02'::timestamp, 7340033, 20709378) was aborted: ERROR: duplicate key value violates unique constraint "sys_idx_sys_ct_10168_10170"
        Detail: Key (parent_id, child_id, membership_type)=(7244073, 7407775, GROUP_USER) already exists.  Call getNextException to see other errors in the batch.
      2022-07-21 07:02:33,125 ERROR [Caesium-1-1]  o.h.e.jdbc.spi.SqlExceptionHelper ERROR: duplicate key value violates unique constraint "sys_idx_sys_ct_10168_10170"
        Detail: Key (parent_id, child_id, membership_type)=(7244073, 7407775, GROUP_USER) already exists.
      2022-07-21 07:02:33,129 WARN  [Caesium-1-1]  c.a.c.u.p.h.b.h.Hibernate5StatelessSessionBatchProcessor batch failed falling back to individual processing
      org.hibernate.exception.ConstraintViolationException: could not execute batch
      	at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:109)
      	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
      	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
      	at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:131)
      	at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.addToBatch(BatchingBatch.java:90)
      	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3292)
      	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3825)
      	at org.hibernate.internal.StatelessSessionImpl.insert(StatelessSessionImpl.java:115)
      	at org.hibernate.internal.StatelessSessionImpl.insert(StatelessSessionImpl.java:91)
      	at com.atlassian.crowd.util.persistence.hibernate.batch.hibernate5.operation.StatelessInsertOperation.performOperation(StatelessInsertOperation.java:11)
      	at com.atlassian.crowd.util.persistence.hibernate.batch.hibernate5.operation.StatelessInsertOperation.performOperation(StatelessInsertOperation.java:7)
      	at com.atlassian.crowd.util.persistence.hibernate.batch.AbstractBatchProcessor.performOperation(AbstractBatchProcessor.java:217)
      	at com.atlassian.crowd.util.persistence.hibernate.batch.AbstractBatchProcessor.processBatch(AbstractBatchProcessor.java:156)
      	at com.atlassian.crowd.util.persistence.hibernate.batch.AbstractBatchProcessor.execute(AbstractBatchProcessor.java:125)
      	at com.atlassian.crowd.dao.membership.MembershipDAOHibernate.addAll(MembershipDAOHibernate.java:60)
      	at com.atlassian.crowd.dao.membership.MembershipDAOHibernate.addAllUsersToGroup(MembershipDAOHibernate.java:83)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at com.atlassian.crowd.directory.CachingDirectory.addAllUsersToGroup(CachingDirectory.java:135)
      	at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.addUserMembershipsForGroup(DbCachingRemoteChangeOperations.java:745)
      	at jdk.internal.reflect.GeneratedMethodAccessor1004.invoke(Unknown Source)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at com.atlassian.crowd.directory.DirectoryCacheImplUsingChangeOperations.syncUserMembersForGroup(DirectoryCacheImplUsingChangeOperations.java:116)
      	at com.atlassian.crowd.directory.synchronisation.cache.AbstractCacheRefresher.synchroniseMemberships(AbstractCacheRefresher.java:211)
      	at com.atlassian.stash.internal.crowd.CustomizedUsnChangedCacheRefresher.synchroniseMemberships(CustomizedUsnChangedCacheRefresher.java:83)
      	at com.atlassian.crowd.directory.synchronisation.cache.AbstractCacheRefresher.synchroniseAll(AbstractCacheRefresher.java:56)
      	at com.atlassian.crowd.directory.synchronisation.cache.UsnChangedCacheRefresher.synchroniseAll(UsnChangedCacheRefresher.java:172)
      	at com.atlassian.crowd.directory.DbCachingRemoteDirectory.synchroniseCache(DbCachingRemoteDirectory.java:1095)
      	at com.atlassian.crowd.manager.directory.DirectorySynchroniserImpl.lambda$synchronise$0(DirectorySynchroniserImpl.java:82)
      	at com.atlassian.crowd.audit.NoOpAuditLogContext.withAuditLogSource(NoOpAuditLogContext.java:17)
      	at com.atlassian.crowd.manager.directory.DirectorySynchroniserImpl.synchronise(DirectorySynchroniserImpl.java:80)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at com.atlassian.crowd.directory.DbCachingDirectoryPoller.pollChanges(DbCachingDirectoryPoller.java:48)
      	at com.atlassian.crowd.manager.directory.monitor.poller.DirectoryPollerJobRunner.runJob(DirectoryPollerJobRunner.java:92)
      	at com.atlassian.scheduler.core.JobLauncher.runJob(JobLauncher.java:134)
      	at com.atlassian.scheduler.core.JobLauncher.launchAndBuildResponse(JobLauncher.java:106)
      	at com.atlassian.scheduler.core.JobLauncher.launch(JobLauncher.java:90)
      	at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.launchJob(CaesiumSchedulerService.java:435)
      	at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeClusteredJob(CaesiumSchedulerService.java:430)
      	at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeClusteredJobWithRecoveryGuard(CaesiumSchedulerService.java:454)
      	at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeQueuedJob(CaesiumSchedulerService.java:382)
      	at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.executeJob(SchedulerQueueWorker.java:66)
      	at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.executeNextJob(SchedulerQueueWorker.java:60)
      	at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.run(SchedulerQueueWorker.java:35)
      	at java.base/java.lang.Thread.run(Thread.java:829)
      	... 32 frames trimmed
      Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into cwd_membership (parent_id, child_id, membership_type, group_type, parent_name, lower_parent_name, child_name, lower_child_name, created_date, directory_id, id) values (7244073, 7407775, 'GROUP_USER', 'GROUP', 'testuser', 'testuser', 'test1', 'test1', '2022-07-21 07:02:33.117+02'::timestamp, 7340033, 20709378) was aborted: ERROR: duplicate key value violates unique constraint "sys_idx_sys_ct_10168_10170"
        Detail: Key (parent_id, child_id, membership_type)=(7244073, 7407775, GROUP_USER) already exists.  Call getNextException to see other errors in the batch.
      	at org.postgresql.jdbc.BatchResultHandler.handleError(BatchResultHandler.java:165)
      	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2366)
      	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:559)
      	at org.postgresql.jdbc.PgStatement.internalExecuteBatch(PgStatement.java:887)
      	at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:910)
      	at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1649)
      	at com.zaxxer.hikari.pool.ProxyStatement.executeBatch(ProxyStatement.java:127)
      	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeBatch(HikariProxyPreparedStatement.java)
      	at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:121)
      	... 45 common frames omitted
      	Next exception: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sys_idx_sys_ct_10168_10170"
        Detail: Key (parent_id, child_id, membership_type)=(7244073, 7407775, GROUP_USER) already exists.
      		at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2675)
      		at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2365)
      		at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:559)
      		at org.postgresql.jdbc.PgStatement.internalExecuteBatch(PgStatement.java:887)
      		at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:910)
      		at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1649)
      		at com.zaxxer.hikari.pool.ProxyStatement.executeBatch(ProxyStatement.java:127)
      		at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeBatch(HikariProxyPreparedStatement.java)
      		at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:121)
      		at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.addToBatch(BatchingBatch.java:90)
      		at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3292)
      		at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3825)
      		at org.hibernate.internal.StatelessSessionImpl.insert(StatelessSessionImpl.java:115)
      		at org.hibernate.internal.StatelessSessionImpl.insert(StatelessSessionImpl.java:91)
      		at com.atlassian.crowd.util.persistence.hibernate.batch.hibernate5.operation.StatelessInsertOperation.performOperation(StatelessInsertOperation.java:11)
      		at com.atlassian.crowd.util.persistence.hibernate.batch.hibernate5.operation.StatelessInsertOperation.performOperation(StatelessInsertOperation.java:7)
      		at com.atlassian.crowd.util.persistence.hibernate.batch.AbstractBatchProcessor.performOperation(AbstractBatchProcessor.java:217)
      		at com.atlassian.crowd.util.persistence.hibernate.batch.AbstractBatchProcessor.processBatch(AbstractBatchProcessor.java:156)
      		at com.atlassian.crowd.util.persistence.hibernate.batch.AbstractBatchProcessor.execute(AbstractBatchProcessor.java:125)
      		at com.atlassian.crowd.dao.membership.MembershipDAOHibernate.addAll(MembershipDAOHibernate.java:60)
      		at com.atlassian.crowd.dao.membership.MembershipDAOHibernate.addAllUsersToGroup(MembershipDAOHibernate.java:83)
      		at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      		at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      		at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      		at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      		at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
      		at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
      		at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
      		at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
      		at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
      		at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
      		at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
      		at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
      		at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
      		at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
      		at com.sun.proxy.$Proxy232.addAllUsersToGroup(Unknown Source)
      		at com.atlassian.crowd.directory.CachingDirectory.addAllUsersToGroup(CachingDirectory.java:135)
      		at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.addUserMembershipsForGroup(DbCachingRemoteChangeOperations.java:745)
      		at jdk.internal.reflect.GeneratedMethodAccessor1004.invoke(Unknown Source)
      		at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      		at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      		at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
      		at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
      		at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
      		at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
      		at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
      		at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
      		at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
      		at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
      		at com.sun.proxy.$Proxy2248.addUserMembershipsForGroup(Unknown Source)
      		at com.atlassian.crowd.directory.DirectoryCacheImplUsingChangeOperations.syncUserMembersForGroup(DirectoryCacheImplUsingChangeOperations.java:116)
      		at com.atlassian.crowd.directory.synchronisation.cache.AbstractCacheRefresher.synchroniseMemberships(AbstractCacheRefresher.java:211)
      		at com.atlassian.stash.internal.crowd.CustomizedUsnChangedCacheRefresher.synchroniseMemberships(CustomizedUsnChangedCacheRefresher.java:83)
      		at com.atlassian.crowd.directory.synchronisation.cache.AbstractCacheRefresher.synchroniseAll(AbstractCacheRefresher.java:56)
      		at com.atlassian.crowd.directory.synchronisation.cache.UsnChangedCacheRefresher.synchroniseAll(UsnChangedCacheRefresher.java:172)
      		at com.atlassian.crowd.directory.DbCachingRemoteDirectory.synchroniseCache(DbCachingRemoteDirectory.java:1095)
      		at com.atlassian.crowd.manager.directory.DirectorySynchroniserImpl.lambda$synchronise$0(DirectorySynchroniserImpl.java:82)
      		at com.atlassian.crowd.audit.NoOpAuditLogContext.withAuditLogSource(NoOpAuditLogContext.java:17)
      		at com.atlassian.crowd.manager.directory.DirectorySynchroniserImpl.synchronise(DirectorySynchroniserImpl.java:80)
      		at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      		at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      		at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      		at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      		at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
      		at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
      		at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
      		at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
      		at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
      		at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
      		at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
      		at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
      		at com.sun.proxy.$Proxy249.synchronise(Unknown Source)
      		at com.atlassian.crowd.directory.DbCachingDirectoryPoller.pollChanges(DbCachingDirectoryPoller.java:48)
      		at com.atlassian.crowd.manager.directory.monitor.poller.DirectoryPollerJobRunner.runJob(DirectoryPollerJobRunner.java:92)
      		at com.atlassian.scheduler.core.JobLauncher.runJob(JobLauncher.java:134)
      		at com.atlassian.scheduler.core.JobLauncher.launchAndBuildResponse(JobLauncher.java:106)
      		at com.atlassian.scheduler.core.JobLauncher.launch(JobLauncher.java:90)
      		at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.launchJob(CaesiumSchedulerService.java:435)
      		at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeClusteredJob(CaesiumSchedulerService.java:430)
      		at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeClusteredJobWithRecoveryGuard(CaesiumSchedulerService.java:454)
      		at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeQueuedJob(CaesiumSchedulerService.java:382)
      		at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.executeJob(SchedulerQueueWorker.java:66)
      		at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.executeNextJob(SchedulerQueueWorker.java:60)
      		at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.run(SchedulerQueueWorker.java:35)
      		at java.base/java.lang.Thread.run(Thread.java:829)
      Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sys_idx_sys_ct_10168_10170"
        Detail: Key (parent_id, child_id, membership_type)=(7244073, 7407775, GROUP_USER) already exists.
      	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2675)
      	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2365)
      	... 52 common frames omitted
      

      Workaround

      There is no functional problem - this is just a logging issue. There is currently no way to avoid the error in the logs.

            69efaf67ab3e M Jin
            46ac2648bc84 Naveen
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: