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

feat(store/v2): support reverse iteration for PebbleDB #18193

Merged
merged 4 commits into from
Oct 23, 2023

Conversation

alexanderbez
Copy link
Contributor

@alexanderbez alexanderbez commented Oct 20, 2023

Description

Closes: #17976

This was actually much simpler to implement than I had originally imagined.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Summary by CodeRabbit

  • New Feature: Enhanced the database navigation capabilities by introducing reverse iteration over the database. This allows users to traverse the database in the opposite direction, providing more flexibility in data access.
  • Improvement: Added robust input validation for database keys. This ensures that the start key is not after the end key, enhancing the reliability of database operations.
  • Test: Removed a redundant test case (TestDatabase_ReverseIterator) for the database's reverse iteration functionality, simplifying the test suite.

These changes aim to improve the user experience by providing more flexible data access and ensuring more reliable database operations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 22, 2023

Walkthrough

This change introduces reverse iteration support for the PebbleDB database, with necessary modifications in the iterator logic and associated tests. It also enhances key validation in the Iterator and ReverseIterator functions.

Changes

File Summary
.../pebbledb/db.go Added input validation for keys and encoding in Iterator and ReverseIterator. Introduced a boolean parameter for reverse iteration in newPebbleDBIterator.
.../pebbledb/db_test.go Removed TestDatabase_ReverseIterator function and its test case.
.../pebbledb/iterator.go Added support for reverse iteration in the PebbleDB database. Modified newPebbleDBIterator, Next, and DebugRawIterate functions to handle reverse iteration.

🐇

In the land of code, where logic intertwines,

A rabbit hops, leaving traces of lines.

Forward we hopped, now backward we go,

Through the keys of PebbleDB, high and low.

Validation added, tests removed in stride,

In the realm of data, no secret can hide.

Celebrate the changes, for they bring delight,

To the world of coding, day and night. 🌙✨


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

@alexanderbez alexanderbez marked this pull request as ready for review October 23, 2023 00:34
@alexanderbez alexanderbez requested a review from a team as a code owner October 23, 2023 00:34
@github-actions
Copy link
Contributor

@alexanderbez your pull request is missing a changelog!

@github-prbot github-prbot requested review from a team, facundomedica and tac0turtle and removed request for a team October 23, 2023 00:34
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between 2fbc547 and fe1fe6b.
Files selected for processing (3)
  • store/storage/pebbledb/db.go (1 hunks)
  • store/storage/pebbledb/db_test.go (2 hunks)
  • store/storage/pebbledb/iterator.go (4 hunks)
Files skipped from review due to trivial changes (1)
  • store/storage/pebbledb/db_test.go
Additional comments (Suppressed): 9
store/storage/pebbledb/iterator.go (4)
  • 29-29: The reverse field has been added to the iterator struct to control the direction of iteration. Ensure that this field is properly initialized and used throughout the codebase.

  • 32-39: The newPebbleDBIterator function now accepts a reverse parameter and uses it to determine the initial position of the iterator. This is a breaking change and all calls to this function need to be updated to include the reverse parameter.

  • 107-122: The Next method of the iterator struct has been updated to handle reverse iteration. The logic for moving to the next key has been modified based on the reverse flag. Ensure that this change does not affect the existing functionality of forward iteration.

  • 265-270: The DebugRawIterate function has been updated to handle reverse iteration. The logic for moving to the next key has been modified based on the reverse flag. Ensure that this change does not affect the existing functionality of forward iteration.

store/storage/pebbledb/db.go (5)
  • 185-185: The newPebbleDBIterator function now accepts a new boolean parameter reverse. Ensure that all calls to this function throughout the codebase have been updated to include this new parameter.

  • 189-195: Input validation has been added for the start and end keys in the ReverseIterator function. This is a good practice to prevent unexpected behavior and errors.

  • 197-202: The keys are now encoded using MVCCEncode before being passed to the iterator. This is likely done to ensure that the keys are in a format that the iterator can understand and process correctly.

  • 204-207: Error handling has been added for the creation of the PebbleDB iterator. This is a good practice to prevent unexpected behavior and errors.

  • 209-209: The newPebbleDBIterator function now accepts a new boolean parameter reverse. Ensure that all calls to this function throughout the codebase have been updated to include this new parameter.

@alexanderbez alexanderbez removed the request for review from facundomedica October 23, 2023 00:46
Copy link
Member

@kocubinski kocubinski left a comment

Choose a reason for hiding this comment

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

ut ACK

@alexanderbez alexanderbez added this pull request to the merge queue Oct 23, 2023
Merged via the queue into main with commit 7590e91 Oct 23, 2023
53 checks passed
@alexanderbez alexanderbez deleted the bez/17976-pebbledb-reverse-iter branch October 23, 2023 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature (store v2): Support Reverse Iteration for PebbleDB
3 participants