Repository navigation
refactor(map_index): extract inner state; add ReadOnlyAppendableMapIndex skeleton - #9020
Conversation
…ableMapIndex
Extract the four in-memory fields (`map`, `point_to_values`, `indexed_points`,
`values_count`) of `MutableMapIndex<N>` into a shared inner struct
`MutableMapIndexInner<N>` under `mutable_map_index/inner.rs`. The
`MapIndexRead<N>` impl moves wholesale onto the inner. `MutableMapIndex<N>`
becomes a thin wrapper `{ inner, storage: Gridstore<...> }`; its
`MapIndexRead<N>` impl forwards to the inner. The Gridstore load loop in
`open_gridstore` collapses to `MutableMapIndexInner::empty()` +
`inner.ingest(idx, value)` per row, sharing the per-value ingestion path with
the future read-only loader.
Add a new sibling `mutable_map_index/read_only/` module containing
`ReadOnlyAppendableMapIndex<N>` (inner + `GridstoreReader<Vec<...>, MmapFile>`),
with its `MapIndexRead<N>` impl forwarding to the same inner. No constructor
yet — loading and lifecycle for the read-only variant will land in a
follow-up. Field `storage` is held to pin the on-disk type and tagged
`#[allow(dead_code)]` until then.
No behavioural change. The 17 existing map_index tests pass unchanged.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/segment/src/index/field_index/map_index/mutable_map_index/lifecycle.rs (1)
103-109: ⚡ Quick winUse explicit
Fromconversions inadd_many_to_map.Please replace implicit
.into()conversions here with explicit<Owned>::from(...)to match the Rust guideline used in this repo.Suggested diff
- for value in values.clone() { - let entry = self.inner.map.entry(value.into()); + for value in values.clone() { + let entry = self + .inner + .map + .entry(<N as MapIndexKey>::Owned::from(value)); self.inner.point_to_values[idx as usize].push(entry.key().clone()); entry.or_default().insert(idx); } - let values = values.into_iter().map(Into::into).collect::<Vec<_>>(); + let values = values + .into_iter() + .map(<N as MapIndexKey>::Owned::from) + .collect::<Vec<_>>();As per coding guidelines
**/*.rs: "Prefer explicitSomeType::from(x)over implicitx.into()in Rust".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/segment/src/index/field_index/map_index/mutable_map_index/lifecycle.rs` around lines 103 - 109, In add_many_to_map, replace implicit .into() calls with explicit From conversions: use the concrete owned key type's from (e.g., <Owned>::from(value)) when calling self.inner.map.entry(...) and when pushing to self.inner.point_to_values, and replace values.into_iter().map(Into::into) with values.into_iter().map(<Owned>::from). Update all occurrences in this function (entry(...) and the values mapping) to use the explicit <Owned>::from(...) form so it matches the repo's Rust guideline.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/segment/src/index/field_index/map_index/mutable_map_index/lifecycle.rs`:
- Around line 103-109: In add_many_to_map, replace implicit .into() calls with
explicit From conversions: use the concrete owned key type's from (e.g.,
<Owned>::from(value)) when calling self.inner.map.entry(...) and when pushing to
self.inner.point_to_values, and replace values.into_iter().map(Into::into) with
values.into_iter().map(<Owned>::from). Update all occurrences in this function
(entry(...) and the values mapping) to use the explicit <Owned>::from(...) form
so it matches the repo's Rust guideline.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 380bf8f2-7598-4076-b71f-09a52da3c673
📒 Files selected for processing (6)
lib/segment/src/index/field_index/map_index/mutable_map_index/inner.rslib/segment/src/index/field_index/map_index/mutable_map_index/lifecycle.rslib/segment/src/index/field_index/map_index/mutable_map_index/mod.rslib/segment/src/index/field_index/map_index/mutable_map_index/read_only/mod.rslib/segment/src/index/field_index/map_index/mutable_map_index/read_only/read_ops.rslib/segment/src/index/field_index/map_index/mutable_map_index/read_ops.rs
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR refactors Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
…dex skeleton (#9020) * refactor(map_index): extract MutableMapIndexInner; add ReadOnlyAppendableMapIndex Extract the four in-memory fields (`map`, `point_to_values`, `indexed_points`, `values_count`) of `MutableMapIndex<N>` into a shared inner struct `MutableMapIndexInner<N>` under `mutable_map_index/inner.rs`. The `MapIndexRead<N>` impl moves wholesale onto the inner. `MutableMapIndex<N>` becomes a thin wrapper `{ inner, storage: Gridstore<...> }`; its `MapIndexRead<N>` impl forwards to the inner. The Gridstore load loop in `open_gridstore` collapses to `MutableMapIndexInner::empty()` + `inner.ingest(idx, value)` per row, sharing the per-value ingestion path with the future read-only loader. Add a new sibling `mutable_map_index/read_only/` module containing `ReadOnlyAppendableMapIndex<N>` (inner + `GridstoreReader<Vec<...>, MmapFile>`), with its `MapIndexRead<N>` impl forwarding to the same inner. No constructor yet — loading and lifecycle for the read-only variant will land in a follow-up. Field `storage` is held to pin the on-disk type and tagged `#[allow(dead_code)]` until then. No behavioural change. The 17 existing map_index tests pass unchanged. * expose storage generic
Summary
MutableMapIndex<N>'s four in-memory fields (map,point_to_values,indexed_points,values_count) into a shared inner structMutableMapIndexInner<N>inmutable_map_index/inner.rs. TheMapIndexRead<N>impl moves wholesale onto the inner.MutableMapIndex<N>becomes a thin wrapper{ inner, storage: Gridstore<...> }. ItsMapIndexRead<N>impl forwards to the inner. The Gridstore load loop inopen_gridstorecollapses toMutableMapIndexInner::empty()+inner.ingest(idx, value)per row.mutable_map_index/read_only/containingReadOnlyAppendableMapIndex<N>— same inner +GridstoreReader<Vec<...>, MmapFile>instead ofGridstore. ItsMapIndexRead<N>impl forwards to the same inner, so the read-method bodies are shared across the two storage variants.open,files,populate, …) will land in a follow-up. Thestoragefield carries an#[allow(dead_code)]until then.Pure refactor — no behavioural change.
Test plan
cargo check -p segment --tests— cleancargo test -p segment --lib index::field_index::map_index::— all 17 existing tests pass unchangedReadOnlyAppendableMapIndex::open(path)constructor and a cross-load test that writes viaMutableMapIndex, reopens viaReadOnlyAppendableMapIndex, and asserts read parity through the shared inner.