bharos commented on code in PR #13957:
URL: https://github.com/apache/gravitino/pull/13957#discussion_r4638265722
##########
scripts/mysql/schema-2.0.0-mysql.sql:
##########
@@ -425,6 +425,18 @@ CREATE TABLE IF NOT EXISTS `policy_tag_relation_meta` (
KEY `policy_tag_relation_meta_idx_tag_id` (`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'policy
tag relation';
+CREATE TABLE IF NOT EXISTS `policy_role_relation_meta` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment
id',
+ `policy_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'policy id',
+ `role_name` VARCHAR(128) NOT NULL COMMENT 'role name referenced by the
policy content',
Review Comment:
Agreed. This table only finds the policies that name a role; it doesn't stop
the name being reused. That needs OQ-3's refusal, plus requiring the role to
exist when a policy names it. I've filed that as #15153, to go into 2.0 with
evaluation.
On reconciliation: `AccessControlContent` hasn't been released and the guard
ships with it in 2.0, so there are no existing policies to reconcile. Agree on
not storing the role ID only here.
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/PolicyMetaService.java:
##########
@@ -429,6 +450,70 @@ private void insertPolicyWithoutCommit(
updatePolicyRootWithVersion(observedIdentifier, existingPolicyPO,
replacementPolicyPO);
insertPolicyVersionIfAllocated(existingPolicyPO, replacementPolicyPO);
afterUpdate(storedPolicy);
+ return replacementPolicyPO.getPolicyId();
+ }
+
+ /**
+ * Brings the role references derived from a policy's content in line with
that content.
+ *
+ * <p>The references are written only here and never by a caller, so {@code
content} stays the one
+ * authority on which roles a policy names.
+ *
+ * <p>Only the difference is written: a reference the content still names
keeps its row, so a
+ * policy edit that leaves {@code applicableRoles} alone writes no reference
rows at all.
+ *
+ * <p>A reference the content drops is deleted rather than soft-deleted, so
no edit leaves a
+ * tombstone behind. Removing a role, naming it again, and removing it once
more therefore cannot
+ * collide on the table's uniqueness over (policy, role, deleted_at), which
the two removals would
+ * otherwise share whenever they read the same millisecond from the database
clock.
+ */
+ private void updateRoleRelationsWithoutCommit(long policyId, PolicyEntity
policyEntity) {
+ List<PolicyRoleRelPO> desired =
POConverters.initializePolicyRoleRelPOs(policyId, policyEntity);
Review Comment:
Agreed. It's in #15153: policy writes check that each named role exists,
single and bulk deletion refuse a referenced role, and both lock the live role
row and recheck it through commit. It includes the two-transaction test with
both commit orders, as you describe.
--
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]