Skip to content
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

Merged
merged 9 commits into from
Sep 12, 2023

Conversation

MrCroxx
Copy link
Contributor

@MrCroxx MrCroxx commented Sep 12, 2023

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 replace BlockLocation.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

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.

@MrCroxx MrCroxx self-assigned this Sep 12, 2023
@codecov
Copy link

codecov bot commented Sep 12, 2023

Codecov Report

Merging #12225 (974f75a) into main (62901e1) will decrease coverage by 0.01%.
The diff coverage is 61.29%.

@@            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     
Flag Coverage Δ
rust 69.66% <61.29%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/ctl/src/cmd_impl/hummock/sst_dump.rs 0.00% <0.00%> (ø)
src/object_store/src/object/s3.rs 3.15% <0.00%> (+0.07%) ⬆️
src/storage/src/hummock/sstable_store.rs 68.59% <42.85%> (+0.44%) ⬆️
src/common/src/range.rs 62.16% <62.16%> (ø)
src/object_store/src/object/mem.rs 92.06% <95.00%> (+3.52%) ⬆️
src/meta/src/hummock/manager/checkpoint.rs 75.18% <100.00%> (ø)
src/meta/src/hummock/manager/mod.rs 60.84% <100.00%> (-0.20%) ⬇️
src/object_store/src/object/mod.rs 59.02% <100.00%> (+4.70%) ⬆️
.../src/object/opendal_engine/opendal_object_store.rs 73.51% <100.00%> (-5.24%) ⬇️
src/storage/backup/src/storage.rs 54.95% <100.00%> (ø)
... and 1 more

... and 6 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

async fn get_object(
&self,
path: &str,
range: impl RangeBounds<usize> + Clone + Send + Sync + 'static,
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@Li0k Li0k left a 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>()
Copy link
Contributor

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/mem.rs Outdated Show resolved Hide resolved
src/object_store/src/object/s3.rs Outdated Show resolved Hide resolved
}

let start = match range.start_bound() {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Comment on lines 248 to 263
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))
Copy link
Collaborator

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?

Copy link
Contributor Author

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.


let start = match range.start_bound() {
std::ops::Bound::Included(v) => v.to_string(),
std::ops::Bound::Excluded(v) => (v - 1).to_string(),
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

@hzxa21 hzxa21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MrCroxx MrCroxx enabled auto-merge September 12, 2023 09:47
+ 'static
+ ZeroOne;

pub trait RangeBoundsExt<T>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RangeBoundsExt<T>: RangeBounds<T>?

async fn read(
&self,
path: &str,
range: impl RangeBounds<usize> + Clone + Send + Sync + std::fmt::Debug + 'static,
Copy link
Contributor

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.

@MrCroxx MrCroxx disabled auto-merge September 12, 2023 09:48

mod private {

pub trait ZeroOne {
Copy link
Contributor

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.

https://docs.rs/num/latest/num/traits/trait.Zero.html

Copy link
Contributor Author

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]>
@MrCroxx MrCroxx enabled auto-merge September 12, 2023 10:02
@MrCroxx MrCroxx added this pull request to the merge queue Sep 12, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 12, 2023
@MrCroxx MrCroxx enabled auto-merge September 12, 2023 11:13
@MrCroxx MrCroxx added this pull request to the merge queue Sep 12, 2023
Merged via the queue into main with commit 1650a3b Sep 12, 2023
6 of 7 checks passed
@MrCroxx MrCroxx deleted the xx/refactor-obj-range branch September 12, 2023 11:47
Li0k pushed a commit that referenced this pull request Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants