You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/12/01 14:43:13 UTC

[GitHub] [pulsar] eolivelli commented on a change in pull request #13069: [Broker] Fix and improve topic ownership assignment

eolivelli commented on a change in pull request #13069:
URL: https://github.com/apache/pulsar/pull/13069#discussion_r760250358



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
##########
@@ -622,24 +640,33 @@ private void searchForCandidateBroker(NamespaceBundle bundle,
     }
 
     private boolean isBrokerActive(String candidateBroker) {
-        List<String> brokers = pulsar.getLocalMetadataStore().getChildren(LoadManager.LOADBALANCE_BROKERS_ROOT).join();
-
-        for (String brokerHostPort : brokers) {
-            if (candidateBroker.equals("http://" + brokerHostPort)) {
+        URI uri = URI.create(candidateBroker);
+        String candidateBrokerHostAndPort = uri.getHost() + ":" + uri.getPort();
+        Set<String> availableBrokers = getAvailableBrokers();
+        for (String brokerHostPort : availableBrokers) {
+            if (candidateBrokerHostAndPort.equals(brokerHostPort)) {
                 if (LOG.isDebugEnabled()) {
-                    LOG.debug("Broker {} found for SLA Monitoring Namespace", brokerHostPort);
+                    LOG.debug("Broker {} is available.", brokerHostPort);
                 }
                 return true;
             }
         }
 
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Broker not found for SLA Monitoring Namespace {}",
-                    candidateBroker + ":" + config.getWebServicePort());
+            LOG.debug("Broker {} couldn't be found in available brokers {}",
+                    candidateBroker, availableBrokers);
         }
         return false;
     }
 
+    private Set<String> getAvailableBrokers() {
+        try {
+            return loadManager.get().getAvailableBrokers();
+        } catch (Exception e) {

Review comment:
       can we avoid catching "Exception" ?




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org