Skip to content

Conversation

generall
Copy link
Member

UUID crate changed Hash implementation, which silently broke our HashRing routing

#6595

Replace derive(Hash) with manual impl in Uuid by @​diopoex in uuid-rs/uuid#824

This PR adds manual implementation of Hash for ExtendedPointId and unit-test which pins shard mapping.

@generall generall requested review from coszio and xzfc July 23, 2025 23:53
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
// WARN: Changing this implementation might break backward compatibility
// Of hash-ring and shard routing
let __self_discr = std::mem::discriminant(self);
Copy link
Member Author

Choose a reason for hiding this comment

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

I have doubts about this: I used "Expand Macro" from Rust Playground, but it generates nightly. This version is copilot suggestion of how to fix Nightly build

Copy link
Contributor

Choose a reason for hiding this comment

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

Rust 1.87 generates the same (std::mem::discriminant).

Copy link
Contributor

coderabbitai bot commented Jul 23, 2025

📝 Walkthrough

Walkthrough

A new unit test named split_point_operations was added to the tests module in the point operations code. This test checks the deterministic assignment of various ExtendedPointId values to shards using a hash ring router. In addition, the Hash trait for the ExtendedPointId enum was changed from a derived implementation to a manual one. The custom implementation first hashes the enum discriminant, then the inner value (either a numeric ID or the bytes of a UUID), with a cautionary comment about backward compatibility. No changes were made to public function signatures or exported entities.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation - Beta

CodeRabbit's unit test generation is now available in Beta! Automatically generate comprehensive unit tests for your code changes, ensuring better test coverage and catching edge cases you might miss. Our AI analyzes your code structure and creates tests that follow best practices and your project's testing patterns. Learn more here, or just try it under ✨ Finishing Touches.


📜 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 f03de34 and ed526bc.

