yuqi1129 opened a new pull request, #13006: URL: https://github.com/apache/gravitino/pull/13006
### What changes were proposed in this pull request? Fence the observed Metalake and newly referenced Role IDs in the same transaction as User/Group membership writes. Lock the principal before Roles and acquire Role locks in stable ID order. Use shared locks on MySQL/PostgreSQL and the existing exclusive-lock fallback on H2. Cover update, insert, and overwrite. ### Why are the changes needed? A principal CAS does not detect Role deletion. Role or Metalake deletion can finish membership cleanup before a concurrent grant inserts its relation, leaving an active relation to a deleted endpoint. Metalake fencing must happen before the principal write because its cascade cleans membership rows first. Fix: #13001 ### Does this PR introduce _any_ user-facing change? Grants referencing a deleted, missing, or foreign-metalake Role fail through the existing IllegalRoleException path instead of writing an invalid membership. Stale IDs never retarget same-name replacements. Existing grant/revoke idempotency and overwrite behavior remain; no API signatures, configuration, or storage formats change. Historical orphan cleanup is tracked separately in #13003. ### How was this patch tested? All 27 TestRoleMembershipWrites cases across H2, MySQL, and PostgreSQL and all 8 authorization tests passed. Coverage includes both deletion orders, rollback for invalid batches, missing/deleted/foreign/recreated Roles, insert/overwrite, idempotency, shared-lock concurrency, and Metalake cascades. Core compilation, Spotless, and core check passed. All 65 final H2/authorization regression tests passed across the User, Group, Role, membership-write, and permission-manager suites. git diff --check passed. No full-repository test run was performed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
