You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "coderzc (via GitHub)" <gi...@apache.org> on 2023/06/27 09:26:25 UTC

[GitHub] [pulsar] coderzc commented on a diff in pull request #20642: [fix][meta] Bookie Info lost by notification race condition.

coderzc commented on code in PR #20642:
URL: https://github.com/apache/pulsar/pull/20642#discussion_r1243418768


##########
pulsar-metadata/src/main/java/org/apache/pulsar/metadata/bookkeeper/PulsarRegistrationClient.java:
##########
@@ -227,46 +276,48 @@ public CompletableFuture<Versioned<BookieServiceInfo>> getBookieServiceInfo(Book
         // this is because there are a few cases in which some operations on the main thread
         // wait for the result. This is due to the fact that resolving the address of a bookie
         // is needed in many code paths.
-        Versioned<BookieServiceInfo> resultFromCache = bookieServiceInfoCache.get(bookieId);
+        Versioned<BookieServiceInfo> info;
+        if ((info = writableBookieInfo.get(bookieId)) == null) {
+            info = readOnlyBookieInfo.get(bookieId);
+        }
         if (log.isDebugEnabled()) {
-            log.debug("getBookieServiceInfo {} -> {}", bookieId, resultFromCache);
+            log.debug("getBookieServiceInfo {} -> {}", bookieId, info);
         }
-        if (resultFromCache != null) {
-            return CompletableFuture.completedFuture(resultFromCache);
+        if (info != null) {
+            return completedFuture(info);
         } else {
             return FutureUtils.exception(new BKException.BKBookieHandleNotAvailableException());
         }
     }
 
-    public CompletableFuture<Void> readBookieServiceInfoAsync(BookieId bookieId) {
-        String asWritable = bookieRegistrationPath + "/" + bookieId;
-        return bookieServiceInfoMetadataCache.get(asWritable)
-                .thenCompose((Optional<BookieServiceInfo> getResult) -> {
-                    if (getResult.isPresent()) {
-                        Versioned<BookieServiceInfo> res =
-                                new Versioned<>(getResult.get(), new LongVersion(-1));
-                        log.info("Update BookieInfoCache (writable bookie) {} -> {}", bookieId, getResult.get());
-                        bookieServiceInfoCache.put(bookieId, res);
-                        return CompletableFuture.completedFuture(null);
-                    } else {
-                        return readBookieInfoAsReadonlyBookie(bookieId);
-                    }
-                }
-        );
+    public CompletableFuture<Optional<CacheGetResult<BookieServiceInfo>>> readBookieServiceInfoAsync(

Review Comment:
   ```suggestion
       public CompletableFuture<Optional<CacheGetResult<BookieServiceInfo>>> readBookieInfoAsWritableBookie(
   ```



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