You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "tisonkun (via GitHub)" <gi...@apache.org> on 2024/06/06 00:47:09 UTC
[PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
tisonkun opened a new pull request, #4697:
URL: https://github.com/apache/opendal/pull/4697
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #4697:
URL: https://github.com/apache/opendal/pull/4697#discussion_r1628602110
##########
core/src/raw/http_util/bytes_range.rs:
##########
@@ -188,13 +181,14 @@ where
Bound::Excluded(n) => n + 1,
Bound::Unbounded => 0,
};
+
let size = match range.end_bound().cloned() {
- Bound::Included(n) => Some(n + 1 - offset),
- Bound::Excluded(n) => Some(n - offset),
- Bound::Unbounded => None,
+ Bound::Included(n) => n - offset + 1,
+ Bound::Excluded(n) => n - offset,
+ Bound::Unbounded => panic!("end of range must be specified"),
Review Comment:
@Xuanwo I'm thinking if we should implement `TryFrom` instead here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4697:
URL: https://github.com/apache/opendal/pull/4697#discussion_r1628596338
##########
core/src/docs/upgrade.md:
##########
@@ -1,3 +1,24 @@
+# Upgrade to v0.47
+
+## Public API
Review Comment:
`BytesRange` is not part of public API.
##########
core/src/raw/http_util/bytes_range.rs:
##########
@@ -77,15 +77,15 @@ impl BytesRange {
///
/// Panic if input `n` is larger than the size of the range.
pub fn advance(&mut self, n: u64) {
- self.0 += n;
- self.1 = self.1.map(|size| size - n);
+ self.offset += n;
+ self.size -= n;
}
/// Check if this range is full of this content.
///
/// If this range is full, we don't need to specify it in http request.
pub fn is_full(&self) -> bool {
- self.0 == 0 && self.1.is_none()
+ self.offset == 0 && self.size == 0
Review Comment:
This is wrong. And we should remove `is_full` API.
##########
core/src/raw/http_util/bytes_range.rs:
##########
@@ -96,32 +96,23 @@ impl BytesRange {
/// Convert bytes range into rust range.
pub fn to_range(&self) -> impl RangeBounds<u64> {
(
- Bound::Included(self.0),
- match self.1 {
- Some(size) => Bound::Excluded(self.0 + size),
- None => Bound::Unbounded,
- },
+ Bound::Included(self.offset),
Review Comment:
Maybe we can return `Range<u64>` directly now
##########
core/src/raw/http_util/bytes_range.rs:
##########
@@ -57,18 +57,18 @@ impl BytesRange {
///
/// - offset=None => `bytes=-<size>`, read `<size>` bytes from end.
/// - offset=Some(0) => `bytes=0-<size>`, read `<size>` bytes from start.
Review Comment:
We can remove those comments.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4697:
URL: https://github.com/apache/opendal/pull/4697#discussion_r1628602153
##########
core/src/docs/upgrade.md:
##########
@@ -1,3 +1,24 @@
+# Upgrade to v0.47
+
+## Public API
Review Comment:
Please note that opendal has clear statement about it's public API and raw API. All types, structs, trait in `opendal::raw` are treated as `Raw API` that users should not rely on if possible. Please list the changes to `BytesRange` in `Raw API` instead,
https://opendal.apache.org/docs/rust/opendal/raw/index.html
##########
core/src/docs/upgrade.md:
##########
@@ -1,3 +1,24 @@
+# Upgrade to v0.47
+
+## Public API
Review Comment:
Please note that opendal has clear statement about it's public API and raw API. All types, structs, trait in `opendal::raw` are treated as `Raw API` that users should not rely on if possible. Please list the changes to `BytesRange` in `Raw API` instead.
https://opendal.apache.org/docs/rust/opendal/raw/index.html
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4697:
URL: https://github.com/apache/opendal/pull/4697#discussion_r1628602153
##########
core/src/docs/upgrade.md:
##########
@@ -1,3 +1,24 @@
+# Upgrade to v0.47
+
+## Public API
Review Comment:
Please note that opendal has clear statement about it's public API and raw API. All types, structs, trait in `opendal::raw` are treated as `Raw API` that users should not rely on.
https://opendal.apache.org/docs/rust/opendal/raw/index.html
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4697:
URL: https://github.com/apache/opendal/pull/4697#discussion_r1628602153
##########
core/src/docs/upgrade.md:
##########
@@ -1,3 +1,24 @@
+# Upgrade to v0.47
+
+## Public API
Review Comment:
Please note that opendal has clear statement about it's public API and raw API. All types, structs, trait in `opendal::raw` are treated as `Raw API` that users should not rely on.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #4697:
URL: https://github.com/apache/opendal/pull/4697#discussion_r1628599898
##########
core/src/raw/http_util/bytes_range.rs:
##########
@@ -77,15 +77,15 @@ impl BytesRange {
///
/// Panic if input `n` is larger than the size of the range.
pub fn advance(&mut self, n: u64) {
- self.0 += n;
- self.1 = self.1.map(|size| size - n);
+ self.offset += n;
+ self.size -= n;
}
/// Check if this range is full of this content.
///
/// If this range is full, we don't need to specify it in http request.
pub fn is_full(&self) -> bool {
- self.0 == 0 && self.1.is_none()
+ self.offset == 0 && self.size == 0
Review Comment:
Yes. I first change it to `false` and will further refactor it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun closed pull request #4697: refactor: handle range bounds consistently and BytesRange always has a size
URL: https://github.com/apache/opendal/pull/4697
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #4697:
URL: https://github.com/apache/opendal/pull/4697#discussion_r1628596423
##########
core/src/types/buffer.rs:
##########
@@ -243,15 +243,15 @@ impl Buffer {
pub fn slice(&self, range: impl RangeBounds<usize>) -> Self {
let len = self.len();
- let begin = match range.start_bound() {
- Bound::Included(&n) => n,
- Bound::Excluded(&n) => n.checked_add(1).expect("out of range"),
+ let begin = match range.start_bound().cloned() {
+ Bound::Included(n) => n,
+ Bound::Excluded(n) => n + 1,
Review Comment:
The default manner is already panic: `attempt to add with overflow`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4697:
URL: https://github.com/apache/opendal/pull/4697#discussion_r1628602153
##########
core/src/docs/upgrade.md:
##########
@@ -1,3 +1,24 @@
+# Upgrade to v0.47
+
+## Public API
Review Comment:
Please note that opendal has clear statement about it's public API and raw API. All types, structs, trait in `opendal::raw` are treated as `Raw API` that users should not rely on if possible.
https://opendal.apache.org/docs/rust/opendal/raw/index.html
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #4697:
URL: https://github.com/apache/opendal/pull/4697#discussion_r1628612543
##########
core/src/docs/upgrade.md:
##########
@@ -1,3 +1,24 @@
+# Upgrade to v0.47
+
+## Public API
Review Comment:
OK.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #4697:
URL: https://github.com/apache/opendal/pull/4697#issuecomment-2151246294
A huge difference is that OpRead initiate a default range, which is previously `0..` but now `0..0`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #4697:
URL: https://github.com/apache/opendal/pull/4697#issuecomment-2204635950
Drop for now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4697:
URL: https://github.com/apache/opendal/pull/4697#discussion_r1628608112
##########
core/src/raw/http_util/bytes_range.rs:
##########
@@ -188,13 +181,14 @@ where
Bound::Excluded(n) => n + 1,
Bound::Unbounded => 0,
};
+
let size = match range.end_bound().cloned() {
- Bound::Included(n) => Some(n + 1 - offset),
- Bound::Excluded(n) => Some(n - offset),
- Bound::Unbounded => None,
+ Bound::Included(n) => n - offset + 1,
+ Bound::Excluded(n) => n - offset,
+ Bound::Unbounded => panic!("end of range must be specified"),
Review Comment:
I found that we have a place rely on this:
```rust
/// Set the range header for this operation.
pub fn range(self, range: impl RangeBounds<u64>) -> Self {
self.map(|(args, op_reader)| (args.with_range(range.into()), op_reader))
}
```
I feel like We should remove the `impl From` for BytesRange, and change the `FutureRead::range`'s implemantion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] refactor: handle range bounds consistently and BytesRange always has a size [opendal]
Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #4697:
URL: https://github.com/apache/opendal/pull/4697#discussion_r1628600671
##########
core/src/docs/upgrade.md:
##########
@@ -1,3 +1,24 @@
+# Upgrade to v0.47
+
+## Public API
Review Comment:
No. We expose it and I noticed that GreptimeDB uses this interface: https://github.com/GreptimeTeam/greptimedb/blob/2ade511f26066b2aa0ee138146965977210b40f2/src/object-store/src/layers/lru_cache/read_cache.rs#L248
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org