mattisonchao commented on a change in pull request #13846:
URL: https://github.com/apache/pulsar/pull/13846#discussion_r790530593



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

Review comment:
       ``validateTopicOwnershipAsync `` has it's own ``exceptionally`` process. 
   
   It's a little weird, but it looks good so far. Since this is a common 
approach, I may need to refactor ``validateTopicOwnershipAsync`` after all PRs 
related to this issue have been merged.
   
   What do you think about it ?




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


Reply via email to