jerrypeng commented on a change in pull request #5371: fix potential deadlock 
that can occur in addConsumer
URL: https://github.com/apache/pulsar/pull/5371#discussion_r336267491
 
 

 ##########
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
 ##########
 @@ -158,9 +158,13 @@ public synchronized void addConsumer(Consumer consumer) 
throws BrokerServiceExce
     private boolean isConsumersExceededOnTopic() {
         Policies policies;
         try {
+            // Use getDataIfPresent from zk cache to make the call 
non-blocking and prevent deadlocks in addConsumer
             policies = 
topic.getBrokerService().pulsar().getConfigurationCache().policiesCache()
-                    .get(AdminResource.path(POLICIES, 
TopicName.get(topic.getName()).getNamespace()))
-                    .orElseGet(() -> new Policies());
+                    .getDataIfPresent(AdminResource.path(POLICIES, 
TopicName.get(topic.getName()).getNamespace()));
+
+            if (policies == null) {
+                policies = new Policies();
 
 Review comment:
   @rdhabalia I don't think that is correct because we still have to check 
serviceConfig.getMaxConsumersPerTopic() here:
   
   
https://github.com/apache/pulsar/pull/5371/files#diff-5cc001bf2b64aad097762e99c5b78e4aR171

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


With regards,
Apache Git Services

Reply via email to