📒 Files selected for processing (1)
  • lib/collection/src/operations/point_ops.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/collection/src/operations/point_ops.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: test-consistency
  • GitHub Check: integration-tests
  • GitHub Check: e2e-tests
  • GitHub Check: test-shard-snapshot-api-s3-minio
  • GitHub Check: storage-compat-test
  • GitHub Check: test-consensus-compose
  • GitHub Check: rust-tests (windows-latest)
  • GitHub Check: lint
  • GitHub Check: integration-tests-consensus
  • GitHub Check: rust-tests (macos-latest)
  • GitHub Check: rust-tests (ubuntu-latest)
  • GitHub Check: rust-tests-no-rocksdb (ubuntu-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch force-uuid-independent-hash-implementation

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests 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.

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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/collection/src/operations/point_ops.rs (1)

936-1003: Excellent regression test for hash consistency.

This test effectively addresses the PR objective by ensuring that shard mapping remains deterministic after the Hash implementation fix. The mix of UUID and numeric IDs provides good coverage.

Consider refactoring for better maintainability:

+        let expected_mappings = vec![
+            (id1, 2), (id2, 1), (id3, 2), (id4, 2), (id5, 0),
+            (id6, 0), (id7, 0), (id8, 2), (id9, 1)
+        ];
+
         match operation_to_shard {
             OperationToShard::ByShard(by_shard) => {
+                let mut actual_mappings = HashMap::new();
                 for (shard_id, points) in by_shard {
                     for point in points {
-                        // Important: This mapping should not change with new updates!
-                        if point.id == id1 {
-                            assert_eq!(shard_id, 2);
-                        }
-                        // ... (repeat for all IDs)
+                        actual_mappings.insert(point.id.clone(), shard_id);
                     }
                 }
+                
+                for (id, expected_shard) in expected_mappings {
+                    assert_eq!(
+                        actual_mappings.get(&id),
+                        Some(&expected_shard),
+                        "Point ID {:?} should map to shard {}, but was assigned to {:?}",
+                        id, expected_shard, actual_mappings.get(&id)
+                    );
+                }
             }

This approach makes the expected mappings more visible and provides better error messages.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6fdf445 and f03de34.

📒 Files selected for processing (2)
  • lib/collection/src/operations/point_ops.rs (1 hunks)
  • lib/segment/src/types.rs (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: generall
PR: qdrant/qdrant#6854
File: lib/segment/src/index/query_estimator.rs:320-327
Timestamp: 2025-07-11T11:35:21.549Z
Learning: In test code for Qdrant's query estimator (lib/segment/src/index/query_estimator.rs), simplified ID resolution logic using `id.to_string().parse().unwrap()` is acceptable for testing purposes and doesn't need to match production code's `id_tracker.internal_id()` approach. Test code can use mock implementations that serve the testing goals.
Learnt from: timvisee
PR: qdrant/qdrant#6444
File: lib/segment/src/index/field_index/map_index/immutable_map_index.rs:373-375
Timestamp: 2025-05-08T10:34:42.223Z
Learning: In the Qdrant codebase, storage backends may have different error handling approaches. Specifically, the mmap variant of `remove_point` method does not return errors, while the RocksDB variant does propagate errors using the `?` operator. These differences are intentional by design.
lib/collection/src/operations/point_ops.rs (4)

Learnt from: generall
PR: #6854
File: lib/segment/src/index/query_estimator.rs:320-327
Timestamp: 2025-07-11T11:35:21.549Z
Learning: In test code for Qdrant's query estimator (lib/segment/src/index/query_estimator.rs), simplified ID resolution logic using id.to_string().parse().unwrap() is acceptable for testing purposes and doesn't need to match production code's id_tracker.internal_id() approach. Test code can use mock implementations that serve the testing goals.

Learnt from: timvisee
PR: #6444
File: lib/segment/src/index/field_index/map_index/immutable_map_index.rs:373-375
Timestamp: 2025-05-08T10:34:42.223Z
Learning: In the Qdrant codebase, storage backends may have different error handling approaches. Specifically, the mmap variant of remove_point method does not return errors, while the RocksDB variant does propagate errors using the ? operator. These differences are intentional by design.

Learnt from: timvisee
PR: #6546
File: lib/segment/src/index/field_index/full_text_index/text_index.rs:497-518
Timestamp: 2025-05-19T09:25:54.285Z
Learning: In the Qdrant project, using .expect() and .unwrap() is considered acceptable in test code since test failures should be loud and obvious, and proper error propagation adds unnecessary complexity to test code.

Learnt from: coszio
PR: #6528
File: lib/posting_list/src/view.rs:118-118
Timestamp: 2025-05-19T14:40:20.068Z
Learning: In the bitpacking crate, the BitPacker::decompress_strictly_sorted function takes an Option as its first parameter, which means using checked_sub(1) without unwrapping is intentional and correct.

lib/segment/src/types.rs (1)

Learnt from: generall
PR: #6854
File: lib/segment/src/index/query_estimator.rs:320-327
Timestamp: 2025-07-11T11:35:21.549Z
Learning: In test code for Qdrant's query estimator (lib/segment/src/index/query_estimator.rs), simplified ID resolution logic using id.to_string().parse().unwrap() is acceptable for testing purposes and doesn't need to match production code's id_tracker.internal_id() approach. Test code can use mock implementations that serve the testing goals.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: test-consistency
  • GitHub Check: e2e-tests
  • GitHub Check: lint
  • GitHub Check: test-shard-snapshot-api-s3-minio
  • GitHub Check: test-consensus-compose
  • GitHub Check: integration-tests
  • GitHub Check: integration-tests-consensus
  • GitHub Check: rust-tests (ubuntu-latest)
  • GitHub Check: storage-compat-test
  • GitHub Check: rust-tests (macos-latest)
  • GitHub Check: rust-tests-no-rocksdb (ubuntu-latest)
  • GitHub Check: rust-tests (windows-latest)
🔇 Additional comments (3)
lib/segment/src/types.rs (2)

149-149: LGTM: Correctly removed Hash from derive attributes

Removing Hash from the derive macro is the correct approach when providing a manual implementation of the Hash trait.


158-170: Excellent manual Hash implementation with proper backward compatibility considerations

This manual Hash implementation correctly addresses the UUID crate Hash changes mentioned in the PR objectives:

  1. Proper enum hashing: First hashes the discriminant to distinguish between NumId and Uuid variants
  2. Deterministic UUID hashing: Uses uuid.as_bytes() for consistent byte-level hashing
  3. Backward compatibility warning: The comment appropriately warns about the impact on hash-ring and shard routing

This ensures consistent shard mapping regardless of changes in the UUID crate's Hash implementation.

lib/collection/src/operations/point_ops.rs (1)

929-929: LGTM: Necessary imports for the test.

The imports are correctly added to support the new test functionality.

Also applies to: 932-932

@generall generall merged commit 2f44084 into dev Jul 24, 2025
21 of 22 checks passed
@generall generall deleted the force-uuid-independent-hash-implementation branch July 24, 2025 06:31
generall added a commit that referenced this pull request Jul 24, 2025
@xzfc xzfc mentioned this pull request Jul 25, 2025
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