diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java index 61ffef77820d8..eb01fa425dc32 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java @@ -1063,7 +1063,8 @@ public void loadNamespaceTopics(NamespaceBundle bundle) { List> persistentTopics = Lists.newArrayList(); long topicLoadStart = System.nanoTime(); - for (String topic : getNamespaceService().getListOfPersistentTopics(nsName).join()) { + for (String topic : getNamespaceService().getListOfPersistentTopics(nsName). + get(config.getZooKeeperOperationTimeoutSeconds(), TimeUnit.SECONDS)) { try { TopicName topicName = TopicName.get(topic); if (bundle.includes(topicName) && !isTransactionSystemTopic(topicName)) { diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java index 2ba0a09ac5901..3fd6c37cfa4e2 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java @@ -391,7 +391,8 @@ protected void internalDeleteNamespaceForcefully(AsyncResponse asyncResponse, bo List topics; try { - topics = pulsar().getNamespaceService().getFullListOfTopics(namespaceName).join(); + topics = pulsar().getNamespaceService().getFullListOfTopics(namespaceName). + get(config().getZooKeeperOperationTimeoutSeconds(), TimeUnit.SECONDS); } catch (Exception e) { asyncResponse.resume(new RestException(e)); return; @@ -571,7 +572,8 @@ protected void internalDeleteNamespaceBundle(String bundleRange, boolean authori try { NamespaceBundle bundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange, authoritative, true); - List topics = pulsar().getNamespaceService().getListOfPersistentTopics(namespaceName).join(); + List topics = pulsar().getNamespaceService().getListOfPersistentTopics(namespaceName) + .get(config().getZooKeeperOperationTimeoutSeconds(), TimeUnit.SECONDS); for (String topic : topics) { NamespaceBundle topicBundle = pulsar().getNamespaceService() .getBundle(TopicName.get(topic)); diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/NonPersistentTopics.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/NonPersistentTopics.java index daf6ea0a2c3f9..c5d5870642bec 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/NonPersistentTopics.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/NonPersistentTopics.java @@ -28,6 +28,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import javax.ws.rs.DefaultValue; import javax.ws.rs.Encoded; import javax.ws.rs.GET; @@ -297,7 +298,14 @@ public List getListFromBundle(@PathParam("property") String property, @P } private Topic getTopicReference(TopicName topicName) { - return pulsar().getBrokerService().getTopicIfExists(topicName.toString()).join() - .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Topic not found")); + try { + return pulsar().getBrokerService().getTopicIfExists(topicName.toString()) + .get(config().getZooKeeperOperationTimeoutSeconds(), TimeUnit.SECONDS) + .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Topic not found")); + } catch (ExecutionException e) { + throw new RuntimeException(e.getCause()); + } catch (InterruptedException | TimeoutException e) { + throw new RestException(e); + } } } diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/NonPersistentTopics.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/NonPersistentTopics.java index 2cfb20faf4aba..d390049b40576 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/NonPersistentTopics.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/NonPersistentTopics.java @@ -29,6 +29,8 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import javax.ws.rs.DELETE; import javax.ws.rs.DefaultValue; @@ -530,7 +532,14 @@ protected void validateAdminOperationOnTopic(TopicName topicName, boolean author } private Topic getTopicReference(TopicName topicName) { - return pulsar().getBrokerService().getTopicIfExists(topicName.toString()).join() - .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Topic not found")); + try { + return pulsar().getBrokerService().getTopicIfExists(topicName.toString()) + .get(config().getZooKeeperOperationTimeoutSeconds(), TimeUnit.SECONDS) + .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Topic not found")); + } catch (ExecutionException e) { + throw new RestException(e.getCause()); + } catch (InterruptedException | TimeoutException e) { + throw new RestException(e); + } } } diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/OwnershipCache.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/OwnershipCache.java index 116397a94d499..c27575c81a842 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/OwnershipCache.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/OwnershipCache.java @@ -30,7 +30,10 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.apache.bookkeeper.util.ZkUtils; import org.apache.pulsar.broker.PulsarService; import org.apache.pulsar.common.naming.NamespaceBundle; @@ -371,7 +374,13 @@ public boolean isNamespaceBundleOwned(NamespaceBundle bundle) { public OwnedBundle getOwnedBundle(NamespaceBundle bundle) { CompletableFuture future = ownedBundlesCache.getIfPresent(ServiceUnitUtils.path(bundle)); if (future != null && future.isDone() && !future.isCompletedExceptionally()) { - return future.join(); + try { + return future.get(pulsar.getConfiguration().getZooKeeperOperationTimeoutSeconds(), TimeUnit.SECONDS); + } catch (InterruptedException | TimeoutException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e.getCause()); + } } else { return null; } diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBuilderImpl.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBuilderImpl.java index 47f99919d50d4..dba18d93283d6 100644 --- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBuilderImpl.java +++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBuilderImpl.java @@ -24,7 +24,9 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.regex.Pattern; import java.util.stream.Collectors; import lombok.AccessLevel; @@ -122,11 +124,19 @@ public CompletableFuture> subscribeAsync() { //Issue 9327: do compatibility check in case of the default retry and dead letter topic name changed String oldRetryLetterTopic = topicFirst.getNamespace() + "/" + conf.getSubscriptionName() + RetryMessageUtil.RETRY_GROUP_TOPIC_SUFFIX; String oldDeadLetterTopic = topicFirst.getNamespace() + "/" + conf.getSubscriptionName() + RetryMessageUtil.DLQ_GROUP_TOPIC_SUFFIX; - if (client.getPartitionedTopicMetadata(oldRetryLetterTopic).join().partitions > 0) { - retryLetterTopic = oldRetryLetterTopic; - } - if (client.getPartitionedTopicMetadata(oldDeadLetterTopic).join().partitions > 0) { - deadLetterTopic = oldDeadLetterTopic; + try { + if (client.getPartitionedTopicMetadata(oldRetryLetterTopic) + .get(client.conf.getOperationTimeoutMs(), TimeUnit.MILLISECONDS).partitions > 0) { + retryLetterTopic = oldRetryLetterTopic; + } + if (client.getPartitionedTopicMetadata(oldDeadLetterTopic) + .get(client.conf.getOperationTimeoutMs(), TimeUnit.MILLISECONDS).partitions > 0) { + deadLetterTopic = oldDeadLetterTopic; + } + } catch (InterruptedException | TimeoutException e) { + return FutureUtil.failedFuture(e); + } catch (ExecutionException e) { + return FutureUtil.failedFuture(e.getCause()); } if(conf.getDeadLetterPolicy() == null) {