BewareMyPower commented on code in PR #22485:
URL: https://github.com/apache/pulsar/pull/22485#discussion_r1562234371


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/ExtensibleLoadManagerImpl.java:
##########
@@ -496,30 +496,42 @@ public CompletableFuture<Optional<BrokerLookupData>> 
assign(Optional<ServiceUnit
             if (topic.isPresent() && isInternalTopic(topic.get().toString())) {
                 owner = serviceUnitStateChannel.getChannelOwnerAsync();
             } else {
-                String candidateBrokerId = 
getHeartbeatOrSLAMonitorBrokerId(serviceUnit);
-                if (candidateBrokerId != null) {
-                    owner = 
CompletableFuture.completedFuture(Optional.of(candidateBrokerId));
-                } else {
-                    owner = getOrSelectOwnerAsync(serviceUnit, 
bundle).thenApply(Optional::ofNullable);
-                }
+                owner = 
getHeartbeatOrSLAMonitorBrokerId(serviceUnit).thenCompose(candidateBrokerId -> {
+                    if (candidateBrokerId != null) {
+                        return 
CompletableFuture.completedFuture(Optional.of(candidateBrokerId));
+                    }
+                    return getOrSelectOwnerAsync(serviceUnit, 
bundle).thenApply(Optional::ofNullable);
+                });
             }
             return getBrokerLookupData(owner, bundle);
         });
     }
 
-    private String getHeartbeatOrSLAMonitorBrokerId(ServiceUnitId serviceUnit) 
{
+    private CompletableFuture<String> 
getHeartbeatOrSLAMonitorBrokerId(ServiceUnitId serviceUnit) {

Review Comment:
   We can add a `LockManager<BrokerLookupData>` field to `NamespaceService` and 
apply the similar logic of `BrokerRegistryImpl#lookupAsync` to check if the 
broker is alive.
   
   ```java
    this.brokerLookupDataLockManager = 
pulsar.getCoordinationService().getLockManager(BrokerLookupData.class);
   ```



-- 
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-unsubscr...@pulsar.apache.org

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

Reply via email to