StevenLuMT commented on code in PR #3522:
URL: https://github.com/apache/bookkeeper/pull/3522#discussion_r991090032


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieImpl.java:
##########
@@ -935,9 +936,10 @@ private void addEntryInternal(LedgerDescriptor handle, 
ByteBuf entry,
 
         // journal `addEntry` should happen after the entry is added to ledger 
storage.
         // otherwise the journal entry can potentially be rolled before the 
ledger is created in ledger storage.
-        if (masterKeyCache.get(ledgerId) == null) {
+        if (masterKeyCache.getIfPresent(ledgerId) == null) {
             // Force the load into masterKey cache
-            byte[] oldValue = masterKeyCache.putIfAbsent(ledgerId, masterKey);
+            byte[] oldValue = masterKeyCache.getIfPresent(ledgerId);
+            masterKeyCache.put(ledgerId, masterKey);
             if (oldValue == null) {

Review Comment:
   @gaozhangmin it doesn't matter:
   the masterKey of the same ledgerID is the same. This is only to prevent 
multiple writes. If it occurs multiple times, there is no risk. It will only 
cover the information when the journal does relay.
   
   you can see this code :
   
   org.apache.bookkeeper.bookie.BookieImpl#addEntryInternal
   <img width="1336" alt="image" 
src="https://user-images.githubusercontent.com/42990025/194837713-56d3db77-7019-4af7-bf73-8c0151466333.png";>
   
   org.apache.bookkeeper.bookie.BookieImpl#readJournal
   <img width="1129" alt="image" 
src="https://user-images.githubusercontent.com/42990025/194837463-b8ed2522-e30c-4428-bf38-64d998cb65c9.png";>
   



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