You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2024/07/05 11:48:45 UTC

(opendal) branch main updated: feat(services): init monoiofs (#4855)

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new ce844a6672 feat(services): init monoiofs (#4855)
ce844a6672 is described below

commit ce844a6672ab6e6a769a0ab10c42172724eaad45
Author: NKID00 <th...@nkid00.name>
AuthorDate: Fri Jul 5 19:48:40 2024 +0800

    feat(services): init monoiofs (#4855)
    
    * feat(services): init monoiofs
    
    * refactor(services/monoiofs): derive Debug instead of manual impl
    
    It is unlikely to introduce credentials or non-primitive fields in MonoiofsConfig, so default Debug implementation should be fine.
---
 core/Cargo.lock                       | 68 ++++++++++++++++++++++++++
 core/Cargo.toml                       |  3 ++
 core/src/services/mod.rs              |  7 +++
 core/src/services/monoiofs/backend.rs | 91 +++++++++++++++++++++++++++++++++++
 core/src/services/monoiofs/docs.md    | 46 ++++++++++++++++++
 core/src/services/monoiofs/mod.rs     | 20 ++++++++
 core/src/types/operator/builder.rs    |  2 +
 core/src/types/scheme.rs              |  6 +++
 8 files changed, 243 insertions(+)

diff --git a/core/Cargo.lock b/core/Cargo.lock
index 46daafd3ac..5d499885c6 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -499,6 +499,17 @@ dependencies = [
  "urlencoding",
 ]
 
+[[package]]
+name = "auto-const-array"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62f7df18977a1ee03650ee4b31b4aefed6d56bac188760b6e37610400fe8d4bb"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.68",
+]
+
 [[package]]
 name = "autocfg"
 version = "1.3.0"
@@ -4202,6 +4213,15 @@ dependencies = [
  "libc",
 ]
 
+[[package]]
+name = "memoffset"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4"
+dependencies = [
+ "autocfg",
+]
+
 [[package]]
 name = "metrics"
 version = "0.23.0"
@@ -4401,6 +4421,40 @@ dependencies = [
  "webpki-roots 0.25.4",
 ]
 
+[[package]]
+name = "monoio"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60824f1a372fa200937885a2d434610333fe47d6c6f3d0855bd4555b46316fe7"
+dependencies = [
+ "auto-const-array",
+ "bytes",
+ "flume",
+ "fxhash",
+ "io-uring",
+ "libc",
+ "memchr",
+ "mio",
+ "monoio-macros",
+ "nix",
+ "once_cell",
+ "pin-project-lite",
+ "socket2 0.5.7",
+ "threadpool",
+ "windows-sys 0.48.0",
+]
+
+[[package]]
+name = "monoio-macros"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "176a5f5e69613d9e88337cf2a65e11135332b4efbcc628404a7c555e4452084c"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.68",
+]
+
 [[package]]
 name = "multimap"
 version = "0.10.0"
@@ -4549,6 +4603,19 @@ dependencies = [
  "smallvec",
 ]
 
+[[package]]
+name = "nix"
+version = "0.26.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
+dependencies = [
+ "bitflags 1.3.2",
+ "cfg-if",
+ "libc",
+ "memoffset",
+ "pin-utils",
+]
+
 [[package]]
 name = "no-std-compat"
 version = "0.4.1"
@@ -4748,6 +4815,7 @@ dependencies = [
  "minitrace",
  "moka",
  "mongodb",
+ "monoio",
  "mysql_async",
  "once_cell",
  "openssh",
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 3e2051f978..f297c2dc13 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -159,6 +159,7 @@ services-memory = []
 services-mini-moka = ["dep:mini-moka"]
 services-moka = ["dep:moka"]
 services-mongodb = ["dep:mongodb"]
+services-monoiofs = ["dep:monoio"]
 services-mysql = ["dep:mysql_async"]
 services-obs = [
   "dep:reqsign",
@@ -345,6 +346,8 @@ compio = { version = "0.11.0", optional = true, features = [
 ] }
 # for services-s3
 crc32c = { version = "0.6.6", optional = true }
+# for services-monoiofs
+monoio = { version = "0.2.3", optional = true, features = ["sync"] }
 
 # Layers
 # for layers-async-backtrace
diff --git a/core/src/services/mod.rs b/core/src/services/mod.rs
index f6e7c15931..8f5fc8e58e 100644
--- a/core/src/services/mod.rs
+++ b/core/src/services/mod.rs
@@ -420,3 +420,10 @@ pub use surrealdb::SurrealdbConfig;
 mod compfs;
 #[cfg(feature = "services-compfs")]
 pub use compfs::Compfs;
+
+#[cfg(feature = "services-monoiofs")]
+mod monoiofs;
+#[cfg(feature = "services-monoiofs")]
+pub use monoiofs::Monoiofs;
+#[cfg(feature = "services-monoiofs")]
+pub use monoiofs::MonoiofsConfig;
diff --git a/core/src/services/monoiofs/backend.rs b/core/src/services/monoiofs/backend.rs
new file mode 100644
index 0000000000..f68fd6b8fa
--- /dev/null
+++ b/core/src/services/monoiofs/backend.rs
@@ -0,0 +1,91 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::fmt::Debug;
+
+use serde::Deserialize;
+
+use crate::raw::*;
+use crate::*;
+
+/// Config for monoiofs services support.
+#[derive(Default, Deserialize, Debug)]
+#[serde(default)]
+#[non_exhaustive]
+pub struct MonoiofsConfig {
+    /// The Root of this backend.
+    ///
+    /// All operations will happen under this root.
+    ///
+    /// Default to `/` if not set.
+    pub root: Option<String>,
+}
+
+/// File system support via [`monoio`].
+#[doc = include_str!("docs.md")]
+#[derive(Default, Debug)]
+pub struct MonoiofsBuilder {
+    config: MonoiofsConfig,
+}
+
+impl MonoiofsBuilder {
+    /// Set root of this backend.
+    ///
+    /// All operations will happen under this root.
+    pub fn root(&mut self, root: &str) -> &mut Self {
+        self.config.root = if root.is_empty() {
+            None
+        } else {
+            Some(root.to_string())
+        };
+
+        self
+    }
+}
+
+impl Builder for MonoiofsBuilder {
+    const SCHEME: Scheme = Scheme::Monoiofs;
+
+    type Accessor = MonoiofsBackend;
+
+    fn from_map(map: std::collections::HashMap<String, String>) -> Self {
+        let config = MonoiofsConfig::deserialize(ConfigDeserializer::new(map))
+            .expect("config deserialize must succeed");
+
+        MonoiofsBuilder { config }
+    }
+
+    fn build(&mut self) -> Result<Self::Accessor> {
+        todo!()
+    }
+}
+
+#[derive(Debug, Clone)]
+pub struct MonoiofsBackend {}
+
+impl Access for MonoiofsBackend {
+    type Reader = ();
+    type Writer = ();
+    type Lister = ();
+    type BlockingReader = ();
+    type BlockingWriter = ();
+    type BlockingLister = ();
+
+    fn info(&self) -> AccessorInfo {
+        todo!()
+    }
+}
diff --git a/core/src/services/monoiofs/docs.md b/core/src/services/monoiofs/docs.md
new file mode 100644
index 0000000000..47b0d5d8f0
--- /dev/null
+++ b/core/src/services/monoiofs/docs.md
@@ -0,0 +1,46 @@
+## Capabilities
+
+This service can be used to:
+
+- [ ] stat
+- [ ] read
+- [ ] write
+- [ ] append
+- [ ] create_dir
+- [ ] delete
+- [ ] copy
+- [ ] rename
+- [ ] list
+- [ ] ~~presign~~
+- [ ] blocking
+
+## Configuration
+
+- `root`: Set the work dir for backend.
+
+You can refer to [`MonoiofsBuilder`]'s docs for more information
+
+## Example
+
+### Via Builder
+
+```rust,no_run
+use anyhow::Result;
+use opendal::services::Monoiofs;
+use opendal::Operator;
+
+#[tokio::main]
+async fn main() -> Result<()> {
+    // Create monoiofs backend builder.
+    let mut builder = Monoiofs::default();
+    // Set the root for monoiofs, all operations will happen under this root.
+    //
+    // NOTE: the root must be absolute path.
+    builder.root("/tmp");
+
+    // `Accessor` provides the low level APIs, we will use `Operator` normally.
+    let op: Operator = Operator::new(builder)?.finish();
+
+    Ok(())
+}
+```
diff --git a/core/src/services/monoiofs/mod.rs b/core/src/services/monoiofs/mod.rs
new file mode 100644
index 0000000000..68c23e3f1e
--- /dev/null
+++ b/core/src/services/monoiofs/mod.rs
@@ -0,0 +1,20 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+mod backend;
+pub use backend::MonoiofsBuilder as Monoiofs;
+pub use backend::MonoiofsConfig;
diff --git a/core/src/types/operator/builder.rs b/core/src/types/operator/builder.rs
index c205fa887a..ab1d96bc9c 100644
--- a/core/src/types/operator/builder.rs
+++ b/core/src/types/operator/builder.rs
@@ -222,6 +222,8 @@ impl Operator {
             Scheme::MiniMoka => Self::from_map::<services::MiniMoka>(map)?.finish(),
             #[cfg(feature = "services-moka")]
             Scheme::Moka => Self::from_map::<services::Moka>(map)?.finish(),
+            #[cfg(feature = "services-monoiofs")]
+            Scheme::Monoiofs => Self::from_map::<services::Monoiofs>(map)?.finish(),
             #[cfg(feature = "services-mysql")]
             Scheme::Mysql => Self::from_map::<services::Mysql>(map)?.finish(),
             #[cfg(feature = "services-obs")]
diff --git a/core/src/types/scheme.rs b/core/src/types/scheme.rs
index 5a3e74fe85..e34e66fae3 100644
--- a/core/src/types/scheme.rs
+++ b/core/src/types/scheme.rs
@@ -105,6 +105,8 @@ pub enum Scheme {
     MiniMoka,
     /// [moka][crate::services::Moka]: moka backend support.
     Moka,
+    /// [monoiofs][crate::services::Monoiofs]: monoio fs services.
+    Monoiofs,
     /// [obs][crate::services::Obs]: Huawei Cloud OBS services.
     Obs,
     /// [onedrive][crate::services::Onedrive]: Microsoft OneDrive services.
@@ -251,6 +253,8 @@ impl Scheme {
             Scheme::MiniMoka,
             #[cfg(feature = "services-moka")]
             Scheme::Moka,
+            #[cfg(feature = "services-monoiofs")]
+            Scheme::Monoiofs,
             #[cfg(feature = "services-mysql")]
             Scheme::Mysql,
             #[cfg(feature = "services-obs")]
@@ -370,6 +374,7 @@ impl FromStr for Scheme {
             "sqlite" => Ok(Scheme::Sqlite),
             "mini_moka" => Ok(Scheme::MiniMoka),
             "moka" => Ok(Scheme::Moka),
+            "monoiofs" => Ok(Scheme::Monoiofs),
             "obs" => Ok(Scheme::Obs),
             "onedrive" => Ok(Scheme::Onedrive),
             "persy" => Ok(Scheme::Persy),
@@ -436,6 +441,7 @@ impl From<Scheme> for &'static str {
             Scheme::Memory => "memory",
             Scheme::MiniMoka => "mini_moka",
             Scheme::Moka => "moka",
+            Scheme::Monoiofs => "monoiofs",
             Scheme::Obs => "obs",
             Scheme::Onedrive => "onedrive",
             Scheme::Persy => "persy",