Repository navigation
feat(universal_io): MultiUniversalRead trait and VecMultiUniversalRead implementation - #8255
Conversation
d76e83a to
519cc7b
Compare
…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
9711c9f to
7cb4d42
Compare
📝 WalkthroughWalkthroughThis 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
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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
🤖 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
📒 Files selected for processing (5)
lib/common/common/src/universal_io/mod.rslib/common/common/src/universal_io/multi_universal_read.rslib/common/common/src/universal_io/multi_universal_write.rslib/common/common/src/universal_io/vec_multi_universal_io.rslib/segment/src/common/operation_error.rs
| /// Length in elements of the given source. Optional; default returns unsupported error. | ||
| fn source_len(&self, source_id: SourceId) -> Result<u64>; |
There was a problem hiding this comment.
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.
| /// 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.
…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]>
…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]>
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
SourceIdtype andMultiUniversalRead<T>trait withread_batch_multi, optionalsource_len,populate,clear_ram_cacheUniversalIoError::InvalidSourceIdvariantVecMultiUniversalRead<T, S>: holdsVec<S: UniversalRead<T>>, implementsMultiUniversalRead, supportsattach(source) -> SourceIdvec_multi_universal_read_batch_and_attachusingMmapUniversalsegment: handleInvalidSourceIdinFrom<UniversalIoError>forOperationErrorNo gridstore or other call-site changes in this PR; focus is interface + minimal impl only.
Made with Cursor