Skip to content

feat(universal_io): MultiUniversalRead trait and VecMultiUniversalRead implementation - #8255

Merged
generall merged 7 commits into
devfrom
multi-file-universal-io
Mar 2, 2026
Merged

generall merged 7 commits into
devfrom
multi-file-universal-io

Conversation

@generall

@generall generall commented Mar 1, 2026

Copy link
Copy Markdown
Member

Adds the multi-source universal I/O interface and minimal mmap-based implementation as planned in docs/design/multi-file-universal-io-plan.md.

Changes

  • SourceId type and MultiUniversalRead<T> trait with read_batch_multi, optional source_len, populate, clear_ram_cache
  • UniversalIoError::InvalidSourceId variant
  • VecMultiUniversalRead<T, S>: holds Vec<S: UniversalRead<T>>, implements MultiUniversalRead, supports attach(source) -> SourceId
  • Unit test vec_multi_universal_read_batch_and_attach using MmapUniversal
  • segment: handle InvalidSourceId in From<UniversalIoError> for OperationError

No gridstore or other call-site changes in this PR; focus is interface + minimal impl only.

Made with Cursor

@coszio
coszio self-requested a review March 2, 2026 15:38
@generall
generall force-pushed the tracker-universal-io branch from d76e83a to 519cc7b Compare March 2, 2026 15:39
Base automatically changed from tracker-universal-io to dev March 2, 2026 17:04
mnaumanofficial13-svg and others added 7 commits March 2, 2026 18:07
…lRead impl

- Add SourceId, MultiUniversalRead<T> trait with read_batch_multi, source_len,
  populate, clear_ram_cache (latter two with default no-op).
- Add UniversalIoError::InvalidSourceId for invalid source id in batch reads.
- Add VecMultiUniversalRead<T, S>: minimal implementation over Vec<S: UniversalRead<T>>
  with attach(source) -> SourceId for adding sources at runtime.
- Add test vec_multi_universal_read_batch_and_attach using MmapUniversal.
- Handle InvalidSourceId in segment OperationError From<UniversalIoError>.

Implements the interface and minimal mmap-based implementation from
docs/design/multi-file-universal-io-plan.md (multi-source universal I/O).

Made-with: Cursor
… drop plan from PR

- Add universal_io/multi_universal_read.rs with SourceId, MultiUniversalRead,
  VecMultiUniversalRead and test; re-export from mod.rs.
- Remove docs/design/multi-file-universal-io-plan.md from the branch.

Made-with: Cursor
…tach, len, is_empty to trait

- MultiUniversalRead: remove default impls for populate() and clear_ram_cache();
  they are now required.
- Add to trait: new(), len(), is_empty() (default), attach() (default Err).
- Introduce associated type Source for attach; add AttachUnsupported<T>
  placeholder for impls that do not support dynamic attach.
- VecMultiUniversalRead: type Source = S; implement all trait methods.
- Re-export AttachUnsupported from universal_io.

Made-with: Cursor
…all impls

- Drop AttachUnsupported placeholder type and its UniversalRead/Send impls.
- Make attach() a required method on MultiUniversalRead (no default).
- Doc: all implementations must support attaching sources dynamically.
- Remove AttachUnsupported from re-exports.

Made-with: Cursor
…, add MultiUniversalWrite

MultiUniversalRead:
- Remove type Source; attach(path, options) opens by path and returns SourceId.
- new(options: OpenOptions) for creating an empty multi-source view.
- Move VecMultiUniversalRead to vec_multi_universal_read.rs.

MultiUniversalWrite (new):
- Trait: new(options), len(), is_empty(), attach(path, options),
  write_batch_multi((SourceId, offset, data)...), source_len, flusher(),
  populate(), clear_ram_cache().
- VecMultiUniversalWrite in vec_multi_universal_write.rs; flusher()
  runs all source flushers.

Re-export MultiUniversalWrite, VecMultiUniversalWrite from universal_io.

Made-with: Cursor
Make MultiUniversalWrite<T>: MultiUniversalRead<T> like UniversalWrite
extends UniversalRead. Remove duplicated methods (new, len, is_empty,
attach, source_len, populate, clear_ram_cache) from the write trait;
keep only write_batch_multi and flusher. VecMultiUniversalWrite now
impl MultiUniversalRead and MultiUniversalWrite separately.

Made-with: Cursor
@generall
generall force-pushed the multi-file-universal-io branch from 9711c9f to 7cb4d42 Compare March 2, 2026 17:07
@coderabbitai

coderabbitai Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request introduces a multi-source I/O abstraction layer to the universal_io module. It adds three new modules (multi_universal_read, multi_universal_write, vec_multi_universal_io) that define traits and implementations for batched reads and writes across multiple attached sources. A new error variant InvalidSourceId is added to UniversalIoError to handle invalid source references. A concrete implementation VecMultiUniversalIo manages multiple source backends and provides batch operation support with sequential/parallel read modes and aggregated flush operations. Error conversion handling is updated to map the new error variant to OperationError.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Universal I/O #8183 — Directly extends the universal_io module with multi-source I/O traits and implementations that depend on types introduced here.
  • universal io mmap #8196 — Modifies UniversalIoError and related types in the same universal_io module.
  • new GridstoreError #7780 — Updates error conversion logic in operation_error.rs for UniversalIoError variants.

