mattisonchao commented on a change in pull request #13846:
URL: https://github.com/apache/pulsar/pull/13846#discussion_r788393831
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
##########
@@ -1044,72 +1044,81 @@ protected void internalDeleteTopic(boolean
authoritative, boolean deleteSchema)
}
protected void internalGetSubscriptions(AsyncResponse asyncResponse,
boolean authoritative) {
+ CompletableFuture<Void> future =
CompletableFuture.completedFuture(null);
Review comment:
Do not initialize ``CompletableFuture`` to avoid waste init.
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
##########
@@ -1044,72 +1044,81 @@ protected void internalDeleteTopic(boolean
authoritative, boolean deleteSchema)
}
protected void internalGetSubscriptions(AsyncResponse asyncResponse,
boolean authoritative) {
+ CompletableFuture<Void> future =
CompletableFuture.completedFuture(null);
if (topicName.isGlobal()) {
- try {
- validateGlobalNamespaceOwnership(namespaceName);
- } catch (Exception e) {
- log.error("[{}] Failed to get subscriptions for topic {}",
clientAppId(), topicName, e);
- resumeAsyncResponseExceptionally(asyncResponse, e);
- return;
- }
+ future = validateGlobalNamespaceOwnershipAsync(namespaceName);
}
-
- validateTopicOwnership(topicName, authoritative);
-
- // If the topic name is a partition name, no need to get partition
topic metadata again
- if (topicName.isPartitioned()) {
- internalGetSubscriptionsForNonPartitionedTopic(asyncResponse,
authoritative);
- } else {
- getPartitionedTopicMetadataAsync(topicName, authoritative,
- false).thenAccept(partitionMetadata -> {
- if (partitionMetadata.partitions > 0) {
- try {
- final Set<String> subscriptions =
Sets.newConcurrentHashSet();
- final List<CompletableFuture<Object>>
subscriptionFutures = Lists.newArrayList();
- if (topicName.getDomain() == TopicDomain.persistent) {
- final Map<Integer, CompletableFuture<Boolean>>
existsFutures = Maps.newConcurrentMap();
- for (int i = 0; i < partitionMetadata.partitions;
i++) {
- existsFutures.put(i,
topicResources().persistentTopicExists(topicName.getPartition(i)));
- }
-
FutureUtil.waitForAll(Lists.newArrayList(existsFutures.values())).thenApply(__
->
- existsFutures.entrySet().stream().filter(e
-> e.getValue().join())
- .map(item ->
topicName.getPartition(item.getKey()).toString())
- .collect(Collectors.toList())
- ).thenAccept(topics -> {
- if (log.isDebugEnabled()) {
- log.debug("activeTopics : {}", topics);
- }
- topics.forEach(topic -> {
- try {
- CompletableFuture<List<String>>
subscriptionsAsync = pulsar().getAdminClient()
-
.topics().getSubscriptionsAsync(topic);
-
subscriptionFutures.add(subscriptionsAsync.thenApply(subscriptions::addAll));
- } catch (PulsarServerException e) {
- throw new RestException(e);
+ future.thenAccept(__ -> validateTopicOwnershipAsync(topicName,
authoritative))
+ .thenAccept(unused -> {
+ // If the topic name is a partition name, no need to get
partition topic metadata again
+ if (topicName.isPartitioned()) {
+
internalGetSubscriptionsForNonPartitionedTopic(asyncResponse, authoritative);
+ } else {
+ getPartitionedTopicMetadataAsync(topicName,
authoritative, false)
+ .thenAccept(partitionMetadata -> {
+ if (partitionMetadata.partitions > 0) {
+ try {
+ final Set<String> subscriptions =
Sets.newConcurrentHashSet();
Review comment:
We need to change this collection to fixed capacity. Avoid useless
scaling.
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
##########
@@ -1044,72 +1044,81 @@ protected void internalDeleteTopic(boolean
authoritative, boolean deleteSchema)
}
protected void internalGetSubscriptions(AsyncResponse asyncResponse,
boolean authoritative) {
+ CompletableFuture<Void> future =
CompletableFuture.completedFuture(null);
if (topicName.isGlobal()) {
- try {
- validateGlobalNamespaceOwnership(namespaceName);
- } catch (Exception e) {
- log.error("[{}] Failed to get subscriptions for topic {}",
clientAppId(), topicName, e);
- resumeAsyncResponseExceptionally(asyncResponse, e);
- return;
- }
+ future = validateGlobalNamespaceOwnershipAsync(namespaceName);
}
-
- validateTopicOwnership(topicName, authoritative);
-
- // If the topic name is a partition name, no need to get partition
topic metadata again
- if (topicName.isPartitioned()) {
- internalGetSubscriptionsForNonPartitionedTopic(asyncResponse,
authoritative);
- } else {
- getPartitionedTopicMetadataAsync(topicName, authoritative,
- false).thenAccept(partitionMetadata -> {
- if (partitionMetadata.partitions > 0) {
- try {
- final Set<String> subscriptions =
Sets.newConcurrentHashSet();
- final List<CompletableFuture<Object>>
subscriptionFutures = Lists.newArrayList();
- if (topicName.getDomain() == TopicDomain.persistent) {
- final Map<Integer, CompletableFuture<Boolean>>
existsFutures = Maps.newConcurrentMap();
- for (int i = 0; i < partitionMetadata.partitions;
i++) {
- existsFutures.put(i,
topicResources().persistentTopicExists(topicName.getPartition(i)));
- }
-
FutureUtil.waitForAll(Lists.newArrayList(existsFutures.values())).thenApply(__
->
- existsFutures.entrySet().stream().filter(e
-> e.getValue().join())
- .map(item ->
topicName.getPartition(item.getKey()).toString())
- .collect(Collectors.toList())
- ).thenAccept(topics -> {
- if (log.isDebugEnabled()) {
- log.debug("activeTopics : {}", topics);
- }
- topics.forEach(topic -> {
- try {
- CompletableFuture<List<String>>
subscriptionsAsync = pulsar().getAdminClient()
-
.topics().getSubscriptionsAsync(topic);
-
subscriptionFutures.add(subscriptionsAsync.thenApply(subscriptions::addAll));
- } catch (PulsarServerException e) {
- throw new RestException(e);
+ future.thenAccept(__ -> validateTopicOwnershipAsync(topicName,
authoritative))
+ .thenAccept(unused -> {
+ // If the topic name is a partition name, no need to get
partition topic metadata again
+ if (topicName.isPartitioned()) {
+
internalGetSubscriptionsForNonPartitionedTopic(asyncResponse, authoritative);
+ } else {
+ getPartitionedTopicMetadataAsync(topicName,
authoritative, false)
+ .thenAccept(partitionMetadata -> {
+ if (partitionMetadata.partitions > 0) {
+ try {
+ final Set<String> subscriptions =
Sets.newConcurrentHashSet();
+ final List<CompletableFuture<Object>>
subscriptionFutures = Lists.newArrayList();
+ if (topicName.getDomain() ==
TopicDomain.persistent) {
+ final Map<Integer,
CompletableFuture<Boolean>> existsFutures =
+ Maps.newConcurrentMap();
+ for (int i = 0; i <
partitionMetadata.partitions; i++) {
+ existsFutures.put(i,
+
topicResources().persistentTopicExists(topicName.getPartition(i)));
+ }
+
FutureUtil.waitForAll(Lists.newArrayList(existsFutures.values()))
+ .thenApply(__ ->
+
existsFutures.entrySet().stream().filter(e -> e.getValue().join())
+ .map(item ->
topicName.getPartition(item.getKey()).toString())
+
.collect(Collectors.toList())
+ ).thenAccept(topics -> {
+ if (log.isDebugEnabled()) {
+ log.debug("activeTopics : {}",
topics);
+ }
+ topics.forEach(topic -> {
+ try {
+
CompletableFuture<List<String>> subscriptionsAsync = pulsar()
+ .getAdminClient()
+
.topics().getSubscriptionsAsync(topic);
+
subscriptionFutures.add(subscriptionsAsync
+
.thenApply(subscriptions::addAll));
+ } catch (PulsarServerException
e) {
+ throw new RestException(e);
+ }
+ });
+ }).thenAccept(__ ->
resumeAsyncResponse(asyncResponse,
+ subscriptions,
subscriptionFutures));
+ } else {
+ for (int i = 0; i <
partitionMetadata.partitions; i++) {
+ CompletableFuture<List<String>>
subscriptionsAsync = pulsar()
+ .getAdminClient().topics()
+
.getSubscriptionsAsync(topicName.getPartition(i).toString());
+
subscriptionFutures.add(subscriptionsAsync
+
.thenApply(subscriptions::addAll));
+ }
+ resumeAsyncResponse(asyncResponse,
subscriptions, subscriptionFutures);
}
- });
- }).thenAccept(__ ->
resumeAsyncResponse(asyncResponse, subscriptions, subscriptionFutures));
- } else {
- for (int i = 0; i < partitionMetadata.partitions;
i++) {
- CompletableFuture<List<String>>
subscriptionsAsync = pulsar().getAdminClient().topics()
-
.getSubscriptionsAsync(topicName.getPartition(i).toString());
-
subscriptionFutures.add(subscriptionsAsync.thenApply(subscriptions::addAll));
+ } catch (Exception e) {
+ log.error("[{}] Failed to get list of
subscriptions for {}",
+ clientAppId(), topicName, e);
+ asyncResponse.resume(e);
+ }
+ } else {
+
internalGetSubscriptionsForNonPartitionedTopic(asyncResponse, authoritative);
}
- resumeAsyncResponse(asyncResponse, subscriptions,
subscriptionFutures);
- }
- } catch (Exception e) {
- log.error("[{}] Failed to get list of subscriptions
for {}", clientAppId(), topicName, e);
- asyncResponse.resume(e);
+ }).exceptionally(ex -> {
+ log.error("[{}] Failed to get subscriptions for
topic {}", clientAppId(), topicName, ex);
+ resumeAsyncResponseExceptionally(asyncResponse,
ex);
+ return null;
+ });
}
- } else {
-
internalGetSubscriptionsForNonPartitionedTopic(asyncResponse, authoritative);
- }
- }).exceptionally(ex -> {
- log.error("[{}] Failed to get subscriptions for topic {}",
clientAppId(), topicName, ex);
- resumeAsyncResponseExceptionally(asyncResponse, ex);
- return null;
- });
- }
+ }).exceptionally(ex -> {
+ Throwable cause = ex.getCause();
+ log.error("[{}] Failed to get subscriptions for topic {}",
clientAppId(), topicName, cause);
Review comment:
``[{}] Failed to validate the global namespace/topic ownership while
get subscriptions for topic {}``
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]