Skip to content

Add mutable ID tracker tests#6158

Merged
timvisee merged 3 commits intodevfrom
mutable-id-tracker-tests
Mar 14, 2025
Merged

Add mutable ID tracker tests#6158
timvisee merged 3 commits intodevfrom
mutable-id-tracker-tests

Conversation

@timvisee
Copy link
Member

@timvisee timvisee commented Mar 12, 2025

Tracked in: #6157
Depends on: #6150

Add mutable ID tracker tests, ported from immutable ID tracker.

Tasks

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --all --all-features command?

Comment on lines +106 to +109
// Also reset inverse mapping
if let Some(internal_id) = internal_id {
self.internal_to_external[internal_id as usize] = PointIdType::NumId(u64::MAX);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Also resetting the inverse mapping is not strictly necessary. However, I think it's nice to do because that'll put the mapping in exactly the same state as before inserting the point.

Adding this here makes the new test test_point_deletion_persists_reload() happy. The alternative would be to not reset the inverse mapping and relax the test a bit to not assert raw values.

@timvisee timvisee force-pushed the mutable-id-tracker-tests branch from 3d914bb to 115ae6a Compare March 12, 2025 16:18
@timvisee timvisee changed the title WIP: add mutable ID tracker tests Add mutable ID tracker tests Mar 12, 2025
@timvisee timvisee marked this pull request as ready for review March 12, 2025 16:19
@timvisee timvisee force-pushed the mutable-id-tracker-tests branch from 115ae6a to 3cdb92b Compare March 12, 2025 16:23
Base automatically changed from mutable-id-tracker to dev March 13, 2025 16:12
@timvisee timvisee force-pushed the mutable-id-tracker-tests branch from 3cdb92b to e44f65f Compare March 13, 2025 16:12
@timvisee timvisee requested review from JojiiOfficial, agourlay and ffuugoo and removed request for JojiiOfficial, agourlay and ffuugoo March 13, 2025 16:12
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2025

📝 Walkthrough

Walkthrough

The pull request introduces several changes across multiple files. In the compressed_point_mappings.rs file, the type casting in the iter_internal_raw method has been changed from an explicit cast (offset as PointOffsetType) to a type inference approach (offset as _). In immutable_id_tracker.rs, the order of flush operations within the test_point_deletion_persists_reload test has been rearranged so that the call to versions_flusher() occurs after the call to mapping_flusher(). In mutable_id_tracker.rs, the open method has been updated to accept an impl Into<PathBuf> parameter instead of a PathBuf, and a new test module has been added to cover functionality such as ID iteration, loading, storing, and state persistence. Lastly, in point_mappings.rs, the drop method has been modified to reset the inverse mapping for removed IDs, and a new public method iter_internal_raw has been added to provide an iterator over the internal mappings.

Suggested reviewers

  • generall
  • JojiiOfficial

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a1b9de and e44f65f.

📒 Files selected for processing (4)
  • lib/segment/src/id_tracker/compressed/compressed_point_mappings.rs (1 hunks)
  • lib/segment/src/id_tracker/immutable_id_tracker.rs (1 hunks)
  • lib/segment/src/id_tracker/mutable_id_tracker.rs (2 hunks)
  • lib/segment/src/id_tracker/point_mappings.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Basic TLS/HTTPS tests
  • GitHub Check: test-snapshot-operations-s3-minio
  • GitHub Check: test-shard-snapshot-api-s3-minio
  • GitHub Check: test-consensus-compose
  • GitHub Check: test-low-resources
  • GitHub Check: test-consistency
  • GitHub Check: test-consensus
  • GitHub Check: test (macos-latest)
  • GitHub Check: test
  • GitHub Check: test (windows-latest)
  • GitHub Check: test
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test
🔇 Additional comments (6)
lib/segment/src/id_tracker/compressed/compressed_point_mappings.rs (1)

171-171: Good use of type inference!

Replacing the explicit offset as PointOffsetType cast with offset as _ leverages Rust's type inference capabilities. This is well-done since:

  1. The return type already specifies PointOffsetType in the function signature, making the type inference unambiguous
  2. This change improves maintainability if the return type ever changes
lib/segment/src/id_tracker/immutable_id_tracker.rs (1)

725-725: Proper ordering of flush operations

Good adjustment to ensure version flushing happens after mapping flushing. This aligns with the intended usage as documented in the mapping_flusher function, which states it "should be called before flushing the version database."

lib/segment/src/id_tracker/point_mappings.rs (2)

106-109: Proper cleanup of internal mapping on point deletion

Resetting the inverse mapping when removing an ID ensures the mapping is in the same state as before insertion, which improves consistency and facilitates testing.


215-223: Good addition of test utility method

The new iter_internal_raw method provides a clean way to enumerate and access the internal mapping structures for testing purposes. The method is properly scoped with #[cfg(test)] and returns the appropriate types.

lib/segment/src/id_tracker/mutable_id_tracker.rs (2)

57-59: Improved API ergonomics with impl Into

Using impl Into<PathBuf> instead of requiring an exact PathBuf type makes the API more flexible and user-friendly. This pattern allows callers to pass strings, Path objects, or PathBuf directly, following Rust best practices.


569-968: Comprehensive test coverage added for MutableIdTracker

Excellent addition of a thorough test suite for the MutableIdTracker that parallels the tests for ImmutableIdTracker. The tests cover:

  1. ID iteration and retrieval
  2. Persistence across reloads
  3. Point deletion behavior
  4. Compatibility with other ID tracker implementations
  5. Version handling

This ensures that the mutable implementation behaves consistently with the immutable one, which is crucial for correctness.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@timvisee timvisee merged commit c0b97e2 into dev Mar 14, 2025
17 checks passed
@timvisee timvisee deleted the mutable-id-tracker-tests branch March 14, 2025 08:52
timvisee added a commit that referenced this pull request Mar 21, 2025
* Add mutable ID tracker tests, ported from immutable ID tracker

* Also test raw mappings, reset inverse mapping when dropping point

* Always flush mappings before version, also in test
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.

3 participants