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

Unique key constraints not working for Embedded Crowd table cwd_membership

    XMLWordPrintable

Details

    Description

      Crowd can generate duplicate rows Crowd for memberships. This causes exceptions when Stash tries to sync with crowd.

      Stash has constraints in cwd_membership.

      org.hibernate.NonUniqueResultException: query did not return a unique result: 2
      	at org.hibernate.internal.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:914) ~[hibernate-core-4.2.5.Final.jar:4.2.5.Final]
      	at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:396) ~[hibernate-core-4.2.5.Final.jar:4.2.5.Final]
      	at com.atlassian.crowd.dao.membership.MembershipDAOHibernate.findInternalMembership(MembershipDAOHibernate.java:356) ~[crowd-persistence-hibernate4-2.7.1-rc.jar:na]
      	at com.atlassian.crowd.dao.membership.MembershipDAOHibernate.isUserDirectMember(MembershipDAOHibernate.java:211) ~[crowd-persistence-hibernate4-2.7.1-rc.jar:na]
      	...
      
      

      Workaround

      Remove and reconnect the affected Crowd directory. More details:
      https://confluence.atlassian.com/display/STASHKB/Unable+to+sync+crowd+user+directory+-+query+did+not+return+a+unique+result

      Additional note

      The fix for this issue inserted the uk_mem_dir_parent_child into a table on our database. After upgrading to versions above that fix, you should get the duplicate records removed from the database and all fixed.

      If your database was in bad shape you could still have a few duplicate records that hadn't been deleted during the upgrade task. This will get your synchronisation failing with the following error:

      2016-08-25 18:07:57,939 ERROR [Caesium-1-4] o.h.e.jdbc.spi.SqlExceptionHelper ERROR: duplicate key value violates unique constraint "uk_mem_dir_parent_child"
      2016-08-25 18:07:57,963 ERROR [Caesium-1-4] c.a.c.d.DbCachingDirectoryPoller Error occurred while refreshing the cache for directory [ 2457601 ].
      org.hibernate.exception.ConstraintViolationException: could not execute statement
      
      

      If you're hitting that, please proceed with the following steps:

      1. Create a copy of your External Directory connection (i.e. LDAP, JIRA, etc) in Administration >> User Directories
      2. Delete the old one
      3. The issue won't return as the constraint will never allow Crowd's bug manifest again.

      Attachments

        Issue Links

          Activity

            People

              jthomas@atlassian.com Justin Thomas
              jgorman James Gorman
              Votes:
              7 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: