lhotari commented on code in PR #25618:
URL: https://github.com/apache/pulsar/pull/25618#discussion_r3162799580


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/ScalableTopics.java:
##########
@@ -268,14 +273,15 @@ public void getStats(
         validateNamespaceName(tenant, namespace);
         TopicName tn = TopicName.get(TopicDomain.topic.value(), namespaceName, 
encodedTopic);
 
-        var scalableTopicService = 
pulsar().getBrokerService().getScalableTopicService();
-        if (scalableTopicService == null) {
-            asyncResponse.resume(new 
RestException(Response.Status.SERVICE_UNAVAILABLE,
-                    "Scalable topic service not available"));
-            return;
-        }
-
-        scalableTopicService.getStats(tn)
+        validateTopicOperationAsync(tn, TopicOperation.GET_STATS)
+                .thenCompose(__ -> {
+                    var scalableTopicService = 
pulsar().getBrokerService().getScalableTopicService();
+                    if (scalableTopicService == null) {
+                        throw new 
RestException(Response.Status.SERVICE_UNAVAILABLE,
+                                "Scalable topic service not available");
+                    }
+                    return scalableTopicService.getStats(tn);
+                })

Review Comment:
   Done in 8c09e1f. Extracted two helpers: `withScalableTopicService(op)` for 
the bare service-availability check (used by `getStats`) and 
`onControllerLeader(tn, op)` which composes it with 
`redirectToControllerLeaderIfNeeded` for the four endpoints that need the 
elected leader 
(`createSubscription`/`deleteSubscription`/`splitSegment`/`mergeSegments`).



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