Skip to content

Commit 1a17091

Browse files
authored
Merge branch 'main' into raft
2 parents a5ee81c + b182e7a commit 1a17091

File tree

74 files changed

+2247
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2247
-347
lines changed

Cargo.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"common/clickhouse-srv",
99
"common/containers",
1010
"common/dal",
11+
"common/dal2",
1112
"common/datablocks",
1213
"common/datavalues",
1314
"common/exception",

common/dal2/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "common-dal2"
3+
version = "0.1.0"
4+
authors = ["Databend Authors <[email protected]>"]
5+
license = "Apache-2.0"
6+
publish = false
7+
edition = "2021"
8+
9+
[lib]
10+
doctest = false
11+
test = false
12+
13+
[dependencies]
14+
common-exception = { path = "../exception" }
15+
16+
async-compat = "0.2.1"
17+
async-trait = "0.1.52"
18+
bytes = "1.1.0"
19+
futures = "0.3.19"
20+
reqwest = "0.11.7"
21+
rusoto_core = "0.47.0"
22+
rusoto_s3 = "0.47.0"
23+
rusoto_credential = "0.47.0"
24+
tokio = {version="1.15.0",features=["fs"]}

common/dal2/src/dal.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::marker::PhantomData;
16+
use std::sync::Arc;
17+
18+
use common_exception::Result;
19+
20+
use crate::ops::Delete;
21+
use crate::ops::Object;
22+
use crate::ops::Read;
23+
use crate::ops::ReadBuilder;
24+
use crate::ops::Stat;
25+
use crate::ops::Write;
26+
use crate::ops::WriteBuilder;
27+
28+
pub struct DataAccessor<'d, S> {
29+
s: Arc<S>,
30+
phantom: PhantomData<&'d ()>,
31+
}
32+
33+
impl<'d, S> DataAccessor<'d, S> {
34+
pub fn new(s: S) -> DataAccessor<'d, S> {
35+
DataAccessor {
36+
s: Arc::new(s),
37+
phantom: PhantomData::default(),
38+
}
39+
}
40+
}
41+
42+
impl<'d, S> DataAccessor<'d, S>
43+
where S: Read<S>
44+
{
45+
pub fn read(&self, path: &'d str) -> ReadBuilder<S> {
46+
ReadBuilder::new(self.s.clone(), path)
47+
}
48+
}
49+
50+
impl<'d, S> DataAccessor<'d, S>
51+
where S: Write<S>
52+
{
53+
pub fn write(&self, path: &'d str, size: u64) -> WriteBuilder<S> {
54+
WriteBuilder::new(self.s.clone(), path, size)
55+
}
56+
}
57+
58+
impl<'d, S> DataAccessor<'d, S>
59+
where S: Stat<S>
60+
{
61+
pub async fn stat(&self, path: &'d str) -> Result<Object> {
62+
self.s.stat(path).await
63+
}
64+
}
65+
66+
impl<'d, S> DataAccessor<'d, S>
67+
where S: Delete<S>
68+
{
69+
pub async fn delete(&self, path: &'d str) -> Result<()> {
70+
self.s.delete(path).await
71+
}
72+
}

common/dal2/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
mod dal;
16+
mod ops;
17+
18+
pub mod services;
19+
pub use dal::DataAccessor;

common/dal2/src/ops/delete.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use async_trait::async_trait;
16+
use common_exception::Result;
17+
18+
#[async_trait]
19+
pub trait Delete<S: Send + Sync>: Send + Sync {
20+
async fn delete(&self, path: &str) -> Result<()> {
21+
let _ = path;
22+
unimplemented!()
23+
}
24+
}

common/dal2/src/ops/io.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::pin::Pin;
16+
use std::task::Poll;
17+
18+
pub type Reader = Box<dyn futures::io::AsyncRead + Unpin + Send>;
19+
20+
pub struct CallbackReader {
21+
inner: Reader,
22+
f: Box<dyn Fn(usize)>,
23+
}
24+
25+
impl futures::AsyncRead for CallbackReader {
26+
fn poll_read(
27+
mut self: Pin<&mut Self>,
28+
cx: &mut std::task::Context<'_>,
29+
buf: &mut [u8],
30+
) -> Poll<std::io::Result<usize>> {
31+
let r = Pin::new(&mut self.inner).poll_read(cx, buf);
32+
33+
if let Poll::Ready(Ok(len)) = r {
34+
(self.f)(len);
35+
};
36+
37+
r
38+
}
39+
}

common/dal2/src/ops/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
mod delete;
16+
mod io;
17+
mod object;
18+
mod read;
19+
mod stat;
20+
mod write;
21+
22+
pub use delete::Delete;
23+
pub use io::Reader;
24+
pub use object::Object;
25+
pub use read::Read;
26+
pub use read::ReadBuilder;
27+
pub use stat::Stat;
28+
pub use write::Write;
29+
pub use write::WriteBuilder;

common/dal2/src/ops/object.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
pub struct Object {
16+
pub path: String,
17+
pub size: u64,
18+
}

common/dal2/src/ops/read.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::sync::Arc;
16+
17+
use async_trait::async_trait;
18+
use common_exception::Result;
19+
20+
use super::io::Reader;
21+
22+
#[async_trait]
23+
pub trait Read<S: Send + Sync>: Send + Sync {
24+
async fn read(&self, args: &ReadBuilder<S>) -> Result<Reader> {
25+
let _ = args;
26+
unimplemented!()
27+
}
28+
}
29+
30+
pub struct ReadBuilder<'p, S> {
31+
s: Arc<S>,
32+
33+
pub path: &'p str,
34+
pub offset: Option<u64>,
35+
pub size: Option<u64>,
36+
}
37+
38+
impl<'p, S> ReadBuilder<'p, S> {
39+
pub fn new(s: Arc<S>, path: &'p str) -> Self {
40+
Self {
41+
s,
42+
path,
43+
offset: None,
44+
size: None,
45+
}
46+
}
47+
48+
pub fn offset(&mut self, offset: u64) -> &mut Self {
49+
self.offset = Some(offset);
50+
51+
self
52+
}
53+
54+
pub fn size(&mut self, size: u64) -> &mut Self {
55+
self.size = Some(size);
56+
57+
self
58+
}
59+
}
60+
61+
impl<'p, S: Read<S>> ReadBuilder<'p, S> {
62+
pub async fn run(&mut self) -> Result<Reader> {
63+
self.s.read(self).await
64+
}
65+
}

common/dal2/src/ops/stat.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2021 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use async_trait::async_trait;
16+
use common_exception::Result;
17+
18+
use crate::ops::Object;
19+
20+
#[async_trait]
21+
pub trait Stat<S: Send + Sync>: Send + Sync {
22+
async fn stat(&self, path: &str) -> Result<Object> {
23+
let _ = path;
24+
unimplemented!()
25+
}
26+
}

0 commit comments

Comments
 (0)