heesung-sn commented on code in PR #19851:
URL: https://github.com/apache/pulsar/pull/19851#discussion_r1144168023


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java:
##########
@@ -1445,23 +1451,44 @@ public PulsarClientImpl 
getNamespaceClient(ClusterDataImpl cluster) {
         });
     }
 
-    public Optional<NamespaceEphemeralData> getOwner(NamespaceBundle bundle) 
throws Exception {
-        // if there is no znode for the service unit, it is not owned by any 
broker
-        return 
getOwnerAsync(bundle).get(pulsar.getConfiguration().getMetadataStoreOperationTimeoutSeconds(),
 SECONDS);
-    }
-
     public CompletableFuture<Optional<NamespaceEphemeralData>> 
getOwnerAsync(NamespaceBundle bundle) {
+        if (ExtensibleLoadManagerImpl.isLoadManagerExtensionEnabled(config)) {
+            ExtensibleLoadManagerImpl extensibleLoadManager = 
ExtensibleLoadManagerImpl.get(loadManager.get());
+            return 
extensibleLoadManager.getOwnershipWithLookupDataAsync(bundle)
+                    .thenCompose(lookupData -> {
+                        if (lookupData.isPresent()) {
+                            return CompletableFuture.completedFuture(
+                                    
Optional.of(lookupData.get().toNamespaceEphemeralData()));
+                        } else {
+                            return 
CompletableFuture.completedFuture(Optional.empty());
+                        }
+                    });
+        }
         return ownershipCache.getOwnerAsync(bundle);
     }
 
+    public boolean checkOwnershipPresent(NamespaceBundle bundle) throws 
Exception {
+        return checkOwnershipPresentAsync(bundle).get(pulsar.getConfiguration()
+                        .getMetadataStoreOperationTimeoutSeconds(), SECONDS);
+    }
+
+    public CompletableFuture<Boolean> 
checkOwnershipPresentAsync(NamespaceBundle bundle) {
+        if (ExtensibleLoadManagerImpl.isLoadManagerExtensionEnabled(config)) {
+            ExtensibleLoadManagerImpl extensibleLoadManager = 
ExtensibleLoadManagerImpl.get(loadManager.get());
+            return extensibleLoadManager.getOwnershipAsync(Optional.empty(), 
bundle)

Review Comment:
   If we don't pass the `Optional<ServiceUnitId> topic`, I think the ownership 
cannot be found for the load manager system topics (like bsc, broker-load, 
top-bundles-load topics). If this checkOwnershipPresentAsync is not used to  
check the load manager system topics, we are good here.
   
   
   ```
   // example how we use Optional<ServiceUnitId> topic
   private CompletableFuture<Optional<String>> 
getOwnershipAsync(Optional<ServiceUnitId> topic,
                                                                    
ServiceUnitId bundleUnit) {
           final String bundle = bundleUnit.toString();
           CompletableFuture<Optional<String>> owner;
           if (topic.isPresent() && isInternalTopic(topic.get().toString())) {
               owner = serviceUnitStateChannel.getChannelOwnerAsync();
           } else {
               owner = serviceUnitStateChannel.getOwnerAsync(bundle);
           }
           return owner;
   
   ```



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