Jason918 commented on a change in pull request #13887:
URL: https://github.com/apache/pulsar/pull/13887#discussion_r789676937



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
##########
@@ -4504,26 +4504,24 @@ protected void 
internalSetReplicatedSubscriptionStatus(AsyncResponse asyncRespon
             return;
         }
 
-        // Permission to consume this topic is required
-        try {
-            validateTopicOperation(topicName, 
TopicOperation.SET_REPLICATED_SUBSCRIPTION_STATUS, subName);
-        } catch (Exception e) {
-            resumeAsyncResponseExceptionally(asyncResponse, e);
-            return;
-        }
+        // 1.Permission to consume this topic is required
+        // 2.Redirect the request to the peer-cluster if the local cluster is 
not included in the replication clusters
+        CompletableFuture<Void> future =
+                validateTopicOperationAsync(topicName, 
TopicOperation.SET_REPLICATED_SUBSCRIPTION_STATUS, subName)
+                        .thenCompose(__ -> 
validateGlobalNamespaceOwnershipAsync(namespaceName));
 
-        // Redirect the request to the peer-cluster if the local cluster is 
not included in the replication clusters
-        try {
-            validateGlobalNamespaceOwnership(namespaceName);
-        } catch (Exception e) {
-            resumeAsyncResponseExceptionally(asyncResponse, e);
-            return;
-        }
 
         // If the topic name is a partition name, no need to get partition 
topic metadata again
         if (topicName.isPartitioned()) {
-            
internalSetReplicatedSubscriptionStatusForNonPartitionedTopic(asyncResponse, 
subName, authoritative,
-                    enabled);
+            future.thenCompose(
+                    __ -> 
internalSetReplicatedSubscriptionStatusForNonPartitionedTopicAsync(asyncResponse,
 subName,
+                            authoritative, enabled))
+                    .exceptionally(ex -> {
+                        log.warn("[{}] Failed to change replicated 
subscription status to {} - {} {}", clientAppId(),
+                                enabled, topicName, subName, ex);
+                        resumeAsyncResponseExceptionally(asyncResponse, ex);
+                        return null;
+                    });
         } else {
             getPartitionedTopicMetadataAsync(topicName, authoritative, 
false).thenAccept(partitionMetadata -> {

Review comment:
       Need `future.thenCompose` here. This should be executed after previous 
validation is finished.




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