lhotari commented on a change in pull request #9850:
URL: https://github.com/apache/pulsar/pull/9850#discussion_r592206657



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
##########
@@ -323,10 +325,11 @@ private void grantPermissions(String topicUri, String 
role, Set<AuthAction> acti
         try {
             namespaceResources().set(path(POLICIES, namespaceName.toString()), 
(policies) -> {
                 if 
(!policies.auth_policies.destination_auth.containsKey(topicUri)) {
-                    policies.auth_policies.destination_auth.put(topicUri, new 
HashMap<>());
+                    policies.auth_policies.destination_auth.put(topicUri, new 
ConcurrentHashMap<>());
                 }
-
-                
policies.auth_policies.destination_auth.get(topicUri).put(role, actions);
+                Set<AuthAction> authActionSet = Collections.newSetFromMap(new 
ConcurrentHashMap<>());
+                authActionSet.addAll(actions);

Review comment:
       I'd recommend using the `Map.compute` method here instead of separate 
lookups and mutations since besides fixing "lost updates", the code is cleaner 
also when concurrency is not a concern.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to