Skip to content

Commit c16be13

Browse files
poorbarcodezymap
authored andcommitted
[fix]Fix entry loss due to incorrect lock of LedgerHandle (#4701)
* [fix]Fix entry loss due to incorrect lock of LedgerHandle (cherry picked from commit 44607a0)
1 parent 088a722 commit c16be13

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/HandleFactoryImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ public LedgerDescriptor getHandle(final long ledgerId, final byte[] masterKey, b
6060
throw BookieException.create(BookieException.Code.LedgerFencedAndDeletedException);
6161
}
6262
handle = LedgerDescriptor.create(masterKey, ledgerId, ledgerStorage);
63-
ledgers.putIfAbsent(ledgerId, handle);
63+
LedgerDescriptor storedValue = ledgers.putIfAbsent(ledgerId, handle);
64+
// If it has been modified by other thread, use the previous one.
65+
if (storedValue != null && storedValue != handle) {
66+
return getHandle(ledgerId, masterKey, journalReplay);
67+
}
6468
}
6569

6670
handle.checkAccess(masterKey);

0 commit comments

Comments
 (0)