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/06/28 08:42:08 UTC

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

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


##########
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, because we already have the topic reference here.



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