RANGER-5614 : Performance improvement for role create/update with many users, groups, and sub-roles#980
Open
ramackri wants to merge 6 commits into
Open
RANGER-5614 : Performance improvement for role create/update with many users, groups, and sub-roles#980ramackri wants to merge 6 commits into
ramackri wants to merge 6 commits into
Conversation
added 2 commits
May 26, 2026 16:44
…e users,groups,roles
…e users,groups,roles
…e users,groups,roles
Contributor
Author
…e users,groups,roles
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes Ranger Admin role create/update performance for roles with many users, groups, and sub-roles by reducing DB round-trips and avoiding full ref-table rebuilds on update (mirroring the earlier PolicyRefUpdater refactor).
Changes:
- Refactored
RoleRefUpdaterto support selective ref-table cleanup on update and batch principal resolution + batch inserts. - Added new JPA named queries and DAO helpers to fetch existing role-ref mappings as
name -> refRowIdmaps for selective deletes. - Updated RoleStore API + REST/DBStore/tests to pass a new
isRefTableCleanupRequiredflag.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| security-admin/src/main/java/org/apache/ranger/biz/RoleRefUpdater.java | Selective cleanup + batch insert path; associator refactor. |
| security-admin/src/main/java/org/apache/ranger/biz/RoleDBStore.java | Updated RoleStore method signatures and wiring for new flag. |
| security-admin/src/main/java/org/apache/ranger/rest/RoleREST.java | Passes new cleanup flag for create vs update and role-member endpoints. |
| agents-common/src/main/java/org/apache/ranger/plugin/store/RoleStore.java | RoleStore API updated to include cleanup flag. |
| security-admin/src/main/java/org/apache/ranger/db/XXRoleRefUserDao.java | Added DAO method to fetch username->refRowId map by roleId. |
| security-admin/src/main/java/org/apache/ranger/db/XXRoleRefGroupDao.java | Added DAO method to fetch groupName->refRowId map by roleId. |
| security-admin/src/main/java/org/apache/ranger/db/XXRoleRefRoleDao.java | Added DAO method to fetch subRoleName->refRowId map by roleId. |
| security-admin/src/main/resources/META-INF/jpa_named_queries.xml | Added named queries backing the new DAO map methods. |
| security-admin/src/test/java/org/apache/ranger/biz/TestRoleRefUpdater.java | Updated tests for batch behavior + added selective-cleanup test. |
| security-admin/src/test/java/org/apache/ranger/biz/TestRoleDBStore.java | Updated tests for new RoleStore method signatures. |
| security-admin/src/test/java/org/apache/ranger/rest/TestRoleREST.java | Updated REST tests for new RoleStore method signatures. |
| security-admin/src/test/java/org/apache/ranger/biz/TestPolicyRefUpdater.java | Updated mock RoleStore signature usage. |
| security-admin/src/main/java/org/apache/ranger/biz/PolicyRefUpdater.java | Updated RoleStore call signature when creating roles from policy path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Resolve policyExists once via getById before principal loops to avoid N+1 DB lookups when building policy ref rows for large policies. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What changes were proposed in this pull request?
Optimized
RoleRefUpdaterand related role-ref DAOs so role create/update performs fewer database round-trips when a role references many users, groups, and sub-roles. The design mirrors RANGER-3899 / PR #962 (PolicyRefUpdater).Problem
When creating or updating a role with a large number of principals, Ranger Admin was slow because:
createNewRoleMappingForRefTable()always calledcleanupRefTables(), deleting all rows fromx_role_ref_user,x_role_ref_group, andx_role_ref_role, then re-inserting every principal even when nothing changed.RolePrincipalAssociatortook three collection parameters and populated one of them insidedoAssociate(), which was harder to read and inconsistent with the refactored policy path.Changes
Performance (
RoleRefUpdater)isRefTableCleanupRequiredtocreateNewRoleMappingForRefTable().RoleDBStore,RoleREST):isRefTableCleanupRequired = false— no selective cleanup on empty ref tables.RoleDBStore,RoleREST, add/remove users/groups/roles, import update):true—cleanupRefTablesForUpdate()deletes only principals removed from the role; unchanged principals are not re-inserted.getIdsByUserNames/getIdsByGroupNames/getIdsByRoleNamesandbatchInsert()for new ref rows.cleanupRoleUsers/cleanupRoleGroups/cleanupRoleRolesaccept the DAO as a parameter (same pattern asPolicyRefUpdater).Associator refactor (aligned with PR #962 review)
Replaced
RolePrincipalAssociatorwith three focused inner classes:getRoleRef()createRoleRef(Long)RoleUserAssociatorXXRoleRefUserfor batch insertcreateon transaction commitRoleGroupAssociatorXXRoleRefGroupcreateon transaction commitRoleRoleAssociatorXXRoleRefRolecreateon transaction commitCall-site pattern (same as
PolicyRoleAssociator/PolicyGroupAssociator/PolicyUserAssociator):