mneethiraj commented on code in PR #545: URL: https://github.com/apache/ranger/pull/545#discussion_r2005982771
########## security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java: ########## @@ -6760,14 +6769,25 @@ private void getOrCreateLabel() { } if (xxPolicyLabel != null) { - XXPolicyLabelMap xxPolicyLabelMap = new XXPolicyLabelMap(); + // doing a find to check if the label is already associated with the policy (may happen in concurrent sessions) + List<XXPolicyLabelMap> xxPolicyLabelMapList = daoMgr.getXXPolicyLabelMap().findByPolicyIdAndLabelId(xPolicy.getId(), xxPolicyLabel.getId()); + if (xxPolicyLabelMapList != null && !xxPolicyLabelMapList.isEmpty()) { + LOG.info("Policy with id {} already linked to label with id = {}", xPolicy.getId(), xxPolicyLabel.getId()); + } else { + XXPolicyLabelMap xxPolicyLabelMap = new XXPolicyLabelMap(); - xxPolicyLabelMap.setPolicyId(xPolicy.getId()); - xxPolicyLabelMap.setPolicyLabelId(xxPolicyLabel.getId()); + xxPolicyLabelMap.setPolicyId(xPolicy.getId()); + xxPolicyLabelMap.setPolicyLabelId(xxPolicyLabel.getId()); - xxPolicyLabelMap = rangerAuditFields.populateAuditFieldsForCreate(xxPolicyLabelMap); + xxPolicyLabelMap = rangerAuditFields.populateAuditFieldsForCreate(xxPolicyLabelMap); - daoMgr.getXXPolicyLabelMap().create(xxPolicyLabelMap); + if (doesPolicyExist(xPolicy)) { Review Comment: If the policy doesn't exist, getOrCreateLabel() method should return at the earliest i.e. at line 6750. No label should be created in such case (line 6764. -- 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