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


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java:
##########
@@ -1696,14 +1696,32 @@ public void openCursorFailed(ManagedLedgerException 
exception, Object ctx) {
         return future;
     }
 
+    private CompletableFuture<Boolean> checkReplicationCluster(String 
remoteCluster) {
+        return 
brokerService.getPulsar().getPulsarResources().getNamespaceResources()
+                .getPoliciesAsync(TopicName.get(topic).getNamespaceObject())
+                .thenApply(optPolicies -> optPolicies.map(policies -> 
policies.replication_clusters)
+                        .orElse(Collections.emptySet()).contains(remoteCluster)
+                        || 
topicPolicies.getReplicationClusters().get().contains(remoteCluster));
+    }
+
     protected CompletableFuture<Void> addReplicationCluster(String 
remoteCluster, ManagedCursor cursor,
             String localCluster) {
         return 
AbstractReplicator.validatePartitionedTopicAsync(PersistentTopic.this.getName(),
 brokerService)
-                .thenCompose(__ -> 
brokerService.pulsar().getPulsarResources().getClusterResources()
-                        .getClusterAsync(remoteCluster)
-                        .thenApply(clusterData ->
-                                
brokerService.getReplicationClient(remoteCluster, clusterData)))
+                .thenCompose(__ -> checkReplicationCluster(remoteCluster))
+                .thenCompose(clusterExists -> {
+                    if (!clusterExists) {
+                        log.warn("Remove the replicator because the cluster 
'{}' does not exist", remoteCluster);
+                        return removeReplicator(remoteCluster).thenApply(__ -> 
null);

Review Comment:
   @315157973 
   
   > Why don't we clean up when the Policy is removed?
   
   When the policy is removed, the cursor will not be clean If this topic is 
not online. see 
https://github.com/apache/pulsar/blob/d1fc7323cbf61a6d2955486fc123fdde5253e72c/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java#L1589



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