poorbarcode commented on code in PR #4701:
URL: https://github.com/apache/bookkeeper/pull/4701#discussion_r2696683839
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/HandleFactoryImpl.java:
##########
@@ -53,16 +53,18 @@ class HandleFactoryImpl implements HandleFactory,
LedgerDeletionListener {
@Override
public LedgerDescriptor getHandle(final long ledgerId, final byte[]
masterKey, boolean journalReplay)
throws IOException, BookieException {
- LedgerDescriptor handle = ledgers.get(ledgerId);
-
- if (handle == null) {
- if (!journalReplay &&
recentlyFencedAndDeletedLedgers.getIfPresent(ledgerId) != null) {
- throw
BookieException.create(BookieException.Code.LedgerFencedAndDeletedException);
+ if (!ledgers.containsKey(ledgerId)) {
+ synchronized (ledgers) {
+ if (!ledgers.containsKey(ledgerId)) {
+ if (!journalReplay &&
recentlyFencedAndDeletedLedgers.getIfPresent(ledgerId) != null) {
+ throw
BookieException.create(BookieException.Code.LedgerFencedAndDeletedException);
+ }
+ LedgerDescriptor handle =
LedgerDescriptor.create(masterKey, ledgerId, ledgerStorage);
+ ledgers.putIfAbsent(ledgerId, handle);
+ }
}
- handle = LedgerDescriptor.create(masterKey, ledgerId,
ledgerStorage);
- ledgers.putIfAbsent(ledgerId, handle);
Review Comment:
Improved, please review again
--
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]