Crowd upgrade fails with 'Duplicate entry 'xxx' for key 'app_dir_mapping_id'
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Problem
Crowd will not start up after an upgrade. The following appears in the atlassian-crowd.log
2016-09-21 22:30:20,348 localhost-startStop-1 INFO [crowd.upgrade.tasks.UpgradeTask645IntroduceUserPermissions] Group mapping for '<somegroup>' is being added in directory 'somedirectory'
2016-09-21 22:30:20,452 localhost-startStop-1 WARN [engine.jdbc.spi.SqlExceptionHelper] SQL Error: 1062, SQLState: 23000
2016-09-21 22:30:20,453 localhost-startStop-1 ERROR [engine.jdbc.spi.SqlExceptionHelper] Duplicate entry '<somegroup>' for key 'app_dir_mapping_id'
2016-09-21 22:30:20,454 localhost-startStop-1 ERROR [jdbc.batch.internal.BatchingBatch] HHH000315: Exception executing batch [could not perform addBatch]
Diagnosis
Diagnostic Steps
Run the following SQL query to see all the groups in your Crowd instance.
SELECT d.directory_name, g.group_name, COUNT(lower_user_name) FROM cwd_user u
LEFT JOIN cwd_membership m
ON u.id = m.id
LEFT JOIN cwd_directory d
ON u.directory_id = d.id
LEFT JOIN cwd_group g
ON u.directory_id = g.directory_id
GROUP BY d.directory_name, g.group_name
ORDER BY d.directory_name;
SELECT * FROM cwd_group;
SELECT * FROM cwd_directory;
Cause
This error occurs when the default 'crowd-administrator' group does not exist in the Crowd internal directory or another internal directory that was created. A new admin group was created in the internal directory. The upgrade is trying to duplicate the group and errors.
Workaround
You can workaround this issue by following the steps below:
- Add a temporary Crowd administrator group into all of your internal directories where it does not exist. Name it 'crowd-administrators'.
- Assign all of the existing 'admin (role) group members to this newly created crowd-administrators group.
- Add this group to each of your Atlassian Applications, as necessary.
- Delete the problematic _admin_ group from your Crowd instance. This group is identified in the error above.
- Reattempt the upgrade process.
Once you've successfully upgraded, you can execute the following SQL queries to rename back the temporary group to _admin (role) _ as desired:
UPDATE cwd_group SET group_name = 'System Administrator' WHERE group_name = 'crowd-administrators'; UPDATE cwd_group SET lower_group_name = 'system administrator' WHERE lower_group_name = 'crowd-administrators'; UPDATE cwd_app_dir_group_mapping SET group_name = 'System Administrator' WHERE group_name = 'crowd-administrators'; UPDATE cwd_membership SET parent_name = 'System Administrator' WHERE parent_name = 'crowd-administrators'; UPDATE cwd_membership SET lower_parent_name = 'system administrator' WHERE lower_parent_name = 'crowd-administrators';
Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.