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(core/raw): Migrate oio::Read to async in trait #4336

Merged
merged 38 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7dd9358
Another failure
Xuanwo Mar 7, 2024
c53adda
Save work
Xuanwo Mar 7, 2024
e55e6d9
Save file read
Xuanwo Mar 7, 2024
77e1448
Save polish
Xuanwo Mar 7, 2024
509411e
Save
Xuanwo Mar 7, 2024
dab21d3
save
Xuanwo Mar 7, 2024
3347510
Remove next
Xuanwo Mar 7, 2024
98f5dfd
able to build
Xuanwo Mar 8, 2024
2ee2c28
Fix retry
Xuanwo Mar 8, 2024
add6f39
save work
Xuanwo Mar 11, 2024
7258e7f
Impl read to end
Xuanwo Mar 11, 2024
bc87faf
Implement futures & tokio reader
Xuanwo Mar 11, 2024
42aacc3
Fix file read
Xuanwo Mar 11, 2024
a705ce4
add warning
Xuanwo Mar 11, 2024
921d4cd
fix ftp
Xuanwo Mar 11, 2024
5bd8f35
Fix dtrace
Xuanwo Mar 11, 2024
6c0621e
Fix retry
Xuanwo Mar 11, 2024
a513d27
all check passed
Xuanwo Mar 11, 2024
8484245
Make clippy happy
Xuanwo Mar 11, 2024
108fcbe
clippy passed
Xuanwo Mar 11, 2024
718edef
Don't impl io traits on dyn reader
Xuanwo Mar 11, 2024
8b6cc0c
Polish naming
Xuanwo Mar 11, 2024
9231409
Rename
Xuanwo Mar 11, 2024
5b8c8d8
Fix naming
Xuanwo Mar 11, 2024
0ced6a0
Remove typo
Xuanwo Mar 11, 2024
0cedba6
Bump msrv
Xuanwo Mar 11, 2024
c8457cb
Fix object store
Xuanwo Mar 11, 2024
9c6b8d5
Fix recursive
Xuanwo Mar 11, 2024
109d102
Fix unit tests
Xuanwo Mar 11, 2024
f2a27aa
Fix fs test
Xuanwo Mar 11, 2024
ebeb269
Fix consume not updated
Xuanwo Mar 11, 2024
8bf798c
Don't expose oio trait out
Xuanwo Mar 11, 2024
11d20d2
Address nodejs support
Xuanwo Mar 11, 2024
30a617b
Fix fs
Xuanwo Mar 11, 2024
4fb29a0
Fix test
Xuanwo Mar 11, 2024
e26952b
Fix diff
Xuanwo Mar 11, 2024
1570a57
Fix wasm support
Xuanwo Mar 11, 2024
3f8ca68
Fix tests
Xuanwo Mar 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ jobs:
check_msrv:
runs-on: ubuntu-latest
env:
# OpenDAL's MSRV is 1.67.
OPENDAL_MSRV: "1.67"
# OpenDAL's MSRV is 1.75.
OPENDAL_MSRV: "1.75"
steps:
- uses: actions/checkout@v4
- name: Setup msrv of rust
Expand Down
2 changes: 1 addition & 1 deletion bin/oay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"
version = "0.41.1"

[features]
Expand Down
2 changes: 1 addition & 1 deletion bin/ofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"

[dependencies]
anyhow = "1"
Expand Down
2 changes: 1 addition & 1 deletion bin/oli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"
version = "0.41.1"

[features]
Expand Down
2 changes: 1 addition & 1 deletion bindings/c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"
version = "0.44.3"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion bindings/cpp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"
version = "0.44.3"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion bindings/dotnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"

[lib]
crate-type = ["cdylib"]
Expand Down
2 changes: 1 addition & 1 deletion bindings/haskell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"
version = "0.44.3"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion bindings/java/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"
version = "0.45.1"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion bindings/lua/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"

[features]
default = ["mlua/lua52"]
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"
version = "0.45.1"

[features]
Expand Down
2 changes: 2 additions & 0 deletions bindings/nodejs/generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ export class Reader {
* > &mut self in async napi methods should be marked as unsafe
*
* Read bytes from this reader into given buffer.
*
* TODO: change api into stream based.
*/
read(buf: Buffer): Promise<bigint>
}
Expand Down
8 changes: 6 additions & 2 deletions bindings/nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use std::time::Duration;
use futures::TryStreamExt;
use napi::bindgen_prelude::*;
use opendal::raw::oio::BlockingRead;
use opendal::raw::oio::ReadExt;