Suggested reviewers

  • ffuugoo
  • xzfc
  • coszio
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: introducing MultiUniversalRead trait and VecMultiUniversalRead implementation for multi-source I/O operations.
Description check ✅ Passed The description is directly related to the changeset, detailing the new MultiUniversalRead trait, SourceId type, VecMultiUniversalRead implementation, error handling, and test additions.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch multi-file-universal-io

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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 the current code and only fix it if needed.

Inline comments:
In `@lib/common/common/src/universal_io/multi_universal_read.rs`:
- Around line 42-43: The doc for source_len currently states the method is
optional with a default, but the trait method signature on MultiUniversalRead
(fn source_len(&self, source_id: SourceId) -> Result<u64>) has no default
implementation; update the doc to state that implementors must provide
source_len and that it returns the length in elements for the given SourceId (or
an error) — reference the method name source_len, the SourceId type, and the
Result<u64> return to make the contract clear.

In `@lib/common/common/src/universal_io/vec_multi_universal_io.rs`:
- Around line 108-115: The multi-source flusher currently returns on the first
error, causing later sources not to flush; update the flusher() closure in
vec_multi_universal_io::flusher to invoke every Flusher in the collected Vec
(iterate and call each f()), record the first Err encountered (but continue
calling remaining flushers), and after the loop return that first Err if any or
Ok(()) otherwise; refer to the flusher() method and the Flusher type when making
this change.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13ded7a and 7cb4d42.

📒 Files selected for processing (5)
  • lib/common/common/src/universal_io/mod.rs
  • lib/common/common/src/universal_io/multi_universal_read.rs
  • lib/common/common/src/universal_io/multi_universal_write.rs
  • lib/common/common/src/universal_io/vec_multi_universal_io.rs
  • lib/segment/src/common/operation_error.rs

Comment on lines +42 to +43
/// Length in elements of the given source. Optional; default returns unsupported error.
fn source_len(&self, source_id: SourceId) -> Result<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 | 🟡 Minor

Fix the source_len doc/API mismatch.

Line 42 says this method is optional with a default behavior, but Line 43 defines it as required (no default impl). Please update the doc to match the actual contract.

