Skip to content

Fix io_uring reads: use byte offset - #8470

Merged
generall merged 2 commits into
devfrom
fix-io-uring-reads-part-1
Mar 20, 2026
Merged

generall merged 2 commits into
devfrom
fix-io-uring-reads-part-1

Conversation

@generall

Copy link
Copy Markdown
Member

This is part 1 of

Problem:

We want to read [T] from file, which contains different datatypes in different places.
Even though, the offset from the start of the file is correct,
io_uring implementation should know T to properly allocate Vec<T>.

As a result, each read need to have it's own T and assume correct offset

Solution, discussed with Roman:

Make ElementsRange: { start -> byte_offset }, for easier navigation in files.
* This would requere adjusting usage in places, where universal IO is already implemented

Remove <T> from UniversalRead and UniversalWrite and move this parameter to read and wrire methods instead, so different types can be read from same file

* This would require changing implementation of MmapUniversal, as currently it uses MmapSlice<T> internally, which is not flexible enough.

@generall
generall requested review from coszio and ffuugoo March 20, 2026 19:24
@coderabbitai

coderabbitai Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR converts the universal I/O abstraction from element-based to byte-based offset semantics. It renames ElementsRange to ReadRange (changing the start field to byte_offset: u64), replaces the ElementOffset type alias with ByteOffset, and updates all trait method signatures in UniversalRead/UniversalWrite and their implementations across io_uring and mmap backends. Downstream call sites throughout the codebase are updated to construct ReadRange with byte offsets and pass ByteOffset values to write operations, with offset calculations adjusted where needed to convert between element and byte indices.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ffuugoo
  • coszio
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix io_uring reads: use byte offset' directly summarizes the main change—replacing element-based offsets with byte offsets in io_uring read operations.
Description check ✅ Passed The description clearly explains the problem (io_uring needs T and correct byte offsets to read typed data), the proposed solution (byte offset in ElementsRange, move T from trait to methods), and notes the change is part 1 of a larger effort.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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 fix-io-uring-reads-part-1

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.

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/vector_storage/chunked_vectors.rs (1)

171-176: ⚠️ Potential issue | 🟡 Minor

Misleading doc comment: function returns element offset, not byte offset.

The comment states "Returns the byte offset" but the function returns chunk_vector_idx * self.config.dim, which is an element offset (number of T elements). The conversion to bytes happens at the call sites (lines 245 and 307) where * size_of::<T>() is applied.

Either update the comment to accurately describe the return value, or rename the function to clarify its semantics (e.g., get_chunk_element_offset).

📝 Suggested fix for the comment
-    /// Returns the byte offset of the vector in the chunk
+    /// Returns the element offset of the vector within the chunk (in units of T elements).
     #[inline]
     fn get_chunk_offset(&self, key: usize) -> usize {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/vector_storage/chunked_vectors.rs` around lines 171 - 176,
The doc comment for get_chunk_offset is misleading: it says "Returns the byte
offset" but the function returns an element offset (chunk_vector_idx *
self.config.dim) and callers multiply by size_of::<T>() to get bytes; update the
comment to say "Returns the element offset (number of T elements) within the
chunk" or rename the function to get_chunk_element_offset and update all call
sites that expect the current name to use the new name, preserving behavior (do
not change the multiplication by size_of::<T>() at call sites).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@lib/segment/src/vector_storage/chunked_vectors.rs`:
- Around line 171-176: The doc comment for get_chunk_offset is misleading: it
says "Returns the byte offset" but the function returns an element offset
(chunk_vector_idx * self.config.dim) and callers multiply by size_of::<T>() to
get bytes; update the comment to say "Returns the element offset (number of T
elements) within the chunk" or rename the function to get_chunk_element_offset
and update all call sites that expect the current name to use the new name,
preserving behavior (do not change the multiplication by size_of::<T>() at call
sites).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f0a0d393-145e-4763-8740-9cfc71835e2e

📥 Commits

Reviewing files that changed from the base of the PR and between ed13a5b and 15f5bfb.

📒 Files selected for processing (11)
  • lib/common/common/src/universal_io/io_uring.rs
  • lib/common/common/src/universal_io/mmap.rs
  • lib/common/common/src/universal_io/mod.rs
  • lib/common/common/src/universal_io/read.rs
  • lib/common/common/src/universal_io/write.rs
  • lib/gridstore/src/pages.rs
  • lib/gridstore/src/tracker.rs
  • lib/segment/src/common/stored_bitslice.rs
  • lib/segment/src/index/field_index/stored_point_to_values.rs
  • lib/segment/src/vector_storage/chunked_vectors.rs
  • lib/segment/src/vector_storage/dense/immutable_dense_vectors.rs

@generall
generall merged commit 454f11b into dev Mar 20, 2026
15 checks passed
@generall
generall deleted the fix-io-uring-reads-part-1 branch March 20, 2026 20:03
generall added a commit that referenced this pull request Mar 26, 2026
* [AI] use byte offset instead of element range

* [AI] change ElementOffset -> ByteOffset
@coderabbitai coderabbitai Bot mentioned this pull request Mar 29, 2026
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
* [AI] use byte offset instead of element range

* [AI] change ElementOffset -> ByteOffset
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