Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(services): init monoiofs #4855

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
68 changes: 68 additions & 0 deletions core/Cargo.lock

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

3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions core/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
91 changes: 91 additions & 0 deletions core/src/services/monoiofs/backend.rs
Original file line number Diff line number Diff line change
@@ -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!()
}
}
46 changes: 46 additions & 0 deletions core/src/services/monoiofs/docs.md
Original file line number Diff line number Diff line change
@@ -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(())
}
```
20 changes: 20 additions & 0 deletions core/src/services/monoiofs/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions core/src/types/operator/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
6 changes: 6 additions & 0 deletions core/src/types/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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",
Expand Down
Loading