✏️ Proposed doc fix
-    /// Length in elements of the given source. Optional; default returns unsupported error.
+    /// Length in elements of the given source.
📝 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
/// Length in elements of the given source. Optional; default returns unsupported error.
fn source_len(&self, source_id: SourceId) -> Result<u64>;
/// Length in elements of the given source.
fn source_len(&self, source_id: SourceId) -> Result<u64>;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/common/common/src/universal_io/multi_universal_read.rs` around lines 42 -
43, The doc for source_len currently states the method is optional with a
default, but the trait method signature on MultiUniversalRead (fn
source_len(&self, source_id: SourceId) -> Result<u64>) has no default
implementation; update the doc to state that implementors must provide
source_len and that it returns the length in elements for the given SourceId (or
an error) — reference the method name source_len, the SourceId type, and the
Result<u64> return to make the contract clear.

@generall
generall merged commit 9b34419 into dev Mar 2, 2026
13 checks passed
@generall
generall deleted the multi-file-universal-io branch March 2, 2026 17:19
@generall generall added this to the Universal IO milestone Mar 26, 2026
generall added a commit that referenced this pull request Mar 26, 2026
…d implementation (#8255)

* feat(universal_io): add MultiUniversalRead trait and VecMultiUniversalRead impl

- Add SourceId, MultiUniversalRead<T> trait with read_batch_multi, source_len,
  populate, clear_ram_cache (latter two with default no-op).
- Add UniversalIoError::InvalidSourceId for invalid source id in batch reads.
- Add VecMultiUniversalRead<T, S>: minimal implementation over Vec<S: UniversalRead<T>>
  with attach(source) -> SourceId for adding sources at runtime.
- Add test vec_multi_universal_read_batch_and_attach using MmapUniversal.
- Handle InvalidSourceId in segment OperationError From<UniversalIoError>.

Implements the interface and minimal mmap-based implementation from
docs/design/multi-file-universal-io-plan.md (multi-source universal I/O).

Made-with: Cursor

* refactor(universal_io): move multi-source interface to separate file, drop plan from PR

- Add universal_io/multi_universal_read.rs with SourceId, MultiUniversalRead,
  VecMultiUniversalRead and test; re-export from mod.rs.
- Remove docs/design/multi-file-universal-io-plan.md from the branch.

Made-with: Cursor

* refactor(universal_io): require populate/clear_ram_cache; add new, attach, len, is_empty to trait

- MultiUniversalRead: remove default impls for populate() and clear_ram_cache();
  they are now required.
- Add to trait: new(), len(), is_empty() (default), attach() (default Err).
- Introduce associated type Source for attach; add AttachUnsupported<T>
  placeholder for impls that do not support dynamic attach.
- VecMultiUniversalRead: type Source = S; implement all trait methods.
- Re-export AttachUnsupported from universal_io.

Made-with: Cursor

* refactor(universal_io): remove AttachUnsupported; require attach for all impls

- Drop AttachUnsupported placeholder type and its UniversalRead/Send impls.
- Make attach() a required method on MultiUniversalRead (no default).
- Doc: all implementations must support attaching sources dynamically.
- Remove AttachUnsupported from re-exports.

Made-with: Cursor

* refactor(universal_io): attach by path, new(options), split vec impls, add MultiUniversalWrite

MultiUniversalRead:
- Remove type Source; attach(path, options) opens by path and returns SourceId.
- new(options: OpenOptions) for creating an empty multi-source view.
- Move VecMultiUniversalRead to vec_multi_universal_read.rs.

MultiUniversalWrite (new):
- Trait: new(options), len(), is_empty(), attach(path, options),
  write_batch_multi((SourceId, offset, data)...), source_len, flusher(),
  populate(), clear_ram_cache().
- VecMultiUniversalWrite in vec_multi_universal_write.rs; flusher()
  runs all source flushers.

Re-export MultiUniversalWrite, VecMultiUniversalWrite from universal_io.

Made-with: Cursor

* universal_io: MultiUniversalWrite extends MultiUniversalRead

Make MultiUniversalWrite<T>: MultiUniversalRead<T> like UniversalWrite
extends UniversalRead. Remove duplicated methods (new, len, is_empty,
attach, source_len, populate, clear_ram_cache) from the write trait;
keep only write_batch_multi and flusher. VecMultiUniversalWrite now
impl MultiUniversalRead and MultiUniversalWrite separately.

Made-with: Cursor

* [manual] final fixes

---------

Co-authored-by: Cursor Agent <[email protected]>
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
…d implementation (#8255)

* feat(universal_io): add MultiUniversalRead trait and VecMultiUniversalRead impl

- Add SourceId, MultiUniversalRead<T> trait with read_batch_multi, source_len,
  populate, clear_ram_cache (latter two with default no-op).
- Add UniversalIoError::InvalidSourceId for invalid source id in batch reads.
- Add VecMultiUniversalRead<T, S>: minimal implementation over Vec<S: UniversalRead<T>>
  with attach(source) -> SourceId for adding sources at runtime.
- Add test vec_multi_universal_read_batch_and_attach using MmapUniversal.
- Handle InvalidSourceId in segment OperationError From<UniversalIoError>.

Implements the interface and minimal mmap-based implementation from
docs/design/multi-file-universal-io-plan.md (multi-source universal I/O).

Made-with: Cursor

* refactor(universal_io): move multi-source interface to separate file, drop plan from PR

- Add universal_io/multi_universal_read.rs with SourceId, MultiUniversalRead,
  VecMultiUniversalRead and test; re-export from mod.rs.
- Remove docs/design/multi-file-universal-io-plan.md from the branch.

Made-with: Cursor

* refactor(universal_io): require populate/clear_ram_cache; add new, attach, len, is_empty to trait

- MultiUniversalRead: remove default impls for populate() and clear_ram_cache();
  they are now required.
- Add to trait: new(), len(), is_empty() (default), attach() (default Err).
- Introduce associated type Source for attach; add AttachUnsupported<T>
  placeholder for impls that do not support dynamic attach.
- VecMultiUniversalRead: type Source = S; implement all trait methods.
- Re-export AttachUnsupported from universal_io.

Made-with: Cursor

* refactor(universal_io): remove AttachUnsupported; require attach for all impls

- Drop AttachUnsupported placeholder type and its UniversalRead/Send impls.
- Make attach() a required method on MultiUniversalRead (no default).
- Doc: all implementations must support attaching sources dynamically.
- Remove AttachUnsupported from re-exports.

Made-with: Cursor

* refactor(universal_io): attach by path, new(options), split vec impls, add MultiUniversalWrite

MultiUniversalRead:
- Remove type Source; attach(path, options) opens by path and returns SourceId.
- new(options: OpenOptions) for creating an empty multi-source view.
- Move VecMultiUniversalRead to vec_multi_universal_read.rs.

MultiUniversalWrite (new):
- Trait: new(options), len(), is_empty(), attach(path, options),
  write_batch_multi((SourceId, offset, data)...), source_len, flusher(),
  populate(), clear_ram_cache().
- VecMultiUniversalWrite in vec_multi_universal_write.rs; flusher()
  runs all source flushers.

Re-export MultiUniversalWrite, VecMultiUniversalWrite from universal_io.

Made-with: Cursor

* universal_io: MultiUniversalWrite extends MultiUniversalRead

Make MultiUniversalWrite<T>: MultiUniversalRead<T> like UniversalWrite
extends UniversalRead. Remove duplicated methods (new, len, is_empty,
attach, source_len, populate, clear_ram_cache) from the write trait;
keep only write_batch_multi and flusher. VecMultiUniversalWrite now
impl MultiUniversalRead and MultiUniversalWrite separately.

Made-with: Cursor

* [manual] final fixes

---------

Co-authored-by: Cursor Agent <[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