Gooch0922 commented on code in PR #538: URL: https://github.com/apache/ranger/pull/538#discussion_r1976543287
########## security-admin/src/main/java/org/apache/ranger/common/RangerRoleCache.java: ########## @@ -69,21 +70,42 @@ public static RangerRoleCache getInstance() { } public RangerRoles getLatestRangerRoleOrCached(String serviceName, RoleDBStore roleDBStore, Long lastKnownRoleVersion, Long rangerRoleVersionInDB) throws Exception { - final RangerRoles ret; + RangerRoles ret = null; if (lastKnownRoleVersion == null || !lastKnownRoleVersion.equals(rangerRoleVersionInDB)) { - roleCacheWrapper = new RangerRoleCacheWrapper(); - ret = roleCacheWrapper.getLatestRangerRoles(serviceName, roleDBStore, lastKnownRoleVersion, rangerRoleVersionInDB); - } else { - ret = null; + ret = roleCacheWrapper.getRoles(); + + if (roleCacheWrapper.getRolesVersion() < rangerRoleVersionInDB) { + boolean lockResult = false; + try { + lockResult = lock.tryLock(waitTimeInSeconds, TimeUnit.SECONDS); + + if (lockResult) { + if (roleCacheWrapper.getRolesVersion() < rangerRoleVersionInDB) { + ret = roleCacheWrapper.getLatestRangerRoles( + serviceName, roleDBStore, lastKnownRoleVersion, rangerRoleVersionInDB); + } Review Comment: The variable "ret" has already been initialized and the cache has been retrieved once at line 76. There is no need to retrieve the cache repeatedly, right? -- 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