streamnative / bookkeeper-achieved

Apache Bookkeeper
https://bookkeeper.apache.org
Apache License 2.0
3 stars 2 forks source link

ISSUE-2770: In class SortedLedgerStorage's method ledgerExists, why don't we simplely return false #401

Open sijie opened 3 years ago

sijie commented 3 years ago

Original Issue: apache/bookkeeper#2770


Class SortedLedgerStorage, method ledgerExists

@Override
    public boolean ledgerExists(long ledgerId) throws IOException {
        // Done this way because checking the skip list is an O(logN) operation compared to
        // the O(1) for the ledgerCache.
        if (!interleavedLedgerStorage.ledgerExists(ledgerId)) {
            EntryKeyValue kv = memTable.getLastEntry(ledgerId);
            if (null == kv) {
                return interleavedLedgerStorage.ledgerExists(ledgerId);
            }
        }
        return true;
    }

I want to know why calculate ledgerExists() two times? Thanks