codelipenghui commented on code in PR #25443:
URL: https://github.com/apache/pulsar/pull/25443#discussion_r3192488354


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:
##########
@@ -4136,6 +4153,38 @@ public void 
setPulsarChannelInitializerFactory(PulsarChannelInitializer.Factory
         this.pulsarChannelInitFactory = factory;
     }
 
+    /**
+     * @return Triple [namespace policies, global topic policies, topic 
policies].
+     */
+    public CompletableFuture<Boolean> isCurrentClusterAllowed(@NonNull 
TopicName topicName) {
+        final String cluster = getPulsar().getConfig().getClusterName();
+        return getCombinedTopicPolicies(topicName).thenApply(triple -> {
+            Optional<TopicPolicies> topicP = triple.getRight();
+            Optional<TopicPolicies> globalTopicP = triple.getMiddle();
+            Optional<Policies> nsPolicies = triple.getLeft();
+            // Disabled a cluster for a namespace manually.
+            if (nsPolicies.isPresent() && 
!isCurrentClusterAllowed(topicName.getNamespaceObject(), nsPolicies.get())) {
+                return false;
+            }
+            // Manually enabled topic-level replication, which can skip to set 
a namespace-level replication.
+            if (topicP.isPresent() && 
CollectionUtils.isNotEmpty(topicP.get().getReplicationClusters())) {
+                if (topicP.get().getReplicationClusters().contains(cluster)) {
+                    return true;
+                } else {
+                    return false;
+                }

Review Comment:
   `if (x) return true; else return false;` → `return 
topicP.get().getReplicationClusters().contains(cluster);` (same simplification 
applies to the `globalTopicP` block below).



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