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


##########
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:
   For example,
   
   ```java
       public static CompletableFuture<String> getHeartbeatOrSLAMonitorBrokerId(
               ServiceUnitId serviceUnit, LockManager<BrokerLookupData> 
brokerLookupData) {
   ```



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