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/08/10 07:35:42 UTC

[GitHub] [pulsar] eolivelli commented on a change in pull request #9298: [Issue 9297][broker] Try to fix flaky infinite reconnection

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



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/OwnershipCache.java
##########
@@ -238,7 +239,32 @@ public OwnershipCache(PulsarService pulsar, NamespaceBundleFactory bundleFactory
         }
 
         // If we're not the owner, we need to check if anybody else is
-        return resolveOwnership(path).thenApply(optional -> optional.map(Map.Entry::getKey));
+        CompletableFuture<Optional<NamespaceEphemeralData>> ownerFuture = new CompletableFuture<>();
+        ownershipReadOnlyCache.getAsync(path).whenComplete((owner, ex) -> {
+            if (ex != null) {
+                ownerFuture.completeExceptionally(ex);
+            } else if (!owner.isPresent()) {
+                ownerFuture.complete(Optional.empty());
+            } else {
+                try {
+                    URI ownerURI = new URI(owner.get().getHttpUrl());
+                    String ownerServiceAddr = ownerURI.getHost() + ":" + ownerURI.getPort();
+                    if (pulsar.getLoadManager().get().getAvailableBrokers().contains(ownerServiceAddr)) {
+                        ownerFuture.complete(owner);
+                    } else {
+                        LOG.warn("Namespace {} owned by broker {} which is not active, remove the ownership",
+                                suName.toString(), owner);
+                        removeOwnership(suName);

Review comment:
       here we are in `getOwnerAsync` that is meant to be free from side effects.
   
   I am not sure this is the right fix




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