poorbarcode commented on code in PR #23049:
URL: https://github.com/apache/pulsar/pull/23049#discussion_r1682365888


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java:
##########
@@ -1509,6 +1514,31 @@ public CompletableFuture<List<String>> 
getListOfTopics(NamespaceName namespaceNa
         }
     }
 
+    public CompletableFuture<List<String>> getListOfUserTopics(NamespaceName 
namespaceName, Mode mode) {
+        String key = String.format("%s://%s", mode, namespaceName);
+        CompletableFuture<List<String>> queryRes =
+                inProgressQueryUserTopics.computeIfAbsent(key, k -> {
+            CompletableFuture<List<String>> res = new CompletableFuture<>();
+            // Switch thread to avoid blocking other threads who are calling 
the current method.
+            pulsar.getExecutor().execute(() -> {
+                getListOfTopics(namespaceName, mode).thenApply(list -> {
+                    return TopicList.filterSystemTopic(list);
+                }).whenComplete((topics, ex) -> {
+                    if (ex != null) {
+                        res.completeExceptionally(ex);
+                    } else {
+                        res.complete(topics);
+                    }
+                });
+            });
+            return res;
+        });
+        queryRes.whenComplete((ignore, ex) -> {

Review Comment:
   > Outputs:
   > Remove 1
   > Remove 1
   > Remove 1
   > Remove 1
   
   The code you provided is the evidence that the first task blocks other 
threads, which answered your below question: 
https://github.com/apache/pulsar/pull/23049#discussion_r1682326069
   
   >The existing code looks like:
   > ...
   > The fix:
   > ...
   
   The difference between the two examples: the `CompletableFuture` in the 
second code never complete.
   
   And all the tasks run on a same thread, which is wrong
   



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