Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize getActiveLedgersInRange #4005

Merged
merged 2 commits into from
Jul 10, 2023

Conversation

AnonHxy
Copy link
Contributor

@AnonHxy AnonHxy commented Jun 29, 2023

Descriptions of the changes in this PR:

Motivation

Optimize Iterable<Long> getActiveLedgersInRange(0, Long.MAX_VALUE) by avoid applying the filter predicate when traverse the Iterable<Long>.

There are many places call getActiveLedgersInRange(0, Long.MAX_VALUE) to get the Iterable of all the ledgerId, for example:

  1. NavigableSet<Long> bkActiveLedgers = Sets.newTreeSet(ledgerStorage.getActiveLedgersInRange(0,
    Long.MAX_VALUE));
  2. for (long ledgerId : interleavedStorage.getActiveLedgersInRange(0, Long.MAX_VALUE)) {
  3. for (Long ledger : ledgers.getActiveLedgersInRange(0, Long.MAX_VALUE)) {

We could return the keys of ledgers directly to avoid applying the filter predicate when traverse the Iterable<Long>

Changes

Return the keys of ledgers directly if firstLedgerId <=0 && lastLedgerId == Long.MAX_VALUE

Copy link
Member

@StevenLuMT StevenLuMT left a comment

Choose a reason for hiding this comment

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

good catch,LGTM

Copy link
Member

@horizonzy horizonzy left a comment

Choose a reason for hiding this comment

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

We would better add a new method getAllActiveLedgers.

@StevenLuMT
Copy link
Member

We would better add a new method getAllActiveLedgers.

Whether to change the semantics of the original method, if it is changed, it is recommended to initiate a BP to add

@hangc0276 hangc0276 added this to the 4.17.0 milestone Jul 3, 2023
@hangc0276
Copy link
Contributor

We would better add a new method getAllActiveLedgers.

@horizonzy This change is low risk, and I think it's ok to be put in the original method.

@horizonzy
Copy link
Member

horizonzy commented Jul 3, 2023 via email

Copy link
Member

@horizonzy horizonzy left a comment

Choose a reason for hiding this comment

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

LGTM

@StevenLuMT StevenLuMT merged commit c967299 into apache:master Jul 10, 2023
16 checks passed
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
* Optimize getActiveLedgersInRange
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants