Skip to content

feat: add readonly null index open - #9197

Merged
dancixx merged 4 commits into
devfrom
feat/readonly-nullindex-open
May 29, 2026
Merged

dancixx merged 4 commits into
devfrom
feat/readonly-nullindex-open

Conversation

@dancixx

@dancixx dancixx commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

All Submissions:

⚠️ PRs must target the dev branch. If your PR targets master, please change the base branch to dev before requesting a review.

  • My PR targets the dev branch (not master) and my branch was created 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 --workspace --all-features command?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@coderabbitai

coderabbitai Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 984ca882-66f0-47da-9a10-d7c84882fcf7

📥 Commits

Reviewing files that changed from the base of the PR and between d86f4b2 and bddec66.

📒 Files selected for processing (1)
  • lib/segment/src/common/flags/read_only_roaring_flags.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/segment/src/common/flags/read_only_roaring_flags.rs

📝 Walkthrough

Walkthrough

Adds 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

  • qdrant/qdrant#9019: Both PRs modify the read-only flags layer in lib/segment/src/common/flags/read_only_roaring_flags.rs—one retains StoredBitSlice backing while the other materializes and drops it.
  • qdrant/qdrant#8893: Prior refactor of DynamicStoredFlags/StoredBitSlice foundation that this PR builds upon by adding iter_ones.
  • qdrant/qdrant#8760: Related edits to StoredBitSlice-based flag iteration and associated dynamic flags logic.

Suggested labels

release:1.18.0

Suggested reviewers

  • generall
  • coszio
  • timvisee

Poem

🐇 I hop through bits both owned and borrowed,
Counting ones where zeros once furrowed,
Flags unfurl as Roaring maps wake,
Read-only doors open without a break,
A happy rabbit cheers the code I helped make.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'feat: add readonly null index open' directly aligns with the primary change: adding the ReadOnlyNullIndex::open method.
Description check ✅ Passed The PR description confirms completion of contributor checklists and indicates tests pass and code is properly formatted, though it lacks implementation details.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 08ab77f and daf434f.

📒 Files selected for processing (5)
  • lib/common/common/src/stored_bitslice.rs
  • lib/segment/src/common/flags/dynamic_stored_flags.rs
  • lib/segment/src/common/flags/read_only_roaring_flags.rs
  • lib/segment/src/index/field_index/null_index/read_only_null_index/lifecycle.rs
  • lib/segment/src/index/field_index/null_index/read_only_null_index/mod.rs

Comment on lines +285 to +287
// 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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

Comment on lines +84 to +86
let bitmap = RoaringBitmap::from_sorted_iter(
flags_storage.iter_set_bits()?.map(|i| i as PointOffsetType),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

@dancixx
dancixx marked this pull request as ready for review May 28, 2026 08:46
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

@dancixx
dancixx marked this pull request as draft May 28, 2026 20:38
@dancixx
dancixx marked this pull request as ready for review May 29, 2026 11:49
@dancixx
dancixx requested a review from generall May 29, 2026 11:50

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
lib/segment/src/common/flags/read_only_roaring_flags.rs (1)

81-84: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Materialization should filter by len and guard the u64→u32 narrowing.

The iterator yields all set bits from the file's physical capacity, which may exceed the logical len read from status. Additionally, the as PointOffsetType cast truncates u64 to u32 without validation. Filter indices to < len and 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8c3b322 and d86f4b2.

📒 Files selected for processing (6)
  • lib/common/common/Cargo.toml
  • lib/common/common/src/stored_bitslice.rs
  • lib/segment/src/common/flags/dynamic_stored_flags.rs
  • lib/segment/src/common/flags/read_only_roaring_flags.rs
  • lib/segment/src/common/flags/roaring_flags.rs
  • lib/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

@dancixx
dancixx requested a review from coszio May 29, 2026 20:23
@dancixx
dancixx merged commit 6c7458d into dev May 29, 2026
11 of 12 checks passed
@dancixx
dancixx deleted the feat/readonly-nullindex-open branch May 29, 2026 20:51
@generall generall added this to the Live-reload milestone May 30, 2026
timvisee pushed a commit that referenced this pull request Jun 3, 2026
* 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]>
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