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

commitlog: Improve skipping behavior of traversals #1902

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

kim
Copy link
Contributor

@kim kim commented Oct 24, 2024

The *_from style traversals have historically yielded commits or transactions before the given from-offset, leaving it to downstream consumers to handle skipping.

While folding handles it internally, this behavior is not great for transaction iterators, due to the statefulness of decoding -- it is usually necessary to call Decoder::skip_record until the desired offset is found.

We would also yield all commits from the start of the nearest segment boundary, which can be quite confusing when using the commit iterators directly.

This patch fixes the situation by:

  • Setting the desired offset as the inital next offset in the Commits iterator, instead of the nearest segment boundary.
  • Looping instead of recursing in the Commits iterator while skipping commits, so we can skip until the initial offset without blowing the stack.
  • Passing the desired offset to Commit::into_transactions, such that Decoder::skip_record can be called if the offset doesn't lie on the commit boundary.

Expected complexity level and risk

2.5 -- makes head spin

NOTE: On top of #1901, because tooling work depends on the whole series

@kim kim requested a review from Shubham8287 October 24, 2024 16:03
Copy link
Contributor

@Shubham8287 Shubham8287 left a comment

Choose a reason for hiding this comment

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

I like these improvments. 👍

@kim kim changed the base branch from kim/core/reducer-ctx-from-tx-inputs to master October 28, 2024 07:22
The `*_from` style traversals have historically yielded commits or
transactions before the given from-offset, leaving it to downstream
consumers to handle skipping.

While folding handles it internally, this behavior is not great for
transaction iterators, due to the statefulness of decoding -- it is
usually necessary to call `Decoder::skip_record` until the desired
offset is found.

We would also yield all commits from the start of the nearest segment
boundary, which can be quite confusing when using the commit iterators
directly.

This patch fixes the situation by:

* Setting the desired offset as the inital next offset in the `Commits`
  iterator, instead of the nearest segment boundary.
* Looping instead of recursing in the `Commits` iterator while skipping
  commits, so we can skip until the initial offset without blowing the
  stack.
* Passing the desired offset to `Commit::into_transactions`, such that
  `Decoder::skip_record` can be called if the offset doesn't lie on the
  commit boundary.
@kim kim force-pushed the kim/commitlog/skipperer branch from 072b68f to 1213b2a Compare October 28, 2024 07:24
@kim kim enabled auto-merge October 28, 2024 07:24
@kim kim added this pull request to the merge queue Oct 28, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 28, 2024
@kim kim added this pull request to the merge queue Oct 28, 2024
Merged via the queue into master with commit d09e1ea Oct 28, 2024
8 checks passed
@kim kim deleted the kim/commitlog/skipperer branch October 28, 2024 08:37
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.

2 participants