Repository navigation
[UIO] Universal load numeric index - #9234
Conversation
📝 WalkthroughWalkthroughThis PR refactors the numeric index infrastructure to decouple from concrete memory-mapped filesystem backends. The public Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 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
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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/segment/src/index/field_index/numeric_index/universal_numeric_index/lifecycle.rs (1)
128-134:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAvoid
Path::is_file()in the generic open path.This existence check bypasses
fsentirely, soopen()will returnOk(None)for indexes that are visible throughS::Fsbut not through the host filesystem. Please make the “missing index” check backend-aware as well.🤖 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/numeric_index/universal_numeric_index/lifecycle.rs` around lines 128 - 134, Remove the Path::is_file() shortcut and make the “missing index” check backend-aware by attempting to read the JSON config via read_json_via(fs, &config_path) and treating a not-found error as Ok(None); only on success of read_json_via proceed to call Histogram::<T>::load_via(fs, path) (or if load_via must run first, run load_via and read_json_via and treat any backend-not-found error from either call as Ok(None)). Concretely: replace the is_file() check with a call to read_json_via inside a match/Result handler that maps the filesystem-specific NotFound/DoesNotExist error into Ok(None) and propagates other errors, then continue to call Histogram::<T>::load_via and use the returned config; reference functions/config_path, read_json_via, Histogram::<T>::load_via and the open() path so the change is applied in the generic open implementation.
🤖 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/index/field_index/numeric_index/universal_numeric_index/lifecycle.rs`:
- Around line 36-37: The build implementation for UniversalNumericIndex::<_,
S>::build currently hardcodes local-mmap persistence (using MmapFs/MmapBitSlice
and host-fs helpers) despite accepting any S: UniversalRead; either make
persistence backend-agnostic by routing all file writes and bit-slice writes
through the generic filesystem type S::Fs (replace uses of MmapFs/MmapBitSlice
and host-fs helpers with S::Fs-backed APIs and factory methods, and ensure any
bit-slice serialization uses a generic trait implemented by the chosen Fs), or
revert the public signature to require the mmap-specific backend (remove the
generic S: UniversalRead or bound S to the mmap Fs) until write support for
arbitrary S is implemented; update UniversalNumericIndex::build and the related
helper calls (the sections around lines referenced: 36-37, 50-57, 59-67, 81-109)
to consistently follow one of these two approaches.
- Around line 148-158: The call to StoredBitSlice::open for deleted_payload_mmap
sets OpenOptions { writeable: true }, but StoredBitSlice::open is implemented
for S: UniversalRead so using a writeable flag may require mutable FS capability
and break read-only backends; inspect StoredBitSlice::open and the UniversalRead
trait to confirm whether options.writeable is actually used for write operations
or requires Fs::write methods, and if it does, change the OpenOptions passed at
the call site to writeable: false (or provide a separate read-only open path) so
the call respects the UniversalRead contract; update references to OpenOptions
in lifecycle.rs where deleted_payload_mmap is opened and ensure tests cover
read-only backends.
---
Outside diff comments:
In
`@lib/segment/src/index/field_index/numeric_index/universal_numeric_index/lifecycle.rs`:
- Around line 128-134: Remove the Path::is_file() shortcut and make the “missing
index” check backend-aware by attempting to read the JSON config via
read_json_via(fs, &config_path) and treating a not-found error as Ok(None); only
on success of read_json_via proceed to call Histogram::<T>::load_via(fs, path)
(or if load_via must run first, run load_via and read_json_via and treat any
backend-not-found error from either call as Ok(None)). Concretely: replace the
is_file() check with a call to read_json_via inside a match/Result handler that
maps the filesystem-specific NotFound/DoesNotExist error into Ok(None) and
propagates other errors, then continue to call Histogram::<T>::load_via and use
the returned config; reference functions/config_path, read_json_via,
Histogram::<T>::load_via and the open() path so the change is applied in the
generic open implementation.
🪄 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: dfa2187a-134f-44d5-a746-eef8349037fd
📒 Files selected for processing (14)
lib/segment/benches/numeric_index_check_values.rslib/segment/src/index/field_index/histogram.rslib/segment/src/index/field_index/numeric_index/builders.rslib/segment/src/index/field_index/numeric_index/immutable_numeric_index/lifecycle.rslib/segment/src/index/field_index/numeric_index/immutable_numeric_index/mod.rslib/segment/src/index/field_index/numeric_index/mod.rslib/segment/src/index/field_index/numeric_index/mutable_numeric_index/lifecycle.rslib/segment/src/index/field_index/numeric_index/storage/lifecycle.rslib/segment/src/index/field_index/numeric_index/storage/mod.rslib/segment/src/index/field_index/numeric_index/storage/read_only/mod.rslib/segment/src/index/field_index/numeric_index/universal_numeric_index/lifecycle.rslib/segment/src/index/field_index/numeric_index/universal_numeric_index/mod.rslib/segment/src/index/field_index/numeric_index/universal_numeric_index/read_ops.rslib/segment/src/index/field_index/tests/histogram_tests.rs
| /// TODO: save using `S::Fs` too | ||
| pub fn build( |
There was a problem hiding this comment.
build still hardcodes mmap/local-disk writes despite exposing arbitrary S.
UniversalNumericIndex::<_, S>::build now accepts any S: UniversalRead, but this implementation still persists state through host-fs helpers and MmapFs/MmapBitSlice. That means the new signature advertises backend-agnostic construction while the body still only builds a local mmap layout.
Either push these writes behind S::Fs too, or keep build specialized to the mmap backend until write support exists.
Also applies to: 50-57, 59-67, 81-109
🤖 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/numeric_index/universal_numeric_index/lifecycle.rs`
around lines 36 - 37, The build implementation for UniversalNumericIndex::<_,
S>::build currently hardcodes local-mmap persistence (using MmapFs/MmapBitSlice
and host-fs helpers) despite accepting any S: UniversalRead; either make
persistence backend-agnostic by routing all file writes and bit-slice writes
through the generic filesystem type S::Fs (replace uses of MmapFs/MmapBitSlice
and host-fs helpers with S::Fs-backed APIs and factory methods, and ensure any
bit-slice serialization uses a generic trait implemented by the chosen Fs), or
revert the public signature to require the mmap-specific backend (remove the
generic S: UniversalRead or bound S to the mmap Fs) until write support for
arbitrary S is implemented; update UniversalNumericIndex::build and the related
helper calls (the sections around lines referenced: 36-37, 50-57, 59-67, 81-109)
to consistently follow one of these two approaches.
| let deleted_payload_mmap = StoredBitSlice::<S>::open( | ||
| fs, | ||
| &deleted_path, | ||
| OpenOptions { | ||
| writeable: true, | ||
| need_sequential: false, | ||
| populate: Populate::Auto, | ||
| advice: AdviceSetting::Global, | ||
| }, | ||
| (), | ||
| Default::default(), | ||
| )?; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Inspect StoredBitSlice::open definition:"
fd -a 'stored_bitslice\.rs$' . | xargs -r rg -n -C3 'fn open\(|struct StoredBitSlice|impl .*StoredBitSlice'
echo
echo "Inspect call sites using StoredBitSlice::<...>::open:"
rg -n -C2 'StoredBitSlice::<.*>::open\('Repository: qdrant/qdrant
Length of output: 2441
Fix OpenOptions usage vs UniversalRead contract
StoredBitSlice::open is implemented under impl<S: UniversalRead>, but the call site opens deleted_payload_mmap with OpenOptions { writeable: true, ... }. Inspect StoredBitSlice::open to see whether options.writeable actually requires mutable filesystem/backends (trait bounds or Fs operations); otherwise this may be a harmless flag. If it does require write-capable backends, this would indeed break read-only backends and should be set to writeable: false (or split the API by capability).
🤖 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/numeric_index/universal_numeric_index/lifecycle.rs`
around lines 148 - 158, The call to StoredBitSlice::open for
deleted_payload_mmap sets OpenOptions { writeable: true }, but
StoredBitSlice::open is implemented for S: UniversalRead so using a writeable
flag may require mutable FS capability and break read-only backends; inspect
StoredBitSlice::open and the UniversalRead trait to confirm whether
options.writeable is actually used for write operations or requires Fs::write
methods, and if it does, change the OpenOptions passed at the call site to
writeable: false (or provide a separate read-only open path) so the call
respects the UniversalRead contract; update references to OpenOptions in
lifecycle.rs where deleted_payload_mmap is opened and ensure tests cover
read-only backends.
* rename module, use read_via * propagate S to `UniversalNumericIndex<T, S>`
This PR propagates the
S: UniversalReadto numeric index by:UniversalRead, usingread_viauniversal_numeric_index