You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/09/05 03:00:48 UTC

[GitHub] [pulsar] mattisonchao commented on a diff in pull request #17402: [improve][admin] Make `getBundleRange` async

mattisonchao commented on code in PR #17402:
URL: https://github.com/apache/pulsar/pull/17402#discussion_r962436900


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -1219,27 +1215,32 @@ protected CompletableFuture<TopicHashPositions> internalGetTopicHashPositionsAsy
                 });
     }
 
-    private String getBundleRange(String bundleName) {
-        NamespaceBundle nsBundle;
+    private CompletableFuture<String> getBundleRangeAsync(String bundleName) {
+        CompletableFuture<NamespaceBundle> future;
         if (BundleType.LARGEST.toString().equals(bundleName)) {
-            nsBundle = findLargestBundleWithTopics(namespaceName);
+            future = findLargestBundleWithTopicsAsync(namespaceName);
         } else if (BundleType.HOT.toString().equals(bundleName)) {
-            nsBundle = findHotBundle(namespaceName);
+            future = findHotBundleAsync(namespaceName);
         } else {
-            return bundleName;
+            return CompletableFuture.completedFuture(bundleName);
         }
-        if (nsBundle == null) {
-            return null;
-        }
-        return nsBundle.getBundleRange();
+        return future.thenApply(nsBundle -> {
+            if (nsBundle == null) {
+                throw new RestException(Status.NOT_FOUND,
+                        String.format("Bundle range %s not found", bundleName));
+            }
+            return nsBundle.getBundleRange();
+        });
     }
 
-    private NamespaceBundle findLargestBundleWithTopics(NamespaceName namespaceName) {
-        return pulsar().getNamespaceService().getNamespaceBundleFactory().getBundleWithHighestTopics(namespaceName);
+    private CompletableFuture<NamespaceBundle> findLargestBundleWithTopicsAsync(NamespaceName namespaceName) {

Review Comment:
   If this method is just used for `getBundleRangeAsync` method, maybe we don't need to extract 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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org