You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by pe...@apache.org on 2020/09/08 02:12:13 UTC

[pulsar] branch master updated: update from zookeeper for available broker one more time if availableBrokers is empty (#7975)

This is an automated email from the ASF dual-hosted git repository.

penghui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ddafdf  update from zookeeper for available broker one more time if availableBrokers is empty (#7975)
9ddafdf is described below

commit 9ddafdf16bc7b24cc2db12a0a1aabff1e66958ac
Author: Aloys <lo...@gmail.com>
AuthorDate: Tue Sep 8 10:12:00 2020 +0800

    update from zookeeper for available broker one more time if availableBrokers is empty (#7975)
    
    Fixes #7476
    
    ### Motivation
    
    In some situations,  discovery service can't find active broker while all brokers are running well.  This PR will update from zookeeper if available broker list is empty to avoid  "No active broker is available"  `RestException` happen.
    
    
    ### Modifications
    
    double check from zookeeper if availableBrokers is empty
---
 .../apache/pulsar/discovery/service/web/ZookeeperCacheLoader.java | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/pulsar-discovery-service/src/main/java/org/apache/pulsar/discovery/service/web/ZookeeperCacheLoader.java b/pulsar-discovery-service/src/main/java/org/apache/pulsar/discovery/service/web/ZookeeperCacheLoader.java
index e1a2cd7..1a6944a 100644
--- a/pulsar-discovery-service/src/main/java/org/apache/pulsar/discovery/service/web/ZookeeperCacheLoader.java
+++ b/pulsar-discovery-service/src/main/java/org/apache/pulsar/discovery/service/web/ZookeeperCacheLoader.java
@@ -28,6 +28,7 @@ import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.bookkeeper.common.util.OrderedScheduler;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.pulsar.common.util.FutureUtil;
 import org.apache.pulsar.common.util.ObjectMapperFactory;
 import org.apache.pulsar.policies.data.loadbalancer.LoadManagerReport;
@@ -124,6 +125,13 @@ public class ZookeeperCacheLoader implements Closeable {
     }
 
     public List<LoadManagerReport> getAvailableBrokers() {
+        if (CollectionUtils.isEmpty(availableBrokers)) {
+            try {
+                updateBrokerList(availableBrokersCache.get());
+            } catch (Exception e) {
+                log.warn("Error updating broker from zookeeper.", e);
+            }
+        }
         return availableBrokers;
     }