You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/07/22 13:52:57 UTC

[GitHub] [pulsar] poorbarcode commented on a diff in pull request #16247: [fix] [broker] The broker has two identical Persitenttopics

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


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:
##########
@@ -1918,15 +1918,38 @@ public AuthorizationService getAuthorizationService() {
         return authorizationService;
     }
 
-    public CompletableFuture<Void> removeTopicFromCache(String topic) {
+    public CompletableFuture<Void> removeTopicFromCache(String topicNameString, Topic topic) {
+        if (topic == null){
+            return removeTopicFromCache(topicNameString);
+        }
+        final CompletableFuture<Optional<Topic>> createTopicFuture = getTopic(topicNameString, false);
+        return createTopicFuture.thenCompose(optionalTopic -> {
+            if (optionalTopic.isPresent() && optionalTopic.get() == topic){
+                return removeTopicFromCache(topicNameString, createTopicFuture);
+            }
+            // If topic is not in Cache, do nothing.
+            return CompletableFuture.completedFuture(null);
+        });

Review Comment:
   > We can use map.compute() to simplify the logic?  And looks like we don't need to wait for the future complete
   
   Yes, I've rewritten the logic.



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org