Skip to content

[UIO, gridstore] generic Bitmask storage - #8501

Merged
coszio merged 5 commits into
devfrom
generic-bitmask-store
Apr 21, 2026
Merged

coszio merged 5 commits into
devfrom
generic-bitmask-store

Conversation

@coszio

@coszio coszio commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Refactors gridstore's Bitmask to use a generic backend for interacting with storage. Particularly, it does it for BitmaskGaps slice, and for the main bitslice itself.

In doing so, I also moved the stored_bitslice.rs from segment into common

@coszio
coszio force-pushed the generic-bitmask-store branch 3 times, most recently from 6393eac to c6b05ab Compare March 25, 2026 19:32
@coszio
coszio marked this pull request as ready for review March 25, 2026 19:32
@coszio
coszio requested review from ffuugoo and generall March 25, 2026 19:33
coderabbitai[bot]

This comment was marked as resolved.

@coszio
coszio force-pushed the generic-bitmask-store branch from c6b05ab to 3a88bde Compare April 7, 2026 20:19
Comment thread lib/gridstore/src/bitmask/gaps.rs Outdated
if self.mmap_slice.len() == 1 {
return if self.get(0).unwrap().max as usize >= num_blocks as usize {
pub fn find_fitting_gap(&self, num_blocks: u32) -> Result<Option<Range<RegionId>>> {
let slice = self.as_slice()?;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note:

This reads the entire thing every time, which is potentially expensive if it is not cached in memory. Otherwise, this structure is expected to be quite small, so it should always fit in memory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the alternative, some kind of iterative/batching approach?

If my calculations are correct:

  • 1 GB stored = 6KB read here
  • 1 TB stored = 6MB read here

@xzfc xzfc Apr 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(reply to #8501 (comment))

So, ~16 KiB for a segment of 11M points. (assuming each point has a payload of 512 bytes)

I think a viable alternative is to keep the whole BitmaskGaps in the RAM.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's probably better, I'll add it to the backlog

@coszio
coszio requested a review from xzfc April 7, 2026 20:24
coderabbitai[bot]

This comment was marked as resolved.

@qdrant qdrant deleted a comment from coderabbitai Bot Apr 8, 2026
@coszio coszio added this to the Universal IO milestone Apr 8, 2026
@coszio coszio mentioned this pull request Apr 8, 2026
34 of 36 tasks
@coszio
coszio force-pushed the generic-bitmask-store branch from 3a88bde to de35f48 Compare April 8, 2026 18:29
@qdrant qdrant deleted a comment from coderabbitai Bot Apr 9, 2026
@coszio
coszio force-pushed the generic-bitmask-store branch 2 times, most recently from d8deece to cf3d190 Compare April 14, 2026 16:15
coderabbitai[bot]

This comment was marked as resolved.

@qdrant qdrant deleted a comment from coderabbitai Bot Apr 15, 2026
@coszio
coszio force-pushed the generic-bitmask-store branch from cf3d190 to 3b15ed0 Compare April 16, 2026 16:53

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/segment/benches/buffered_update_bitslice.rs (1)

5-11: ⚠️ Potential issue | 🔴 Critical

Duplicate import of MmapBitSlice will cause compilation error.

Line 5 adds the new import from the relocated common::stored_bitslice module, but line 11 still imports from the old segment::common::stored_bitslice path. Since the module was removed from segment::common, this will fail to compile.

🐛 Proposed fix: remove stale import
 use common::mmap::create_and_ensure_length;
 use common::stored_bitslice::MmapBitSlice;
 use common::universal_io::OpenOptions;
 use criterion::{Criterion, criterion_group, criterion_main};
 use rand::prelude::*;
 use rand::rngs::StdRng;
 use segment::common::buffered_update_bitslice::BufferedUpdateBitSlice;
-use segment::common::stored_bitslice::MmapBitSlice;
 use tempfile::tempdir;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/benches/buffered_update_bitslice.rs` around lines 5 - 11, The
file contains a duplicate/stale import of MmapBitSlice: remove the incorrect
import path (segment::common::stored_bitslice::MmapBitSlice) and keep the
correct one (common::stored_bitslice::MmapBitSlice) so the module resolves;
specifically edit the use statements to delete the import line that references
segment::common::stored_bitslice::MmapBitSlice and ensure BufferedUpdateBitSlice
and OpenOptions imports remain unchanged.
🧹 Nitpick comments (2)
lib/gridstore/src/bitmask/mod.rs (1)

133-140: Reuse OPEN_OPTIONS in open().

create() and cover_new_page() reopen the bitmask with explicit mutable flags, but open() switches to OpenOptions::default(). Keeping those paths aligned makes the new generic backend less surprising after restart.

♻️ Suggested change
-        let bitslice = StoredBitSlice::open(&path, OpenOptions::default())?;
+        let bitslice = StoredBitSlice::open(&path, OPEN_OPTIONS)?;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/gridstore/src/bitmask/mod.rs` around lines 133 - 140, The open() function
currently uses OpenOptions::default() to reopen the bitslice, which diverges
from create() and cover_new_page() that use the shared OPEN_OPTIONS with
explicit mutable flags; change StoredBitSlice::open(&path,
OpenOptions::default()) to reuse the existing OPEN_OPTIONS constant so open(),
create(), and cover_new_page() all open the bitmask with the same options
(update the call site in open() to pass OPEN_OPTIONS.clone() or the appropriate
reference to the shared OpenOptions value used elsewhere, ensuring types and
mutability match StoredBitSlice::open).
lib/common/common/src/stored_bitslice.rs (1)

107-139: Add direct coverage for read_bit_range().

This method now underpins bitmask gap recomputation, but this file still only exercises whole-slice and single-bit reads. A couple of empty-range and cross-u64 cases would cover the trimming logic introduced here.

If helpful, I can sketch a small test matrix for this method.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/common/common/src/stored_bitslice.rs` around lines 107 - 139, Add direct
unit tests for StoredBitslice::read_bit_range to cover the new trimming/widening
logic: write tests that call read_bit_range with an empty Range (expect empty
BitSlice), a range contained within a single u64-aligned element (single-bit and
small ranges), and a range that crosses a u64 boundary to exercise the
elem_start/elem_end widening and bit_offset/bit_end trimming. Ensure you
exercise both storage read variants by configuring the underlying storage to
return Cow::Borrowed and Cow::Owned so the BitSlice and BitVec branches are
covered; use assertions on the returned slice contents and lengths to validate
correct trimming and offsets.
🤖 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/gridstore/src/bitmask/gaps.rs`:
- Around line 149-176: The extend() method replaces the backend slice_store
without flushing prior set() updates, so flush any buffered/writer-local data on
the current self.slice_store via the UniversalWrite API (e.g., call the
appropriate flush/sync method such as flush() or sync_all() on self.slice_store
and handle its Result) before you call create_and_ensure_length() / before
reopening with S::open; ensure the flush error bubbles up rather than being
ignored so no pending gap writes are lost when slice_store is replaced.

---

Outside diff comments:
In `@lib/segment/benches/buffered_update_bitslice.rs`:
- Around line 5-11: The file contains a duplicate/stale import of MmapBitSlice:
remove the incorrect import path
(segment::common::stored_bitslice::MmapBitSlice) and keep the correct one
(common::stored_bitslice::MmapBitSlice) so the module resolves; specifically
edit the use statements to delete the import line that references
segment::common::stored_bitslice::MmapBitSlice and ensure BufferedUpdateBitSlice
and OpenOptions imports remain unchanged.

---

Nitpick comments:
In `@lib/common/common/src/stored_bitslice.rs`:
- Around line 107-139: Add direct unit tests for StoredBitslice::read_bit_range
to cover the new trimming/widening logic: write tests that call read_bit_range
with an empty Range (expect empty BitSlice), a range contained within a single
u64-aligned element (single-bit and small ranges), and a range that crosses a
u64 boundary to exercise the elem_start/elem_end widening and bit_offset/bit_end
trimming. Ensure you exercise both storage read variants by configuring the
underlying storage to return Cow::Borrowed and Cow::Owned so the BitSlice and
BitVec branches are covered; use assertions on the returned slice contents and
lengths to validate correct trimming and offsets.

In `@lib/gridstore/src/bitmask/mod.rs`:
- Around line 133-140: The open() function currently uses OpenOptions::default()
to reopen the bitslice, which diverges from create() and cover_new_page() that
use the shared OPEN_OPTIONS with explicit mutable flags; change
StoredBitSlice::open(&path, OpenOptions::default()) to reuse the existing
OPEN_OPTIONS constant so open(), create(), and cover_new_page() all open the
bitmask with the same options (update the call site in open() to pass
OPEN_OPTIONS.clone() or the appropriate reference to the shared OpenOptions
value used elsewhere, ensuring types and mutability match StoredBitSlice::open).
🪄 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: 217ead30-44bc-40f5-b9c7-de01dd4bb257

📥 Commits

Reviewing files that changed from the base of the PR and between cf3d190 and 3b15ed0.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (18)
  • lib/common/common/src/lib.rs
  • lib/common/common/src/stored_bitslice.rs
  • lib/gridstore/Cargo.toml
  • lib/gridstore/benches/bitmask_bench.rs
  • lib/gridstore/benches/real_data_bench.rs
  • lib/gridstore/src/bitmask/gaps.rs
  • lib/gridstore/src/bitmask/mod.rs
  • lib/gridstore/src/gridstore/mod.rs
  • lib/gridstore/src/gridstore/tests.rs
  • lib/segment/benches/buffered_update_bitslice.rs
  • lib/segment/src/common/buffered_update_bitslice.rs
  • lib/segment/src/common/mod.rs
  • lib/segment/src/id_tracker/immutable_id_tracker.rs
  • lib/segment/src/index/field_index/full_text_index/inverted_index/mmap_inverted_index/mod.rs
  • lib/segment/src/index/field_index/geo_index/mmap_geo_index.rs
  • lib/segment/src/index/field_index/map_index/mmap_map_index.rs
  • lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs
  • lib/segment/src/payload_storage/mmap_payload_storage.rs
💤 Files with no reviewable changes (1)
  • lib/segment/src/common/mod.rs
✅ Files skipped from review due to trivial changes (11)
  • lib/segment/src/common/buffered_update_bitslice.rs
  • lib/segment/src/id_tracker/immutable_id_tracker.rs
  • lib/common/common/src/lib.rs
  • lib/gridstore/Cargo.toml
  • lib/segment/src/index/field_index/map_index/mmap_map_index.rs
  • lib/segment/src/index/field_index/full_text_index/inverted_index/mmap_inverted_index/mod.rs
  • lib/gridstore/benches/real_data_bench.rs
  • lib/segment/src/index/field_index/geo_index/mmap_geo_index.rs
  • lib/gridstore/src/gridstore/tests.rs
  • lib/gridstore/benches/bitmask_bench.rs
  • lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/segment/src/payload_storage/mmap_payload_storage.rs

Comment on lines +149 to +176
/// Extends the file to fit the new regions
pub fn extend(&mut self, iter: impl ExactSizeIterator<Item = RegionGaps>) -> Result<()> {
let data: Vec<RegionGaps> = iter.collect();
if data.is_empty() {
return Ok(());
}

// reopen the file with a larger size
let prev_len = self.mmap_slice.len();
let new_slice_len = prev_len + iter.len();
let prev_len = self.len()?;
let new_slice_len = prev_len + data.len();
let new_length_in_bytes = new_slice_len * size_of::<RegionGaps>();

create_and_ensure_length(&self.path, new_length_in_bytes).unwrap();
create_and_ensure_length(&self.path, new_length_in_bytes)?;

let mmap = open_write_mmap(&self.path, AdviceSetting::from(Advice::Normal), false)?;

self.mmap_slice = unsafe { MmapSlice::try_from(mmap) }?;
let options = OpenOptions {
writeable: true,
need_sequential: false,
disk_parallel: None,
populate: Some(false),
advice: Some(AdviceSetting::Advice(Advice::Normal)),
prevent_caching: None,
};
self.slice_store = S::open(&self.path, options)?;

debug_assert_eq!(self.mmap_slice[prev_len..].len(), iter.len());
debug_assert_eq!(self.len()? - prev_len, data.len());

self.mmap_slice[prev_len..].fill_with(|| iter.next().unwrap());
let byte_offset = (prev_len * size_of::<RegionGaps>()) as u64;
self.slice_store.write(byte_offset, &data)?;

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

Flush pending gap writes before reopening slice_store.

extend() replaces the current backend handle after resizing the file, but it never flushes earlier set() updates. With the new generic UniversalWrite abstraction, reopening can lose or hide handle-local buffered writes, so growing the bitmask can resurrect stale gap metadata and send later allocations down the wrong search path.

🩹 Suggested fix
     pub fn extend(&mut self, iter: impl ExactSizeIterator<Item = RegionGaps>) -> Result<()> {
         let data: Vec<RegionGaps> = iter.collect();
         if data.is_empty() {
             return Ok(());
         }

+        let flusher = self.slice_store.flusher();
+        flusher()?;
+
         // reopen the file with a larger size
         let prev_len = self.len()?;
         let new_slice_len = prev_len + data.len();
         let new_length_in_bytes = new_slice_len * size_of::<RegionGaps>();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/gridstore/src/bitmask/gaps.rs` around lines 149 - 176, The extend()
method replaces the backend slice_store without flushing prior set() updates, so
flush any buffered/writer-local data on the current self.slice_store via the
UniversalWrite API (e.g., call the appropriate flush/sync method such as flush()
or sync_all() on self.slice_store and handle its Result) before you call
create_and_ensure_length() / before reopening with S::open; ensure the flush
error bubbles up rather than being ignored so no pending gap writes are lost
when slice_store is replaced.

@qdrant qdrant deleted a comment from coderabbitai Bot Apr 17, 2026
Comment thread lib/gridstore/src/bitmask/gaps.rs Outdated
if self.mmap_slice.len() == 1 {
return if self.get(0).unwrap().max as usize >= num_blocks as usize {
pub fn find_fitting_gap(&self, num_blocks: u32) -> Result<Option<Range<RegionId>>> {
let slice = self.as_slice()?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the alternative, some kind of iterative/batching approach?

If my calculations are correct:

  • 1 GB stored = 6KB read here
  • 1 TB stored = 6MB read here

@timvisee
timvisee force-pushed the generic-bitmask-store branch from 3b15ed0 to 96c8485 Compare April 17, 2026 15:31
coderabbitai[bot]

This comment was marked as resolved.

@qdrant qdrant deleted a comment from coderabbitai Bot Apr 20, 2026
Comment thread lib/gridstore/src/bitmask/gaps.rs Resolved
Comment thread lib/gridstore/src/bitmask/gaps.rs Outdated
if self.mmap_slice.len() == 1 {
return if self.get(0).unwrap().max as usize >= num_blocks as usize {
pub fn find_fitting_gap(&self, num_blocks: u32) -> Result<Option<Range<RegionId>>> {
let slice = self.as_slice()?;

@xzfc xzfc Apr 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(reply to #8501 (comment))

So, ~16 KiB for a segment of 11M points. (assuming each point has a payload of 512 bytes)

I think a viable alternative is to keep the whole BitmaskGaps in the RAM.

let gaps = Self::calculate_gaps(bitslice, self.config.region_size_blocks);

*self.regions_gaps.get_mut(region_id) = gaps;
self.regions_gaps.set(region_id, gaps)?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Performance: we can use UniversalWrite::write_batch here instead of calling UniversalWrite::write in a loop.


Or (maybe it's complicated/outside of scope of this PR), this can be merged with set_ascending_bits_batch so a single call write_multi can be used in mark_blocks_batch to write both bitmask.dat and gaps.dat.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added to #8630

@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request generalizes the storage layer in gridstore by making core types generic over storage backends. The stored_bitslice module is exposed as public in the common crate with a new read_bit_range method, and internal imports switch to crate:: paths. In gridstore, Bitmask and BitmaskGaps are parameterized over UniversalWrite storage providers, converting many previously infallible methods to fallible Result-returning ones. RegionGaps gains bytemuck derives for memory safety. All dependent code in gridstore and segment crates is updated to handle fallible APIs and import from the now-public common::stored_bitslice path.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • PR #8679 — Updates StoredBitSlice API usage and switches to generic storage patterns in buffered wrapper implementations
  • PR #8493 — Modifies stored_bitslice module and MmapBitSlice type aliases alongside UniversalRead/UniversalWrite trait changes
  • PR #8605 — Enables this refactoring by exposing common::stored_bitslice as public and introducing the read_bit_range method

Suggested reviewers

  • generall
  • ffuugoo
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main refactoring: making Bitmask use generic storage backends (UIO pattern) in gridstore.
Description check ✅ Passed The description clearly relates to the changeset, mentioning the refactoring of Bitmask to use generic storage backends and the relocation of stored_bitslice.rs.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch generic-bitmask-store

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/gridstore/src/bitmask/mod.rs (1)

413-428: ⚠️ Potential issue | 🟠 Major

Handle partial failures between bit writes and gap updates.

mark_blocks_batch mutates the bitmask first, then persists recomputed region gaps. If update_region_gaps() fails after any bit write succeeds, the persisted bitmask and gap summary diverge, and future allocation can miss free space or stop on stale candidate regions.

Please add an explicit consistency strategy here: e.g. precompute affected region states before writing, batch/transactionalize both stores where possible, or document and recover from dirty metadata on reopen.

Also applies to: 431-443

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/gridstore/src/bitmask/mod.rs` around lines 413 - 428, The code currently
mutates bits via set_ascending_bits_batch inside mark_blocks_batch then calls
update_region_gaps, which can leave bitmask and gap summaries inconsistent on
partial failure; instead precompute the affected dirty_regions and the new
region-gap state (based on current state + intended used flag) before writing,
then perform a transactional update: either call update_region_gaps first and
only apply set_ascending_bits_batch if gap-persistence succeeds, or (if the
backend supports transactions) bundle both writes together, or else implement a
compensating rollback that uses the list of successfully-written indices from
set_ascending_bits_batch to revert the bit changes on update_region_gaps
failure; reference set_ascending_bits_batch, update_region_gaps and
mark_blocks_batch when making the change.
🧹 Nitpick comments (1)
lib/gridstore/src/bitmask/mod.rs (1)

133-133: Consider using OPEN_OPTIONS for consistency with other methods opening the bitmask file.

The open() method uses OpenOptions::default() while create() and cover_new_page() use the OPEN_OPTIONS constant. Although both are writeable, using the same options throughout would be more consistent and better reflects that bitmask access is random, not sequential.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/gridstore/src/bitmask/mod.rs` at line 133, The call to
StoredBitSlice::open currently uses OpenOptions::default() which is inconsistent
with other methods (create, cover_new_page) that use the OPEN_OPTIONS constant;
update the open call in the open() method to use OPEN_OPTIONS instead of
OpenOptions::default() so all bitmask file opens use the same options and
reflect random-access writeable semantics (reference StoredBitSlice::open,
OPEN_OPTIONS, create(), cover_new_page, and the open() method where path is
passed).
🤖 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/gridstore/src/bitmask/mod.rs`:
- Around line 35-36: BitmaskStorage is declared public but bounds reference the
private type RegionGaps (from the gaps module), making the trait impossible for
external crates to name/implement; fix by either (A) making BitmaskStorage
crate-private (change to pub(crate) BitmaskStorage and its impl) or (B)
decoupling the public trait from RegionGaps by replacing the bound
UniversalWrite<RegionGaps> with a public abstraction (e.g., a public wrapper
type or a new public trait name like RegionGapWrite) or by making RegionGaps
itself public; update the BitmaskStorage declaration and its impl accordingly
(referencing BitmaskStorage, UniversalWrite, RegionGaps, and the gaps module) so
the public API no longer exposes private types.

---

Outside diff comments:
In `@lib/gridstore/src/bitmask/mod.rs`:
- Around line 413-428: The code currently mutates bits via
set_ascending_bits_batch inside mark_blocks_batch then calls update_region_gaps,
which can leave bitmask and gap summaries inconsistent on partial failure;
instead precompute the affected dirty_regions and the new region-gap state
(based on current state + intended used flag) before writing, then perform a
transactional update: either call update_region_gaps first and only apply
set_ascending_bits_batch if gap-persistence succeeds, or (if the backend
supports transactions) bundle both writes together, or else implement a
compensating rollback that uses the list of successfully-written indices from
set_ascending_bits_batch to revert the bit changes on update_region_gaps
failure; reference set_ascending_bits_batch, update_region_gaps and
mark_blocks_batch when making the change.

---

Nitpick comments:
In `@lib/gridstore/src/bitmask/mod.rs`:
- Line 133: The call to StoredBitSlice::open currently uses
OpenOptions::default() which is inconsistent with other methods (create,
cover_new_page) that use the OPEN_OPTIONS constant; update the open call in the
open() method to use OPEN_OPTIONS instead of OpenOptions::default() so all
bitmask file opens use the same options and reflect random-access writeable
semantics (reference StoredBitSlice::open, OPEN_OPTIONS, create(),
cover_new_page, and the open() method where path is passed).
🪄 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: 994e6fe9-6250-49eb-b1ef-4c3a54de0bfa

📥 Commits

Reviewing files that changed from the base of the PR and between 96c8485 and 162752a.

📒 Files selected for processing (3)
  • lib/gridstore/src/bitmask/gaps.rs
  • lib/gridstore/src/bitmask/mod.rs
  • lib/segment/benches/buffered_update_bitslice.rs
✅ Files skipped from review due to trivial changes (1)
  • lib/segment/benches/buffered_update_bitslice.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/gridstore/src/bitmask/gaps.rs

Comment on lines +35 to +36
pub trait BitmaskStorage: UniversalWrite<RegionGaps> + UniversalWrite<u64> {}
impl<T> BitmaskStorage for T where T: UniversalWrite<RegionGaps> + UniversalWrite<u64> {}

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify visibility of RegionGaps and whether private-bounds warnings are denied in this crate.

rg -n -C3 '^(pub(\([^)]*\))?\s+)?(struct|trait)\s+RegionGaps\b|^mod\s+gaps\b|pub\s+trait\s+BitmaskStorage\b'
rg -n -C3 '#!\[(deny|forbid)\((warnings|private_bounds|private_interfaces)'

Repository: qdrant/qdrant

Length of output: 1289


🏁 Script executed:

# Check for private_bounds lint configuration in crate root files
find lib/gridstore -maxdepth 2 -name "lib.rs" -o -name "mod.rs" | head -5 | xargs -I {} grep -n "private_bounds\|private_interfaces" {}

# Check for any deny/forbid directives anywhere in the crate
find lib/gridstore -name "*.rs" | xargs grep -l "#!\[(deny|forbid)" | head -3

# Check the main lib.rs for this module
cat lib/gridstore/src/lib.rs | head -50

Repository: qdrant/qdrant

Length of output: 525


🏁 Script executed:

# Check if BitmaskStorage trait is re-exported or used publicly
rg -n "BitmaskStorage" lib/gridstore/src --type rust -B2 -A2

# Check if gaps module or RegionGaps is re-exported
rg -n "pub use.*gaps\|pub use.*RegionGaps" lib/gridstore/src --type rust

Repository: qdrant/qdrant

Length of output: 824


🏁 Script executed:

# Check for Cargo.toml to see Rust edition and lint settings
cat lib/gridstore/Cargo.toml

# Check for any #![...] lint directives in lib.rs
cat lib/gridstore/src/lib.rs | grep -A5 -B5 "#!"

# Check if RegionGaps is actually exported publicly from the bitmask module
rg -n "pub use.*RegionGaps\|pub.*RegionGaps" lib/gridstore/src/bitmask/ --type rust

Repository: qdrant/qdrant

Length of output: 1432


🏁 Script executed:

# Check workspace Cargo.toml for lint configuration
find . -maxdepth 2 -name "Cargo.toml" -exec grep -l "\[lints\]" {} \;

# Check the workspace root Cargo.toml
cat Cargo.toml | head -100

Repository: qdrant/qdrant

Length of output: 2806


🏁 Script executed:

# Find and display the [lints] section in the workspace Cargo.toml
cat Cargo.toml | sed -n '/^\[lints\]/,/^\[/p' | head -50

Repository: qdrant/qdrant

Length of output: 93


🏁 Script executed:

# Check for lints definition in the workspace root or in a lints config file
rg -n "^\[lints\]" --type toml -A20 Cargo.toml

# Also check if there's a lints section after the package definition
sed -n '1,/^\[dependencies\]/p' Cargo.toml | grep -A50 "\[lints\]"

# Check if there's a lints.toml or similar config
find . -maxdepth 2 -name "*.toml" -exec grep -l "private_bounds\|private_interfaces" {} \;

Repository: qdrant/qdrant

Length of output: 1624


🏁 Script executed:

# Search the entire root Cargo.toml for the actual lints definitions
cat Cargo.toml | tail -200 | head -150

Repository: qdrant/qdrant

Length of output: 4319


🏁 Script executed:

# Search for where lints are actually defined in the workspace
grep -r "^\[lints\]" --include="*.toml" . 2>/dev/null | grep -v ".git" | head -10

# Check if there's a dedicated lints definition in the root Cargo.toml
tail -100 Cargo.toml

Repository: qdrant/qdrant

Length of output: 2502


🏁 Script executed:

# Search for the actual lints table definition in root Cargo.toml (not just [lints] header)
awk '/^\[lints\]/{flag=1; next} /^\[/{flag=0} flag' Cargo.toml

Repository: qdrant/qdrant

Length of output: 74


🏁 Script executed:

# Check if there's a cargo config directory
find . -maxdepth 3 -name ".cargo" -type d -exec find {} -name "*.toml" \;

# Check if any member crate has the actual lints definitions
for toml in lib/api/Cargo.toml lib/collection/Cargo.toml lib/gridstore/Cargo.toml; do
  echo "=== $toml ==="
  awk '/^\[lints\]/{flag=1; next} /^\[/{flag=0} flag' "$toml" | head -20
done

Repository: qdrant/qdrant

Length of output: 204


🏁 Script executed:

# Search for the actual lints definitions - they might be after the workspace definition
awk '/^\[workspace\]/{flag=1} /^\[workspace.*lints\]/{lints=1} lints' Cargo.toml | head -50

Repository: qdrant/qdrant

Length of output: 39


🏁 Script executed:

# Check the end of Cargo.toml for a workspace.lints section
tail -200 Cargo.toml | grep -A50 "\[workspace"

Repository: qdrant/qdrant

Length of output: 1118


🏁 Script executed:

# Check if there's a workspace.lints section by looking at the entire file
wc -l Cargo.toml

# Look for any lints configuration in the entire file
grep -n "lints\|lint" Cargo.toml | head -20

Repository: qdrant/qdrant

Length of output: 168


🏁 Script executed:

# Display the workspace.lints configuration
sed -n '167,220p' Cargo.toml

Repository: qdrant/qdrant

Length of output: 1707


🏁 Script executed:

# Check if BitmaskStorage is re-exported publicly or if Bitmask is the public API
rg -n "pub.*BitmaskStorage\|pub use.*BitmaskStorage" lib/gridstore/src --type rust

# Check the actual public methods and types in the bitmask module
sed -n '35,100p' lib/gridstore/src/bitmask/mod.rs

Repository: qdrant/qdrant

Length of output: 2362


🏁 Script executed:

# Check what's exported from the bitmask module in lib.rs
cat lib/gridstore/src/lib.rs

# Verify if RegionGaps is accessible from outside
rg -n "pub use.*gaps\|pub use.*RegionGaps\|pub.*gaps" lib/gridstore/src/bitmask/ --type rust

Repository: qdrant/qdrant

Length of output: 525


Avoid exposing private RegionGaps in the public storage trait.

BitmaskStorage is public, but its supertrait bounds mention RegionGaps from the private gaps module. External code cannot name or directly implement this bound because the type is from a private module, making the public trait unusable outside the crate.

Consider either keeping the generic storage API crate-private, or exposing a public storage abstraction that does not depend on RegionGaps.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/gridstore/src/bitmask/mod.rs` around lines 35 - 36, BitmaskStorage is
declared public but bounds reference the private type RegionGaps (from the gaps
module), making the trait impossible for external crates to name/implement; fix
by either (A) making BitmaskStorage crate-private (change to pub(crate)
BitmaskStorage and its impl) or (B) decoupling the public trait from RegionGaps
by replacing the bound UniversalWrite<RegionGaps> with a public abstraction
(e.g., a public wrapper type or a new public trait name like RegionGapWrite) or
by making RegionGaps itself public; update the BitmaskStorage declaration and
its impl accordingly (referencing BitmaskStorage, UniversalWrite, RegionGaps,
and the gaps module) so the public API no longer exposes private types.

@coszio
coszio merged commit 5dc2766 into dev Apr 21, 2026
15 checks passed
@coszio
coszio deleted the generic-bitmask-store branch April 21, 2026 14:07
timvisee pushed a commit that referenced this pull request May 8, 2026
* [AI + manual] generalize BitmaskGaps storage

* [AI + manual] use StoredBitSlice in Bitmask

* use MmapFile as default storage

* rename to read_all

* duplicate import
@coderabbitai coderabbitai Bot mentioned this pull request Jul 3, 2026
10 of 11 tasks
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