-
Notifications
You must be signed in to change notification settings - Fork 590
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
refactor: use usize range instead of BlockLocation to read obj #12225
Conversation
Signed-off-by: MrCroxx <[email protected]>
Signed-off-by: MrCroxx <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #12225 +/- ##
==========================================
- Coverage 69.67% 69.66% -0.01%
==========================================
Files 1410 1411 +1
Lines 236255 236127 -128
==========================================
- Hits 164599 164505 -94
+ Misses 71656 71622 -34
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 6 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
src/object_store/src/object/mem.rs
Outdated
async fn get_object( | ||
&self, | ||
path: &str, | ||
range: impl RangeBounds<usize> + Clone + Send + Sync + 'static, |
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.
src/storage/src/store.rs StaticSendSync
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.
range
here requires a lot more trait bounds, IMO, expend them here is also okay.
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.
Rest LGTM, thanks
// version, magic | ||
2 * std::mem::size_of::<u32>() + | ||
// footer, checksum | ||
2 * std::mem::size_of::<u64>() |
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.
typo
src/object_store/src/object/s3.rs
Outdated
} | ||
|
||
let start = match range.start_bound() { |
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.
How about constructing start and end in separate functions? It's repeated several times in pr
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.
Agreed! I'm doing it.
src/object_store/src/object/mem.rs
Outdated
let start = match range.start_bound() { | ||
std::ops::Bound::Included(v) => *v, | ||
std::ops::Bound::Excluded(v) => *v - 1, | ||
std::ops::Bound::Unbounded => 0, | ||
}; | ||
let end = match range.end_bound() { | ||
std::ops::Bound::Included(v) => *v + 1, | ||
std::ops::Bound::Excluded(v) => *v, | ||
std::ops::Bound::Unbounded => obj.len(), | ||
}; | ||
|
||
if end > obj.len() { | ||
return Err(Error::other("bad block offset and size").into()); | ||
} | ||
|
||
fn find_block(obj: &Bytes, block: BlockLocation) -> ObjectResult<Bytes> { | ||
if block.offset + block.size > obj.len() { | ||
Err(Error::other("bad block offset and size").into()) | ||
} else { | ||
Ok(obj.slice(block.offset..(block.offset + block.size))) | ||
Ok(obj.slice(start..end)) |
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.
Why not passng the range
directly to obj.slice
?
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.
Code here needs to check overflow.
src/object_store/src/object/s3.rs
Outdated
|
||
let start = match range.start_bound() { | ||
std::ops::Bound::Included(v) => v.to_string(), | ||
std::ops::Bound::Excluded(v) => (v - 1).to_string(), |
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.
Shouldn't this be v+1
?
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.
We may need some tests to test different combinations of left close/open/unbounded and right close/open/unbounded. If it is hard to mock aws client, we can mannually test it as well.
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.
Yep! I've found it and fixed it. (I thought no one find it and I can fix it quietly. 🤣)
We may need some tests to test different combinations of left close/open/unbounded and right close/open/unbounded. If it is hard to mock aws client, we can mannually test it as well.
After the latest commits, combinations of bounds are implemented in RangeBoundsExt
.
Signed-off-by: MrCroxx <[email protected]>
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.
LGTM
Signed-off-by: MrCroxx <[email protected]>
src/common/src/range.rs
Outdated
+ 'static | ||
+ ZeroOne; | ||
|
||
pub trait RangeBoundsExt<T> |
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.
RangeBoundsExt<T>: RangeBounds<T>
?
src/object_store/src/object/mem.rs
Outdated
async fn read( | ||
&self, | ||
path: &str, | ||
range: impl RangeBounds<usize> + Clone + Send + Sync + std::fmt::Debug + 'static, |
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.
May define pub trait ObjectStoreRange = RangeBounds<usize> + Clone + Send + Sync + std::fmt::Debug + 'static
to avoid defining the long trait for multiple times.
|
||
mod private { | ||
|
||
pub trait ZeroOne { |
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.
Found a crate that implements similar functionality.
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.
Yep, there is One
and Zero
, but I need both of them. 🤣 I preferred not to introduce two more dependencies here.
Signed-off-by: MrCroxx <[email protected]>
Signed-off-by: MrCroxx <[email protected]>
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
Use
impl RangeBounds<usize> + Clone + Sync + Send + 'static
to replaceBlockLocation
.Checklist
./risedev check
(or alias,./risedev c
)Documentation
Release note
If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.