AnonHxy commented on code in PR #16946:
URL: https://github.com/apache/pulsar/pull/16946#discussion_r958331532


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:
##########
@@ -5233,42 +5241,41 @@ protected void 
internalGetReplicatedSubscriptionStatus(AsyncResponse asyncRespon
         });
     }
 
+    private CompletableFuture<Map<String, Boolean>> 
getReplicatedSubscriptionStatusFromBroker(TopicName partitionName,
+                                                                               
               String subName) {
+        return getTopicReferenceAsync(partitionName).thenCompose(topic -> {
+            Subscription sub = topic.getSubscription(subName);
+            if (sub == null) {
+                return FutureUtil.failedFuture(new 
RestException(Status.NOT_FOUND,
+                    getSubNotFoundErrorMessage(partitionName.toString(), 
subName)));
+            }
+            if (topic instanceof PersistentTopic && sub instanceof 
PersistentSubscription) {
+                Map<String, Boolean> res = Maps.newHashMap();
+                res.put(partitionName.toString(), sub.isReplicated());
+                return CompletableFuture.completedFuture(res);
+            } else {
+                return FutureUtil.failedFuture(new 
RestException(Status.METHOD_NOT_ALLOWED,
+                    "Cannot get replicated subscriptions on non-persistent 
topics"));
+            }
+        });
+    }
+
     private void internalGetReplicatedSubscriptionStatusForNonPartitionedTopic(
                                                                                
AsyncResponse asyncResponse,
                                                                                
String subName,
                                                                                
boolean authoritative) {
         // Redirect the request to the appropriate broker if this broker is 
not the owner of the topic
         validateTopicOwnershipAsync(topicName, authoritative)
-                .thenCompose(__ -> getTopicReferenceAsync(topicName))
-                .thenAccept(topic -> {
-                    if (topic == null) {

Review Comment:
   `getTopicReferenceAsync(topicName))`  cannot return `null`,  so here we no 
need to check  `topic == null` I think.
   
   If topic doesn't exist, `getTopicReferenceAsync` will return 
`completeFuture` with  exception result, see Line4312
   
https://github.com/apache/pulsar/blob/cb881d47f7e5c561ac0e2c76e525b8b5a8a9aaef/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java#L4308-L4312



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