Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ public boolean ledgerExists(long ledgerId) throws IOException {
// the O(1) for the ledgerCache.
if (!interleavedLedgerStorage.ledgerExists(ledgerId)) {
EntryKeyValue kv = memTable.getLastEntry(ledgerId);
if (null == kv) {
return interleavedLedgerStorage.ledgerExists(ledgerId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen this patch before.
Maybe there is already another open PR

My question is...
Why this code was written the way it is?
In order to deal with some possible race condition ?

@merlimat do you know?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any case that line 145 returns false, but line 148 returns true?

Copy link
Member

@zymap zymap Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the comment said, checking the skip list is an O(logN) operation compared to the O(1) for the ledgerCache.

My thought that means the memTable.getLastEntry(ledgerId) is time consuming operation. After checking that, the ledgerCache may be filled so we check it again.

}
return null != kv;
}
return true;
}
Expand Down