Repository navigation
feat: add readonly null index open - #9197
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds StoredBitSlice::iter_ones with borrowed and owned paths (self_cell-backed owned iterator), updates DynamicStoredFlags to consume that iterator, changes ReadOnlyRoaringFlags to materialize an in-memory RoaringBitmap on open (dropping the stored backing), and introduces a ReadOnlyNullIndex open lifecycle and tests. Also promotes self_cell to a regular dependency and adds a default no-op RoaringFlagsRead::clear_cache. Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 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
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: 2
🤖 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.
Inline comments:
In `@lib/segment/src/common/flags/dynamic_stored_flags.rs`:
- Around line 285-287: iter_trues currently iterates over the entire storage via
self.flags.iter_set_bits() and blindly casts indices to PointOffsetType, which
can expose bits beyond self.status.len and truncate large usize values; change
iter_trues (the method using self.flags.iter_set_bits() and mapping to
PointOffsetType) to stop at the logical length by applying a take_while (or
equivalent) that only yields indices i where i < self.status.len, and before
casting each i to PointOffsetType add an explicit bound check (or assert) that i
fits into PointOffsetType (e.g., i <= PointOffsetType::MAX as usize) and handle
the error path if it does not rather than performing an unchecked cast.
In `@lib/segment/src/common/flags/read_only_roaring_flags.rs`:
- Around line 84-86: In open(), when building the RoaringBitmap via
RoaringBitmap::from_sorted_iter(...) using flags_storage.iter_set_bits() and
casting indices to PointOffsetType, restrict the iterator to only indices < len
and add an explicit guard that len <= PointOffsetType::MAX (or panic/return Err)
before any narrowing; replace the unchecked `as PointOffsetType` cast with a
checked conversion (e.g., try_from/checked cast) when mapping the filtered
indices so no unchecked usize→PointOffsetType narrowing occurs and only points
within the logical length are materialized.
🪄 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: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 25e18d0a-f03a-4af8-bef9-279d92572824
📒 Files selected for processing (5)
lib/common/common/src/stored_bitslice.rslib/segment/src/common/flags/dynamic_stored_flags.rslib/segment/src/common/flags/read_only_roaring_flags.rslib/segment/src/index/field_index/null_index/read_only_null_index/lifecycle.rslib/segment/src/index/field_index/null_index/read_only_null_index/mod.rs
| // Unused capacity past `len` is always cleared, so iterating set bits | ||
| // over the whole storage yields exactly the "true" positions. | ||
| Ok(self.flags.iter_set_bits()?.map(|i| i as PointOffsetType)) |
There was a problem hiding this comment.
Bound iter_trues() to logical length and guard PointOffsetType conversion.
This now iterates full storage capacity and blindly casts indices to PointOffsetType; that can leak out-of-len bits and truncate on large indices. Please clamp to self.status.len (e.g. take_while) and add an explicit bound check before casting.
Based on learnings: “avoid unsafe or unchecked casts from usize to PointOffsetType (u32)… validate the bound first and add an explicit assertion or guard.”
🤖 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/common/flags/dynamic_stored_flags.rs` around lines 285 - 287,
iter_trues currently iterates over the entire storage via
self.flags.iter_set_bits() and blindly casts indices to PointOffsetType, which
can expose bits beyond self.status.len and truncate large usize values; change
iter_trues (the method using self.flags.iter_set_bits() and mapping to
PointOffsetType) to stop at the logical length by applying a take_while (or
equivalent) that only yields indices i where i < self.status.len, and before
casting each i to PointOffsetType add an explicit bound check (or assert) that i
fits into PointOffsetType (e.g., i <= PointOffsetType::MAX as usize) and handle
the error path if it does not rather than performing an unchecked cast.
| let bitmap = RoaringBitmap::from_sorted_iter( | ||
| flags_storage.iter_set_bits()?.map(|i| i as PointOffsetType), | ||
| ) |
There was a problem hiding this comment.
Materialization should be bounded by len and avoid unchecked PointOffsetType narrowing.
open() reads logical len but currently builds the bitmap from all set bits in file capacity and casts with as. Please filter indices to < len and enforce a len <= PointOffsetType::MAX guard before narrowing.
Based on learnings: “avoid unsafe or unchecked casts from usize to PointOffsetType (u32)… validate the bound first and add an explicit assertion or guard.”
🤖 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/common/flags/read_only_roaring_flags.rs` around lines 84 -
86, In open(), when building the RoaringBitmap via
RoaringBitmap::from_sorted_iter(...) using flags_storage.iter_set_bits() and
casting indices to PointOffsetType, restrict the iterator to only indices < len
and add an explicit guard that len <= PointOffsetType::MAX (or panic/return Err)
before any narrowing; replace the unchecked `as PointOffsetType` cast with a
checked conversion (e.g., try_from/checked cast) when mapping the filtered
indices so no unchecked usize→PointOffsetType narrowing occurs and only points
within the logical length are materialized.
|
Actionable comments posted: 0 |
There was a problem hiding this comment.
♻️ Duplicate comments (1)
lib/segment/src/common/flags/read_only_roaring_flags.rs (1)
81-84:⚠️ Potential issue | 🟠 Major | ⚡ Quick winMaterialization should filter by
lenand guard theu64→u32narrowing.The iterator yields all set bits from the file's physical capacity, which may exceed the logical
lenread from status. Additionally, theas PointOffsetTypecast truncatesu64tou32without validation. Filter indices to< lenand add a bound check.🛡️ Proposed fix
+ let len_u64 = len as u64; let bitmap = RoaringBitmap::from_sorted_iter( - flags_storage.iter_ones()?.map(|i| i as PointOffsetType), + flags_storage + .iter_ones()? + .take_while(|&i| i < len_u64) + .map(|i| { + debug_assert!(i <= u64::from(PointOffsetType::MAX)); + i as PointOffsetType + }), ) .expect("iter_ones iterates in sorted order");Based on learnings: "avoid unsafe or unchecked casts from usize to PointOffsetType (u32)… validate the bound first and add an explicit assertion or guard."
🤖 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/common/flags/read_only_roaring_flags.rs` around lines 81 - 84, The materialization currently uses RoaringBitmap::from_sorted_iter over flags_storage.iter_ones() and casts each u64 index to PointOffsetType (u32) without bounds checks; update the iterator to first filter indices to be strictly less than the logical len (the status len variable) and then validate each index fits into PointOffsetType before narrowing (e.g., via a numeric bound check or TryFrom) so you never truncate; reference the bitmap construction at RoaringBitmap::from_sorted_iter, the source iterator flags_storage.iter_ones(), the length variable len, and the PointOffsetType cast when applying the filter and guard.
🤖 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.
Duplicate comments:
In `@lib/segment/src/common/flags/read_only_roaring_flags.rs`:
- Around line 81-84: The materialization currently uses
RoaringBitmap::from_sorted_iter over flags_storage.iter_ones() and casts each
u64 index to PointOffsetType (u32) without bounds checks; update the iterator to
first filter indices to be strictly less than the logical len (the status len
variable) and then validate each index fits into PointOffsetType before
narrowing (e.g., via a numeric bound check or TryFrom) so you never truncate;
reference the bitmap construction at RoaringBitmap::from_sorted_iter, the source
iterator flags_storage.iter_ones(), the length variable len, and the
PointOffsetType cast when applying the filter and guard.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 34e975ff-9c5d-4a4b-83cd-2e19329aa8b7
📒 Files selected for processing (6)
lib/common/common/Cargo.tomllib/common/common/src/stored_bitslice.rslib/segment/src/common/flags/dynamic_stored_flags.rslib/segment/src/common/flags/read_only_roaring_flags.rslib/segment/src/common/flags/roaring_flags.rslib/segment/src/index/field_index/null_index/read_only_null_index/lifecycle.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/segment/src/common/flags/dynamic_stored_flags.rs
* feat: add readonly null index open * feat: add get_mutability_type to ReadOnlyNullIndex * fix: pr reviews * simpler phantomdata --------- Co-authored-by: Luis Cossío <[email protected]>
All Submissions:
devbranch (notmaster) and my branch was created fromdev.New Feature Submissions:
cargo +nightly fmt --allcommand prior to submission?cargo clippy --workspace --all-featurescommand?Changes to Core Features: