merlimat commented on a change in pull request #1527: Reduce un-necessary work 
when doing bundle lookup for partitioned topic
URL: https://github.com/apache/incubator-pulsar/pull/1527#discussion_r181456643
 
 

 ##########
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
 ##########
 @@ -288,38 +295,51 @@ private boolean registerNamespace(String namespace, 
boolean ensureOwned) throws
             LOG.debug("findBrokerServiceUrl: {} - read-only: {}", bundle, 
readOnly);
         }
 
-        CompletableFuture<Optional<LookupResult>> future = new 
CompletableFuture<>();
+        ConcurrentOpenHashMap<NamespaceBundle, 
CompletableFuture<Optional<LookupResult>>> targetMap;
+        if (authoritative) {
+            targetMap = findingBundlesAuth;
+        } else {
+            targetMap = findingBundlesNoAuth;
+        }
 
-        // First check if we or someone else already owns the bundle
-        ownershipCache.getOwnerAsync(bundle).thenAccept(nsData -> {
-            if (!nsData.isPresent()) {
-                // No one owns this bundle
+        return targetMap.computeIfAbsent(bundle, (k) -> {
+            CompletableFuture<Optional<LookupResult>> future = new 
CompletableFuture<>();
 
-                if (readOnly) {
-                    // Do not attempt to acquire ownership
-                    future.complete(Optional.empty());
-                } else {
-                    // Now, no one owns the namespace yet. Hence, we will try 
to dynamically assign it
-                    pulsar.getExecutor().execute(() -> {
-                        searchForCandidateBroker(bundle, future, 
authoritative);
-                    });
-                }
-            } else if (nsData.get().isDisabled()) {
-                future.completeExceptionally(
+            // First check if we or someone else already owns the bundle
+            ownershipCache.getOwnerAsync(bundle).thenAccept(nsData -> {
 
 Review comment:
   My idea was to just convert `owershipCache` value from `OwnedBundle` to a 
`CompletableFuture<OwnedBundle>`. 
   
   The concern here is that `findingBundlesAuth` and `ownershipCache` can be 
out if sync after the removal, since the cleanup is done in background.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to