Skip to content

Add TypedStorage wrapper - #8508

Merged
xzfc merged 7 commits into
devfrom
uio-typed-storage
Mar 26, 2026
Merged

xzfc merged 7 commits into
devfrom
uio-typed-storage

Conversation

@xzfc

@xzfc xzfc commented Mar 26, 2026

Copy link
Copy Markdown
Member

This PR introduces TypedStorage wrapper.

This wrapper lets you specify the type T only once in the storage type, and not on every callsite:

// before
let file = <IoUringFile as UniversalRead<u64>>::open(&path, opts)?;
let value = <IoUringFile as UniversalRead<u64>>::read::<Sequential>(&file, range)?;
let len = <IoUringFile as UniversalRead<u64>>::len(&file)?;

// after
let file = TypedStorage::<IoUringFile, u64>::open(&path, opts)?;
let value = file.read::<Sequential>(range)?;
let len = file.len()?;

Usually, it's not required as the Rust compiler is able to deduce the type T based on where clauses. But it helps when there are more than one type is used within the same structure, e.g.:

struct Storage<S> {
    counts_per_hash: TypedStorage<S, Counts>,
    points_map: TypedStorage<S, PointKeyValue>,
    points_map_ids: TypedStorage<S, PointOffsetType>,
    point_to_values: StoredPointToValues<GeoPoint, S>,
    deleted: MmapBitSliceBufferedUpdateWrapper,
}

Unlike MmapUniversal<T> that removed in #8493/#8505, this wrapper can work with any UIO implementation.

@xzfc xzfc mentioned this pull request Mar 26, 2026
@xzfc
xzfc requested review from coszio, ffuugoo and generall March 26, 2026 05:06
@coderabbitai

coderabbitai Bot commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 158a075d-0201-4a5b-9073-8b63b26cad04

📥 Commits

Reviewing files that changed from the base of the PR and between 3759376 and 5f4d1b6.

📒 Files selected for processing (1)
  • lib/common/common/src/universal_io/wrappers/typed.rs

📝 Walkthrough

Walkthrough

The PR reorganizes universal_io wrappers (making wrappers an internal module and re-exporting its contents), adds a transparent TypedStorage<S, T> wrapper that binds an element type to a backend, converts ReadOnly<S> to a transparent wrapper and adds read_whole and read_multi, removes the provided is_empty from UniversalRead<T> and adds an expectation for clippy, and inserts comments reminding maintainers to update wrapper impls when adding provided trait methods. Call sites and tests were updated to use TypedStorage (io_uring test, ChunkedVectors, ImmutableDenseVectors), and several PhantomData markers were removed.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • ffuugoo
  • coszio
  • generall
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add TypedStorage wrapper' directly and clearly summarizes the main change: introducing a new TypedStorage wrapper type.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of TypedStorage, providing before/after code examples, and noting the difference from MmapUniversal.
Docstring Coverage ✅ Passed Docstring coverage is 84.62% which is sufficient. The required threshold is 80.00%.

✏️ 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 uio-typed-storage

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.

@ffuugoo

ffuugoo commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor

<IoUringFile as UniversalRead<u64>>

Propaganda piece.

let bytes: Cow<[u8]> = file.read::<Sequential>()?;
file.read(ranges, |_, floats: &[f32]| {
    Ok(())
})

@ffuugoo

This comment was marked as resolved.

@ffuugoo

This comment was marked as duplicate.

@ffuugoo ffuugoo 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.

Personally, I'd not use TypedStorage if we have generic storage with a single trait bound. E.g., just use S instead of TypedStorage<S, T>. My logic is fewer wrappers/indirection is better. Like, I forgot provided impls in ReadOnly, and even with a comment it might happen again. 🤦‍♀️

But LGTM.

xzfc added 6 commits March 26, 2026 12:42
Reason: Less methods to override in wrappers. And I don't think this
method makes much sense.
Implement missing methods, and follow the code style of the upcoming
TypedStrorage wrapper.
@xzfc
xzfc force-pushed the uio-typed-storage branch from 83adf26 to c3f46b2 Compare March 26, 2026 12:43

@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

🤖 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/typed.rs`:
- Around line 13-26: Update the doc comment for TypedStorage to fix the typo:
change "mut" to "but" in the sentence describing when the wrapper is helpful
(the comment above the TypedStorage struct). Ensure the corrected wording
remains grammatically correct and preserves the existing explanation about
multiple UniversalRead bounds.
🪄 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: c47bdf51-1709-4645-b671-e12cb220ff70

📥 Commits

Reviewing files that changed from the base of the PR and between 83adf26 and c3f46b2.

📒 Files selected for processing (10)
  • lib/common/common/src/universal_io/file_ops.rs
  • lib/common/common/src/universal_io/io_uring.rs
  • lib/common/common/src/universal_io/mod.rs
  • lib/common/common/src/universal_io/read.rs
  • lib/common/common/src/universal_io/wrappers/mod.rs
  • lib/common/common/src/universal_io/wrappers/read_only.rs
  • lib/common/common/src/universal_io/wrappers/typed.rs
  • lib/common/common/src/universal_io/write.rs
  • lib/segment/src/vector_storage/chunked_vectors.rs
  • lib/segment/src/vector_storage/dense/immutable_dense_vectors.rs
✅ Files skipped from review due to trivial changes (4)
  • lib/common/common/src/universal_io/file_ops.rs
  • lib/common/common/src/universal_io/write.rs
  • lib/common/common/src/universal_io/wrappers/mod.rs
  • lib/common/common/src/universal_io/io_uring.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • lib/common/common/src/universal_io/mod.rs
  • lib/segment/src/vector_storage/dense/immutable_dense_vectors.rs
  • lib/common/common/src/universal_io/wrappers/read_only.rs

@xzfc
xzfc force-pushed the uio-typed-storage branch from c3f46b2 to 3759376 Compare March 26, 2026 12:59
@xzfc
xzfc force-pushed the uio-typed-storage branch from 3759376 to 5f4d1b6 Compare March 26, 2026 13:15
@xzfc
xzfc merged commit 50e4796 into dev Mar 26, 2026
15 checks passed
@xzfc
xzfc deleted the uio-typed-storage branch March 26, 2026 14:10
@generall generall added this to the Universal IO milestone Mar 26, 2026
generall pushed a commit that referenced this pull request Mar 26, 2026
* Remove UniversalRead::is_empty

Reason: Less methods to override in wrappers. And I don't think this
method makes much sense.

* Move common::universal_io::{ => wrappers}::read_only

* Update ReadOnly wrapper

Implement missing methods, and follow the code style of the upcoming
TypedStrorage wrapper.

* Add TypedStorage

* Use TypedStorage

* Add reminder comments

* Clarify TypedStorage use-case
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
* Remove UniversalRead::is_empty

Reason: Less methods to override in wrappers. And I don't think this
method makes much sense.

* Move common::universal_io::{ => wrappers}::read_only

* Update ReadOnly wrapper

Implement missing methods, and follow the code style of the upcoming
TypedStrorage wrapper.

* Add TypedStorage

* Use TypedStorage

* Add reminder comments

* Clarify TypedStorage use-case
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.

4 participants