mattisonchao commented on a change in pull request #13846:
URL: https://github.com/apache/pulsar/pull/13846#discussion_r789406982
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
##########
@@ -1044,72 +1045,88 @@ protected void internalDeleteTopic(boolean
authoritative, boolean deleteSchema)
}
protected void internalGetSubscriptions(AsyncResponse asyncResponse,
boolean authoritative) {
+ CompletableFuture<Void> future;
if (topicName.isGlobal()) {
- try {
- validateGlobalNamespaceOwnership(namespaceName);
- } catch (Exception e) {
- log.error("[{}] Failed to get subscriptions for topic {}",
clientAppId(), topicName, e);
- resumeAsyncResponseExceptionally(asyncResponse, e);
- return;
- }
- }
-
- 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);
+ future = validateGlobalNamespaceOwnershipAsync(namespaceName);
} 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 = CompletableFuture.completedFuture(null);
+ }
+ 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 =
+ Collections.newSetFromMap(
+ new
ConcurrentHashMap<>(partitionMetadata.partitions));
+ final List<CompletableFuture<Object>>
subscriptionFutures = Lists.newArrayList();
+ if (topicName.getDomain() ==
TopicDomain.persistent) {
+ final Map<Integer,
CompletableFuture<Boolean>> existsFutures =
+ new
ConcurrentHashMap<>(partitionMetadata.partitions);
+ 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);
Review comment:
Well, I think I need to clean up the code after the #13854 work is done
(like checking for duplicates, refactoring some code, etc.).
--
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]