Directory Synchronisation with Crowd fails regarding duplicate entries in database
The directories synchronisation will not work due to duplicate entries in the database. This could be due to a possible corruption with the directory. When you try to synchronise the external directories under Confluence Admin > User Directories, the following appears in the
INFO [http-8443-31] [embedded.admin.list.DirectoriesController] sync User directory synchronisation requested: [ Crowd Server ], type: [ CROWD ] INFO [scheduler_Worker-5] [atlassian.crowd.directory.DbCachingRemoteDirectory] synchroniseCache synchronisation for directory [ xxxx ] starting ERROR [scheduler_Worker-5] [sf.hibernate.util.JDBCExceptionReporter] logExceptions Duplicate entry 'xxxxx' for key 'cwd_unique_user_membership' ERROR [scheduler_Worker-5] [sf.hibernate.impl.SessionImpl] execute Could not synchronize database state with session INFO [scheduler_Worker-5] [atlassian.crowd.directory.DbCachingRemoteDirectory] synchroniseCache failed synchronisation complete in [ 40ms ] ERROR [scheduler_Worker-5] [atlassian.crowd.directory.DbCachingDirectoryPoller] pollChanges Error occurred while refreshing the cache for directory [ xxxxx ]. org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not insert: com.atlassian.crowd.embedded.hibernate2.HibernateMembership#xxxx; SQL ; Duplicate entry 'xxxx' for key 'cwd_unique_user_membership'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'xxxxx' for key 'cwd_unique_user_membership'
A group membership is trying to be synchronised from the remote directory which already exists. When Confluence is trying to add the directory (again) the synchronisation will not be allowed, since duplicate entries are found.
Flushing the cache of the directory will stop the error from happening, and cause the directory to synchronise fully, until the next time a duplicate group membership is sent from the remote directory. The simplest way of forcing this is:
- Disable the directory
- Enable the directory