mneethiraj commented on code in PR #545: URL: https://github.com/apache/ranger/pull/545#discussion_r2006620536
########## 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); Review Comment: The second attempt to retrieve from the database is indeed reduncent, since the result will be same as the first attempt - given they both are executing the same transaction. The second attempt can be removed. -- 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