#[napi]
pub struct Operator(opendal::Operator);
Expand Down Expand Up @@ -665,9 +664,14 @@ impl Reader {
/// > &mut self in async napi methods should be marked as unsafe
///
/// Read bytes from this reader into given buffer.
///
/// TODO: change api into stream based.
#[napi]
pub async unsafe fn read(&mut self, mut buf: Buffer) -> Result<usize> {
self.0.read(buf.as_mut()).await.map_err(format_napi_error)
let buf = buf.as_mut();
let bs = self.0.read(buf.len()).await.map_err(format_napi_error)?;
buf[..bs.len()].copy_from_slice(&bs);
Ok(bs.len())
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/ocaml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"

[lib]
crate-type = ["staticlib", "cdylib"]
Expand Down
2 changes: 1 addition & 1 deletion bindings/php/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"

[lib]
crate-type = ["cdylib"]
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"
version = "0.45.1"

[features]
Expand Down
8 changes: 3 additions & 5 deletions bindings/python/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use std::io::Write;
use std::ops::DerefMut;
use std::sync::Arc;

use futures::AsyncReadExt;
use futures::AsyncSeekExt;
use futures::AsyncWriteExt;
use pyo3::exceptions::PyIOError;
Expand Down Expand Up @@ -243,12 +242,11 @@ impl AsyncFile {

let buffer = match size {
Some(size) => {
let mut buffer = vec![0; size];
reader
.read_exact(&mut buffer)
let buffer = reader
.read_exact(size)
.await
.map_err(|err| PyIOError::new_err(err.to_string()))?;
buffer
buffer.to_vec()
}
None => {
let mut buffer = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion bindings/ruby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"

[lib]
crate-type = ["cdylib"]
Expand Down
6 changes: 3 additions & 3 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.67"
rust-version = "1.75"
version = "0.45.1"

[package.metadata.docs.rs]
Expand Down Expand Up @@ -235,7 +235,7 @@ async-tls = { version = "0.13.0", optional = true }
# Required dependencies
anyhow = { version = "1.0.30", features = ["std"] }
async-trait = "0.1.68"
backon = "0.4.1"
backon = "0.4.3"
base64 = "0.21"
bytes = "1.4"
chrono = { version = "0.4.28", default-features = false, features = [
Expand All @@ -256,7 +256,7 @@ reqwest = { version = "0.11.18", features = [
], default-features = false }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1.27", features = ["sync"] }
tokio = { version = "1.27", features = ["sync", "io-util"] }
uuid = { version = "1", features = ["serde", "v4"] }

# Test only dependencies
Expand Down
10 changes: 4 additions & 6 deletions core/benches/ops/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use criterion::Criterion;
use futures::io;
use futures::AsyncReadExt;
use opendal::raw::tests::init_test_service;
use opendal::raw::tests::TEST_RUNTIME;
use opendal::Operator;
Expand Down Expand Up @@ -112,25 +111,24 @@ fn bench_read_parallel(c: &mut Criterion, name: &str, op: Operator) {
let content = gen_bytes(&mut rng, (size.bytes() * 2) as usize);
let path = uuid::Uuid::new_v4().to_string();
let offset = (size.bytes() / 2) as u64;
let buf = vec![0; size.bytes() as usize];
let buf_size = size.bytes() as usize;
let temp_data = TempData::generate(op.clone(), &path, content.clone());

for parallel in [1, 2, 4, 8, 16] {
group.throughput(criterion::Throughput::Bytes(parallel * size.bytes() as u64));
group.bench_with_input(
format!("{}x{}", parallel, size.to_string()),
&(op.clone(), &path, buf.clone()),
|b, (op, path, buf)| {
&(op.clone(), &path, buf_size),
|b, (op, path, buf_size)| {
b.to_async(&*TEST_RUNTIME).iter(|| async {
let futures = (0..parallel)
.map(|_| async {
let mut buf = buf.clone();
let mut r = op
.reader_with(path)
.range(offset..=offset + size.bytes() as u64)
.await
.unwrap();
r.read_exact(&mut buf).await.unwrap();
r.read_exact(*buf_size).await.unwrap();

let mut d = 0;
// mock same little cpu work
Expand Down
2 changes: 1 addition & 1 deletion core/benches/vs_fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ edition = "2021"
license = "Apache-2.0"
name = "opendal-benchmark-vs-fs"
publish = false
rust-version = "1.67"
rust-version = "1.75"
version = "0.0.0"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion core/benches/vs_s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ edition = "2021"
license = "Apache-2.0"
name = "opendal-benchmark-vs-s3"
publish = false
rust-version = "1.67"
rust-version = "1.75"
version = "0.0.0"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion core/edge/file_write_on_full_disk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ edition = "2021"
license = "Apache-2.0"
name = "edge_test_file_write_on_full_disk"
publish = false
rust-version = "1.67"
rust-version = "1.75"
version = "0.0.0"

[dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ edition = "2021"
license = "Apache-2.0"
name = "edge_test_aws_s3_assume_role_with_web_identity"
publish = false
rust-version = "1.67"
rust-version = "1.75"
version = "0.0.0"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion core/edge/s3_read_on_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ edition = "2021"
license = "Apache-2.0"
name = "edge_test_s3_read_on_wasm"
publish = false
rust-version = "1.67"
rust-version = "1.75"
version = "0.0.0"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion core/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ edition = "2021"
license = "Apache-2.0"
name = "opendal-fuzz"
publish = false
rust-version = "1.67"
rust-version = "1.75"
version = "0.0.0"

[package.metadata]
Expand Down
10 changes: 4 additions & 6 deletions core/fuzz/fuzz_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,25 @@ impl Arbitrary<'_> for FuzzInput {
let mut actions = vec![];

for _ in 0..count {
let action = match u.int_in_range(0..=4)? {
let action = match u.int_in_range(0..=3)? {
// Read
0 => {
let size = u.int_in_range(0..=total_size * 2)?;
ReadAction::Read(size)
}
// Next
1 => ReadAction::Next,
// Seek Start
2 => {
1 => {
// NOTE: seek out of the end of file is valid.
let offset = u.int_in_range(0..=total_size * 2)?;
ReadAction::Seek(SeekFrom::Start(offset as u64))
}
// Seek Current
3 => {
2 => {
let offset = u.int_in_range(-(total_size as i64)..=(total_size as i64))?;
ReadAction::Seek(SeekFrom::Current(offset))
}
// Seek End
4 => {
3 => {
let offset = u.int_in_range(-(total_size as i64)..=(total_size as i64))?;
ReadAction::Seek(SeekFrom::End(offset))
}
Expand Down
Loading
Loading