Skip to content

[UIO] Generic dynamic flags - #8893

Merged
coszio merged 6 commits into
devfrom
generic-dynamic-flags
May 5, 2026
Merged

coszio merged 6 commits into
devfrom
generic-dynamic-flags

Conversation

@coszio

@coszio coszio commented May 4, 2026

Copy link
Copy Markdown
Contributor

Finishes refactoring for DynamicMmapFlags, which is now renamed to DynamicStoredFlags<S>, where S is the storage backend.

As a bonus, this PR introduces StoredStruct, a wrapper to interact with a lightweight type like the status type, which only contains len: usize, but we still need to persist it. It keeps an in-memory copy that gets written entirely on flush.

@coszio coszio added this to the Universal IO milestone May 4, 2026
@coszio
coszio requested review from ffuugoo, generall and xzfc May 4, 2026 16:41
@coderabbitai

This comment was marked as low quality.

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

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/common/flags/buffered_dynamic_flags.rs (1)

15-15: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Stale doc comment — still refers to DynamicMmapFlags.

The struct-level doc says "A buffered wrapper around DynamicMmapFlags", but the type was renamed to DynamicStoredFlags.

📝 Proposed fix
-/// A buffered wrapper around DynamicMmapFlags that provides manual flushing, without interface for reading.
+/// A buffered wrapper around DynamicStoredFlags that provides manual flushing, without interface for reading.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/common/flags/buffered_dynamic_flags.rs` at line 15, Update
the stale struct-level doc comment that reads "A buffered wrapper around
DynamicMmapFlags" to reference the correct renamed type DynamicStoredFlags
(e.g., for the BufferedDynamicFlags struct), so the documentation matches the
current type names and intent; search for BufferedDynamicFlags in
buffered_dynamic_flags.rs and replace the old type name with DynamicStoredFlags
in the doc comment.
🧹 Nitpick comments (1)
lib/segment/src/common/flags/buffered_dynamic_flags.rs (1)

31-31: 💤 Low value

Stale parameter name mmap_flags — doesn't match the new type.

The parameter was renamed at the type level but the name still reads mmap_flags. Rename to stored_flags or dynamic_flags for consistency with the surrounding refactor.

