mneethiraj commented on code in PR #545:
URL: https://github.com/apache/ranger/pull/545#discussion_r2006207719


##########
security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java:
##########
@@ -6741,33 +6741,53 @@ public void run() {
             getOrCreateLabel();
         }
 
+        private boolean doesPolicyExist(XXPolicy xPolicy) {
+            return daoMgr.getXXPolicy().getById(xPolicy.getId()) != null;
+        }
+
         private void getOrCreateLabel() {
             LOG.debug("==> AssociatePolicyLabel.getOrCreateLabel(policyId={}, 
label={})", xPolicy.getId(), policyLabel);
 
-            XXPolicyLabel xxPolicyLabel = 
daoMgr.getXXPolicyLabels().findByName(policyLabel);
-
-            if (xxPolicyLabel == null) {
-                xxPolicyLabel = 
daoMgr.getXXPolicyLabels().findByName(policyLabel);
+            if (doesPolicyExist(xPolicy)) {
+                LOG.debug("Searching for policyLabel: {}", policyLabel);
+                XXPolicyLabel xxPolicyLabel = 
daoMgr.getXXPolicyLabels().findByName(policyLabel);
+                LOG.debug("Search returned: {}", xxPolicyLabel);
 
                 if (xxPolicyLabel == null) {
-                    xxPolicyLabel = new XXPolicyLabel();
+                    LOG.debug("Searching again for policyLabel: {}", 
policyLabel);
+                    xxPolicyLabel = 
daoMgr.getXXPolicyLabels().findByName(policyLabel);
+                    LOG.debug("Another Search returned: {}", xxPolicyLabel);
 
-                    xxPolicyLabel.setPolicyLabel(policyLabel);
+                    if (xxPolicyLabel == null) {
+                        LOG.debug("Creating policyLabel: {}", policyLabel);
+                        xxPolicyLabel = new XXPolicyLabel();
 
-                    xxPolicyLabel = 
rangerAuditFields.populateAuditFieldsForCreate(xxPolicyLabel);
-                    xxPolicyLabel = 
daoMgr.getXXPolicyLabels().create(xxPolicyLabel);
+                        xxPolicyLabel.setPolicyLabel(policyLabel);
+
+                        xxPolicyLabel = 
rangerAuditFields.populateAuditFieldsForCreate(xxPolicyLabel);
+                        xxPolicyLabel = 
daoMgr.getXXPolicyLabels().create(xxPolicyLabel);
+                    }
                 }
-            }
 
-            if (xxPolicyLabel != null) {
-                XXPolicyLabelMap xxPolicyLabelMap = new XXPolicyLabelMap();
+                if (xxPolicyLabel != null) {

Review Comment:
   Is `if` at line 6772 necessary? `xxPolicyLabel` should not be null here.



##########
security-admin/src/main/java/org/apache/ranger/common/db/RangerTransactionSynchronizationAdapter.java:
##########
@@ -206,8 +197,17 @@ private void runRunnables(final List<Runnable> runnables, 
final boolean isParent
                             LOG.debug("Failed to commit TransactionService 
transaction, throwable:[{}]", String.valueOf(e));
                         }
                     }
-                }
-                while (isParentTransactionCommitted && 
!isThisTransactionCommitted);
+
+                    isThisTransactionCommitted = result == runnable;

Review Comment:
   Is moving of lines 200 - 209 outside the `try` block necessary?



-- 
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: dev-unsubscr...@ranger.apache.org

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

Reply via email to