-
Notifications
You must be signed in to change notification settings - Fork 150
feat: check VortexReadAt::read_at results in the I/O driver #7783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+96
−23
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b0c6ad9
feat: check VortexReadAt::read_at results in the I/O driver
danking 8223fea
address comments
danking b0dde19
more comment addressing
danking 82af0e4
more comment addressing
danking b32030b
got the check backwards
danking f8039b1
pick nits
danking 160c6bc
fix tests
danking a7c4640
fix
danking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,10 @@ use vortex_buffer::Alignment; | |
| use vortex_error::VortexError; | ||
| use vortex_error::VortexExpect; | ||
| use vortex_error::VortexResult; | ||
| use vortex_error::vortex_ensure; | ||
|
|
||
| /// An I/O request, either a single read or a coalesced set of reads. | ||
| #[derive(Debug)] | ||
| pub(crate) struct IoRequest(IoRequestInner); | ||
|
|
||
| impl IoRequest { | ||
|
|
@@ -37,8 +39,10 @@ impl IoRequest { | |
| pub fn len(&self) -> usize { | ||
| match &self.0 { | ||
| IoRequestInner::Single(r) => r.length, | ||
| IoRequestInner::Coalesced(r) => usize::try_from(r.range.end - r.range.start) | ||
| .vortex_expect("range too big for usize"), | ||
| IoRequestInner::Coalesced(r) => { | ||
| usize::try_from(r.range.end.saturating_sub(r.range.start)) | ||
| .vortex_expect("range too big for usize") | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -78,6 +82,7 @@ impl IoRequest { | |
| } | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| pub(crate) enum IoRequestInner { | ||
| Single(ReadRequest), | ||
| Coalesced(CoalescedRequest), | ||
|
|
@@ -115,9 +120,9 @@ impl ReadRequest { | |
|
|
||
| /// A set of I/O requests that have been coalesced into a single larger request. | ||
| pub(crate) struct CoalescedRequest { | ||
| pub(crate) range: Range<u64>, | ||
| pub(crate) alignment: Alignment, // Global max segment alignment used for the coalesced range. | ||
| pub(crate) requests: Vec<ReadRequest>, // TODO(ngates): we could have enum of Single/Many to avoid Vec. | ||
| range: Range<u64>, | ||
| alignment: Alignment, // Global max segment alignment used for the coalesced range. | ||
| requests: Vec<ReadRequest>, // TODO(ngates): we could have enum of Single/Many to avoid Vec. | ||
| } | ||
|
|
||
| impl Debug for CoalescedRequest { | ||
|
|
@@ -132,6 +137,58 @@ impl Debug for CoalescedRequest { | |
| } | ||
|
|
||
| impl CoalescedRequest { | ||
| pub fn try_new( | ||
| range: Range<u64>, | ||
| alignment: Alignment, | ||
| requests: Vec<ReadRequest>, | ||
| ) -> VortexResult<Self> { | ||
| vortex_ensure!( | ||
| range.start <= range.end, | ||
| "CoalescedRequest: range.start, {}, must be less than or equal to range.end, {}.", | ||
| range.start, | ||
| range.end, | ||
| ); | ||
| for req in requests.iter() { | ||
| vortex_ensure!( | ||
| req.offset >= range.start, | ||
| "CoalescedRequest: sub-request for length {} at file offset {} precedes coalesced range: {}..{}. {:?}", | ||
| req.length, | ||
| req.offset, | ||
| range.start, | ||
| range.end, | ||
| req, | ||
| ); | ||
| vortex_ensure!( | ||
| req.offset.saturating_add(req.length as u64) <= range.end, | ||
| "CoalescedRequest: sub-request for length {} at file offset {} exceeds the coalesced range: {}..{}. {:?}", | ||
| req.length, | ||
| req.offset, | ||
| range.start, | ||
| range.end, | ||
| req, | ||
| ); | ||
| } | ||
| Ok(Self { | ||
| range, | ||
| alignment, | ||
| requests, | ||
| }) | ||
| } | ||
|
|
||
| #[allow(unused)] | ||
| pub fn range(&self) -> &Range<u64> { | ||
| &self.range | ||
| } | ||
|
|
||
| #[allow(unused)] | ||
| pub fn alignment(&self) -> Alignment { | ||
| self.alignment | ||
| } | ||
|
|
||
| pub fn requests(&self) -> &[ReadRequest] { | ||
| &self.requests | ||
| } | ||
|
Comment on lines
+188
to
+190
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Java?? ☕ ⚰️
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's the only way to have read-only public fields so I can enforce my invariants. |
||
|
|
||
| pub fn resolve(self, result: VortexResult<BufferHandle>) { | ||
| match result { | ||
| Ok(buffer) => { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would also be ok with this panicking since passing a request that is outside of the coalescing window is an implementer error. but this is fine