♻️ Proposed fix
-    pub fn new(mmap_flags: DynamicStoredFlags<MmapFile>) -> Self {
+    pub fn new(stored_flags: DynamicStoredFlags<MmapFile>) -> Self {
         let buffer = Arc::new(RwLock::new(AHashMap::new()));
         let is_alive_flush_lock = IsAliveLock::new();
         Self {
-            storage: Arc::new(Mutex::new(mmap_flags)),
+            storage: Arc::new(Mutex::new(stored_flags)),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/common/flags/buffered_dynamic_flags.rs` at line 31, The
constructor parameter name is stale: in pub fn new(mmap_flags:
DynamicStoredFlags<MmapFile>) -> Self { } rename the parameter to reflect the
type change (e.g., stored_flags or dynamic_flags) so it matches surrounding
refactor and intent; update the parameter name in the new function signature and
all uses inside BufferedDynamicFlags::new to use the new identifier (reference:
the new function and the DynamicStoredFlags<MmapFile> type).
🤖 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/common/common/src/universal_io/wrappers/stored_struct.rs`:
- Around line 37-54: The flusher currently snapshots self.inner at creation (let
state = self.inner) so later mutations are lost; instead capture the live
reference/handle to the in-memory value and read it when the closure executes.
Replace the outer let state = self.inner with cloning/capturing the container
(e.g. Arc/Mutex or whatever type backing self.inner) and inside the closure,
after confirming is_alive and upgrading storage, read the current value from
that captured container (e.g. lock/clone/deref the inner handle) and then call
storage.write(..., &[state]) with that freshly-read state; keep all existing
checks using is_alive_lock.handle(), storage.upgrade(), storage.lock(),
storage.write(...) and storage.flusher()() intact.
- Around line 27-29: In StoredStruct::open, avoid indexing read_whole()
directly; after calling TypedStorage::open(path, options)? and let payloads =
storage.read_whole()? check that payloads.len() >= 1 and if not return an
appropriate Err (e.g. create a universal_io::Error with
InvalidData/UnexpectedEof and a clear message) instead of using payloads[0];
then proceed to use payloads[0] only after that validation so on-disk corruption
yields an error return rather than a panic.

In `@lib/segment/src/common/flags/bitvec_flags.rs`:
- Line 129: The test function name is misleading: rename the function
test_roaring_flags_consistency_after_persistence to
test_bitvec_flags_consistency_after_persistence in bitvec_flags.rs so it
correctly reflects that it tests BitvecFlags; update any internal references or
test harness entries that call this symbol (e.g., the function declaration and
any uses in #[test] annotations or modular test lists) to use the new name.

In `@lib/segment/src/common/flags/dynamic_stored_flags.rs`:
- Around line 53-56: Update the doc comment that lists buffered variants by
correcting the misspelled word "persistance" to "persistence" so Codespell CI
passes; edit the comment referencing RoaringFlags, BitvecFlags, and
BufferedDynamicFlags to use the correct spelling.

---

Outside diff comments:
In `@lib/segment/src/common/flags/buffered_dynamic_flags.rs`:
- Line 15: Update the stale struct-level doc comment that reads "A buffered
wrapper around DynamicMmapFlags" to reference the correct renamed type
DynamicStoredFlags (e.g., for the BufferedDynamicFlags struct), so the
documentation matches the current type names and intent; search for
BufferedDynamicFlags in buffered_dynamic_flags.rs and replace the old type name
with DynamicStoredFlags in the doc comment.

---

Nitpick comments:
In `@lib/segment/src/common/flags/buffered_dynamic_flags.rs`:
- Line 31: The constructor parameter name is stale: in pub fn new(mmap_flags:
DynamicStoredFlags<MmapFile>) -> Self { } rename the parameter to reflect the
type change (e.g., stored_flags or dynamic_flags) so it matches surrounding
refactor and intent; update the parameter name in the new function signature and
all uses inside BufferedDynamicFlags::new to use the new identifier (reference:
the new function and the DynamicStoredFlags<MmapFile> type).
🪄 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: 0dfad2ba-60b7-46cb-b7e3-151595bf978c

📥 Commits

Reviewing files that changed from the base of the PR and between fd4e25d and 7c152e3.

📒 Files selected for processing (13)
  • lib/common/common/src/universal_io/wrappers/mod.rs
  • lib/common/common/src/universal_io/wrappers/stored_struct.rs
  • lib/segment/benches/dynamic_mmap_flags.rs
  • lib/segment/src/common/flags/bitvec_flags.rs
  • lib/segment/src/common/flags/buffered_dynamic_flags.rs
  • lib/segment/src/common/flags/dynamic_stored_flags.rs
  • lib/segment/src/common/flags/mod.rs
  • lib/segment/src/common/flags/roaring_flags.rs
  • lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs
  • lib/segment/src/index/field_index/null_index/mutable_null_index.rs
  • lib/segment/src/vector_storage/dense/appendable_dense_vector_storage.rs
  • lib/segment/src/vector_storage/multi_dense/appendable_mmap_multi_dense_vector_storage.rs
  • lib/segment/src/vector_storage/sparse/mmap_sparse_vector_storage.rs

Comment on lines +27 to +29
pub fn open(path: impl AsRef<Path>, options: OpenOptions) -> universal_io::Result<Self> {
let storage = TypedStorage::open(path, options)?;
let inner = storage.read_whole()?[0];

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

Return an error instead of indexing the first record.

read_whole()?[0] will panic on an empty or truncated file, turning on-disk corruption into a process abort during open(). Please validate the payload length and return an I/O/format error instead.

Suggested fix
-        let inner = storage.read_whole()?[0];
+        let inner = storage
+            .read_whole()?
+            .into_iter()
+            .next()
+            .ok_or_else(|| {
+                std::io::Error::new(
+                    std::io::ErrorKind::UnexpectedEof,
+                    "stored struct file is empty",
+                )
+            })?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn open(path: impl AsRef<Path>, options: OpenOptions) -> universal_io::Result<Self> {
let storage = TypedStorage::open(path, options)?;
let inner = storage.read_whole()?[0];
pub fn open(path: impl AsRef<Path>, options: OpenOptions) -> universal_io::Result<Self> {
let storage = TypedStorage::open(path, options)?;
let inner = storage
.read_whole()?
.into_iter()
.next()
.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::UnexpectedEof,
"stored struct file is empty",
)
})?;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/common/common/src/universal_io/wrappers/stored_struct.rs` around lines 27
- 29, In StoredStruct::open, avoid indexing read_whole() directly; after calling
TypedStorage::open(path, options)? and let payloads = storage.read_whole()?
check that payloads.len() >= 1 and if not return an appropriate Err (e.g. create
a universal_io::Error with InvalidData/UnexpectedEof and a clear message)
instead of using payloads[0]; then proceed to use payloads[0] only after that
validation so on-disk corruption yields an error return rather than a panic.

use crate::common::flags::dynamic_stored_flags::DynamicStoredFlags;

#[test]
fn test_roaring_flags_consistency_after_persistence() {

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 | 🟡 Minor | ⚡ Quick win

Copy-paste test function name — wrong type referenced.

test_roaring_flags_consistency_after_persistence is in bitvec_flags.rs and tests BitvecFlags, not RoaringFlags. The name should match.

📝 Proposed fix
-    fn test_roaring_flags_consistency_after_persistence() {
+    fn test_bitvec_flags_consistency_after_persistence() {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn test_roaring_flags_consistency_after_persistence() {
fn test_bitvec_flags_consistency_after_persistence() {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/common/flags/bitvec_flags.rs` at line 129, The test function
name is misleading: rename the function
test_roaring_flags_consistency_after_persistence to
test_bitvec_flags_consistency_after_persistence in bitvec_flags.rs so it
correctly reflects that it tests BitvecFlags; update any internal references or
test harness entries that call this symbol (e.g., the function declaration and
any uses in #[test] annotations or modular test lists) to use the new name.

coderabbitai[bot]

This comment was marked as resolved.

};

let mut storage = storage.lock();
storage.write(0, &[state])?;

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.

Can our data shrink? If so, should we also shrink the file?

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.

All good, we have bytemuck::Pod on T

@coszio
coszio merged commit c1ba01b into dev May 5, 2026
15 checks passed
@coszio
coszio deleted the generic-dynamic-flags branch May 5, 2026 14:46
@coszio coszio mentioned this pull request May 5, 2026
34 of 36 tasks
timvisee pushed a commit that referenced this pull request May 8, 2026
* rename status

* impl simple StoredStruct

* use StoredStruct in `status`

* rename to `DynamicStoredFlags`

* Propagate `S` generic

* codespell nit
@coderabbitai coderabbitai Bot mentioned this pull request May 27, 2026
9 tasks done
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.

2 participants