mchades commented on code in PR #7842:
URL: https://github.com/apache/gravitino/pull/7842#discussion_r2262795188


##########
core/src/main/java/org/apache/gravitino/storage/relational/service/PolicyMetaService.java:
##########
@@ -86,6 +91,24 @@ public void insertPolicy(PolicyEntity policyEntity, boolean 
overwritten) throws
       PolicyPO.Builder builder = PolicyPO.builder().withMetalakeId(metalakeId);
       PolicyPO policyPO = 
POConverters.initializePolicyPOWithVersion(policyEntity, builder);
 
+      List<PolicyPO> diffPolicyPOs = 
getDiffPolicyPOsByMetalakeIdAndPolicy(metalakeId, policyPO);
+      if (!diffPolicyPOs.isEmpty()) {
+        throw new IllegalArgumentException(
+            String.format(
+                "Policy '%s' has inconsistent immutable attributes with 
existing policy '%s' of the same type '%s'. "
+                    + "expected: exclusive=%s, inheritable=%s, 
supportedObjectTypes=%s; "
+                    + "but got: exclusive=%s, inheritable=%s, 
supportedObjectTypes=%s.",
+                policyPO.getPolicyName(),
+                diffPolicyPOs.get(0).getPolicyName(),
+                policyPO.getPolicyType(),
+                diffPolicyPOs.get(0).isExclusive(),
+                diffPolicyPOs.get(0).isInheritable(),
+                diffPolicyPOs.get(0).getSupportedObjectTypes(),
+                policyPO.isExclusive(),
+                policyPO.isInheritable(),
+                policyPO.getSupportedObjectTypes()));
+      }

Review Comment:
   Moving this logic to `PolicyManager` would expose unnecessary methods to 
`policyMetaService` and also require adding a new interface to `JDBCBackend`, 
which is not a standard operation for `RelationalBackend`. So I prefer to keep 
it where it is.



-- 
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: commits-unsubscr...@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to