Skip to content

ISSUE-2770: Code refactor calling ledgerExists two times.#2903

Open
jadireddi wants to merge 1 commit intoapache:masterfrom
jadireddi:Issue2770-refactor
Open

ISSUE-2770: Code refactor calling ledgerExists two times.#2903
jadireddi wants to merge 1 commit intoapache:masterfrom
jadireddi:Issue2770-refactor

Conversation

@jadireddi
Copy link

Changes

SortedLedgerStorage's method ledgerExists, is being called two times to check for the ledger exists or not. Refactored to call only once.

Master Issue: #2770

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Lgtm

I would like to double check with @merlimat and @dlg99

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?

if (!interleavedLedgerStorage.ledgerExists(ledgerId)) {
EntryKeyValue kv = memTable.getLastEntry(ledgerId);
if (null == kv) {
return interleavedLedgerStorage.ledgerExists(ledgerId);
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.

@zymap
Copy link
Member

zymap commented Jul 29, 2022

Remove it to the next release because I think it needs more people to confirm.

@StevenLuMT
Copy link
Member

fix old workflow,please see #3455 for detail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants