Repository navigation
refactor: split mutable_id_tracker.rs into a module - #8795
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
💤 Files with no reviewable changes (1)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds a new modular, file-backed implementation of a mutable ID tracker. New modules: Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/segment/src/id_tracker/mutable_id_tracker/mod.rs`:
- Around line 67-156: The mappings_path function is unnecessarily pub(crate)
while versions_path is pub(super); change mappings_path's visibility to
pub(super) so both helpers used only by sibling modules under mutable_id_tracker
have the same, narrower scope—locate mappings_path in mappings_storage.rs
(symbol: mappings_path) and update its declaration from pub(crate) fn
mappings_path(...) to pub(super) fn mappings_path(...), then run cargo check to
ensure no external callers rely on the wider visibility.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4df23c42-d0c6-461d-9d39-016a0d5d8f74
📒 Files selected for processing (6)
lib/segment/src/id_tracker/mutable_id_tracker.rslib/segment/src/id_tracker/mutable_id_tracker/change.rslib/segment/src/id_tracker/mutable_id_tracker/mappings_storage.rslib/segment/src/id_tracker/mutable_id_tracker/mod.rslib/segment/src/id_tracker/mutable_id_tracker/tests.rslib/segment/src/id_tracker/mutable_id_tracker/versions_storage.rs
💤 Files with no reviewable changes (1)
- lib/segment/src/id_tracker/mutable_id_tracker.rs
|
|
||
| impl MutableIdTracker { | ||
| pub fn open(segment_path: impl Into<PathBuf>) -> OperationResult<Self> { | ||
| let segment_path = segment_path.into(); | ||
|
|
||
| let (mappings_path, versions_path) = | ||
| (mappings_path(&segment_path), versions_path(&segment_path)); | ||
| let (has_mappings, has_versions) = (mappings_path.is_file(), versions_path.is_file()); | ||
|
|
||
| // Warn or error about unlikely or problematic scenarios | ||
| if !has_mappings && has_versions { | ||
| debug_assert!( | ||
| false, | ||
| "Missing mappings file for ID tracker while versions file exists, storage may be corrupted!", | ||
| ); | ||
| log::error!( | ||
| "Missing mappings file for ID tracker while versions file exists, storage may be corrupted!", | ||
| ); | ||
| } | ||
| if has_mappings && !has_versions { | ||
| log::warn!( | ||
| "Missing versions file for ID tracker, assuming automatic point mappings and version recovery by WAL", | ||
| ); | ||
| } | ||
|
|
||
| let (mappings, mappings_expected_len) = if has_mappings { | ||
| load_mappings(&mappings_path).map_err(|err| { | ||
| OperationError::service_error(format!("Failed to load ID tracker mappings: {err}")) | ||
| })? | ||
| } else { | ||
| (PointMappings::default(), 0) | ||
| }; | ||
|
|
||
| let internal_to_version = if has_versions { | ||
| load_versions(&versions_path).map_err(|err| { | ||
| OperationError::service_error(format!("Failed to load ID tracker versions: {err}")) | ||
| })? | ||
| } else { | ||
| vec![] | ||
| }; | ||
|
|
||
| // Compare internal point mappings and versions count, report warning if we don't | ||
| debug_assert!( | ||
| mappings.total_point_count() >= internal_to_version.len(), | ||
| "can never have more versions than internal point mappings", | ||
| ); | ||
| if mappings.total_point_count() != internal_to_version.len() { | ||
| log::warn!( | ||
| "Mutable ID tracker mappings and versions count mismatch, could have been partially flushed, assuming automatic recovery by WAL ({} mappings, {} versions)", | ||
| mappings.total_point_count(), | ||
| internal_to_version.len(), | ||
| ); | ||
| } | ||
|
|
||
| #[cfg(debug_assertions)] | ||
| mappings.assert_mappings(); | ||
|
|
||
| Ok(Self { | ||
| segment_path, | ||
| internal_to_version, | ||
| mappings, | ||
| pending_versions: Default::default(), | ||
| pending_mappings: Default::default(), | ||
| is_alive_lock: IsAliveLock::new(), | ||
| mappings_expected_len: Arc::new(AtomicU64::new(mappings_expected_len)), | ||
| }) | ||
| } | ||
|
|
||
| /// Approximate RAM usage in bytes for in-memory data structures. | ||
| pub fn ram_usage_bytes(&self) -> usize { | ||
| let Self { | ||
| segment_path: _, | ||
| internal_to_version, | ||
| mappings, | ||
| pending_versions: _, // transient, small | ||
| pending_mappings: _, // transient, small | ||
| is_alive_lock: _, | ||
| mappings_expected_len: _, | ||
| } = self; | ||
|
|
||
| internal_to_version.capacity() * std::mem::size_of::<SeqNumberType>() | ||
| + mappings.ram_usage_bytes() | ||
| } | ||
|
|
||
| pub fn segment_files(segment_path: &Path) -> Vec<PathBuf> { | ||
| [mappings_path(segment_path), versions_path(segment_path)] | ||
| .into_iter() | ||
| .filter(|path| path.is_file()) | ||
| .collect() | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Find call sites of mappings_path and versions_path outside the new module to
# confirm pub(crate) vs pub(super) visibilities are still appropriate.
rg -nP --type=rust -C2 '\b(mappings_path|versions_path)\s*\(' \
-g '!lib/segment/src/id_tracker/mutable_id_tracker/**'Repository: qdrant/qdrant
Length of output: 39
🏁 Script executed:
# First, find where mappings_path and versions_path are defined
rg -nP --type=rust '(pub\(.*\)\s+)?fn\s+(mappings_path|versions_path)' \
lib/segment/src/id_tracker/Repository: qdrant/qdrant
Length of output: 319
🏁 Script executed:
# Also search for all uses of these functions across the entire codebase
rg -nP --type=rust '(mappings_path|versions_path)' \
lib/segment/src/id_tracker/ | head -40Repository: qdrant/qdrant
Length of output: 4828
🏁 Script executed:
# Check specifically in the mod.rs file to see the current visibility
cat -n lib/segment/src/id_tracker/mutable_id_tracker/mod.rs | grep -A5 -B5 'fn mappings_path\|fn versions_path'Repository: qdrant/qdrant
Length of output: 39
Align mappings_path visibility with versions_path: Change pub(crate) fn mappings_path to pub(super) in mappings_storage.rs:22. Both functions are only used by sibling modules within mutable_id_tracker (verified: no external callers outside this module), so narrower visibility is appropriate and aligns with the codebase preference for avoiding unnecessary broader exposure.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@lib/segment/src/id_tracker/mutable_id_tracker/mod.rs` around lines 67 - 156,
The mappings_path function is unnecessarily pub(crate) while versions_path is
pub(super); change mappings_path's visibility to pub(super) so both helpers used
only by sibling modules under mutable_id_tracker have the same, narrower
scope—locate mappings_path in mappings_storage.rs (symbol: mappings_path) and
update its declaration from pub(crate) fn mappings_path(...) to pub(super) fn
mappings_path(...), then run cargo check to ensure no external callers rely on
the wider visibility.
a24bbcb to
ad77b06
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/segment/src/id_tracker/mutable_id_tracker/tests.rs (1)
32-41: Use explicitPointIdType::from(...)here.These new test calls use implicit
.into(), which goes against the repository Rust style rule. Please make the conversion explicit in setup and assertions.♻️ Suggested cleanup
- id_tracker.set_link(200.into(), 0).unwrap(); - id_tracker.set_link(100.into(), 1).unwrap(); - id_tracker.set_link(150.into(), 2).unwrap(); - id_tracker.set_link(120.into(), 3).unwrap(); - id_tracker.set_link(180.into(), 4).unwrap(); - id_tracker.set_link(110.into(), 5).unwrap(); - id_tracker.set_link(115.into(), 6).unwrap(); - id_tracker.set_link(190.into(), 7).unwrap(); - id_tracker.set_link(177.into(), 8).unwrap(); - id_tracker.set_link(118.into(), 9).unwrap(); + id_tracker.set_link(PointIdType::from(200), 0).unwrap(); + id_tracker.set_link(PointIdType::from(100), 1).unwrap(); + id_tracker.set_link(PointIdType::from(150), 2).unwrap(); + id_tracker.set_link(PointIdType::from(120), 3).unwrap(); + id_tracker.set_link(PointIdType::from(180), 4).unwrap(); + id_tracker.set_link(PointIdType::from(110), 5).unwrap(); + id_tracker.set_link(PointIdType::from(115), 6).unwrap(); + id_tracker.set_link(PointIdType::from(190), 7).unwrap(); + id_tracker.set_link(PointIdType::from(177), 8).unwrap(); + id_tracker.set_link(PointIdType::from(118), 9).unwrap(); @@ - assert_eq!(first_four[0].0, 100.into()); + assert_eq!(first_four[0].0, PointIdType::from(100));As per coding guidelines,
**/*.rs: Prefer explicitSomeType::from(x)over implicitx.into()in Rust.Also applies to: 50-50
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/id_tracker/mutable_id_tracker/tests.rs` around lines 32 - 41, Replace implicit `.into()` conversions in the test setup with explicit PointIdType::from(...) calls: update each id_tracker.set_link(... .into(), ...) call (function set_link in tests.rs) to pass PointIdType::from(200), PointIdType::from(100), etc., and apply the same explicit conversion pattern anywhere else in the file where ids are converted implicitly (e.g., assertions or additional set_link invocations) to comply with the repository style.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/segment/src/id_tracker/mutable_id_tracker/tests.rs`:
- Around line 32-41: Replace implicit `.into()` conversions in the test setup
with explicit PointIdType::from(...) calls: update each id_tracker.set_link(...
.into(), ...) call (function set_link in tests.rs) to pass
PointIdType::from(200), PointIdType::from(100), etc., and apply the same
explicit conversion pattern anywhere else in the file where ids are converted
implicitly (e.g., assertions or additional set_link invocations) to comply with
the repository style.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8fe3e27d-565c-4f93-874e-7d795c8e0cf7
📒 Files selected for processing (1)
lib/segment/src/id_tracker/mutable_id_tracker/tests.rs
600be35 to
c102ac0
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/segment/src/id_tracker/mutable_id_tracker/tests.rs (1)
243-243: Typo:intetrnal_id→internal_id.Minor typo carried over in the moved test. Optional cleanup while you're touching this file.
♻️ Proposed nit fix
- let intetrnal_id = id_tracker + let internal_id = id_tracker .internal_id(point_to_delete) .expect("Point to delete exists."); - assert!(!id_tracker.is_deleted_point(intetrnal_id)); + assert!(!id_tracker.is_deleted_point(internal_id));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/id_tracker/mutable_id_tracker/tests.rs` at line 243, Rename the misspelled local variable intetrnal_id to internal_id in the test that uses id_tracker (identify the occurrence where the test assigns from id_tracker to intetrnal_id) so the variable name is correct; update all references to that variable within the same test function to match the new name.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/segment/src/id_tracker/mutable_id_tracker/tests.rs`:
- Line 243: Rename the misspelled local variable intetrnal_id to internal_id in
the test that uses id_tracker (identify the occurrence where the test assigns
from id_tracker to intetrnal_id) so the variable name is correct; update all
references to that variable within the same test function to match the new name.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a99dd078-1c69-4bfa-b9e4-49bc75b84bc8
📒 Files selected for processing (6)
lib/segment/src/id_tracker/mutable_id_tracker.rslib/segment/src/id_tracker/mutable_id_tracker/change.rslib/segment/src/id_tracker/mutable_id_tracker/mappings_storage.rslib/segment/src/id_tracker/mutable_id_tracker/mod.rslib/segment/src/id_tracker/mutable_id_tracker/tests.rslib/segment/src/id_tracker/mutable_id_tracker/versions_storage.rs
💤 Files with no reviewable changes (1)
- lib/segment/src/id_tracker/mutable_id_tracker.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/segment/src/id_tracker/mutable_id_tracker/versions_storage.rs
Break the 1630-line file into a directory module with logically separated components: change.rs (MappingChange + entry codec), mappings_storage.rs (mappings file IO), versions_storage.rs (versions file IO), tests.rs (all unit tests), and mod.rs (struct + IdTracker impl). No logic changes. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- Import std::io::Seek so Cursor::stream_position resolves - Drop unused PointMappingsRefEnum import
c102ac0 to
78358c5
Compare
* refactor: split mutable_id_tracker.rs into a module Break the 1630-line file into a directory module with logically separated components: change.rs (MappingChange + entry codec), mappings_storage.rs (mappings file IO), versions_storage.rs (versions file IO), tests.rs (all unit tests), and mod.rs (struct + IdTracker impl). No logic changes. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix: clippy errors in mutable_id_tracker tests - Import std::io::Seek so Cursor::stream_position resolves - Drop unused PointMappingsRefEnum import --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> Co-authored-by: Cursor Agent <[email protected]>
Summary
lib/segment/src/id_tracker/mutable_id_tracker.rsinto a directory module with logical separation.lib/segment/src/id_tracker/mutable_id_tracker/:mod.rs—MutableIdTrackerstruct +IdTrackerimpl (incl. flusher closures)change.rs—MappingChange/MappingChangeType+read_entry/write_entrycodecmappings_storage.rs—mappings_path,load_mappings,store_mapping_changes,read_mappings*,write_mapping_changes,reconcile_persisted_mapping_changesversions_storage.rs—versions_path,load_versions,store_version_changes,write_version_changes,reconcile_persisted_version_changes,VERSION_ELEMENT_SIZEtests.rs— all unit tests, with explicit submodule importspub(super) mod tests,pub(crate) fn mappings_path,pub(super) mappingsfield).Test plan
cargo +nightly fmt --all -- --checkpasses (verified locally via pre-push hook)cargo check -p segment --lib --testsintroduces no new errors vs.dev(the pre-existingnull_index::for_each_payload_blockbuild errors ondevare unrelated to this change)cargo test -p segment id_tracker::mutable_id_trackerpasses once the unrelatednull_indexerrors are resolved ondev🤖 Generated with Claude Code