This is an automated email from the ASF dual-hosted git repository. koushiro pushed a commit to branch extract-dashmap-service in repository https://gitbox.apache.org/repos/asf/opendal.git
commit c8e25549ba456e4b9fbec422e7ae56862f45e54e Author: koushiro <[email protected]> AuthorDate: Tue Dec 16 14:09:00 2025 +0800 refactor: Split dashmap service to new crate --- core/Cargo.lock | 13 ++++++++++++- core/Cargo.toml | 5 +++-- core/core/Cargo.toml | 3 --- core/core/src/services/mod.rs | 5 ----- core/services/{sqlite => dashmap}/Cargo.toml | 15 +++++---------- .../services/dashmap => services/dashmap/src}/backend.rs | 4 ++-- .../services/dashmap => services/dashmap/src}/config.rs | 16 +++++++++------- .../services/dashmap => services/dashmap/src}/core.rs | 3 +-- .../services/dashmap => services/dashmap/src}/deleter.rs | 5 +++-- .../services/dashmap => services/dashmap/src}/docs.md | 2 +- .../dashmap/mod.rs => services/dashmap/src/lib.rs} | 12 ++++++++---- .../services/dashmap => services/dashmap/src}/lister.rs | 13 +++++++------ .../services/dashmap => services/dashmap/src}/writer.rs | 8 ++++---- core/services/sqlite/Cargo.toml | 1 - core/src/lib.rs | 2 ++ 15 files changed, 57 insertions(+), 50 deletions(-) diff --git a/core/Cargo.lock b/core/Cargo.lock index fcc412432..01af10cf7 100644 --- a/core/Cargo.lock +++ b/core/Cargo.lock @@ -5557,6 +5557,7 @@ dependencies = [ "opendal-service-azdls", "opendal-service-azfile", "opendal-service-cloudflare-kv", + "opendal-service-dashmap", "opendal-service-fs", "opendal-service-ftp", "opendal-service-gcs", @@ -5625,7 +5626,6 @@ dependencies = [ "compio", "criterion", "ctor", - "dashmap 6.1.0", "divan", "dotenvy", "etcd-client", @@ -5967,6 +5967,17 @@ dependencies = [ "serde_json", ] +[[package]] +name = "opendal-service-dashmap" +version = "0.55.0" +dependencies = [ + "ctor", + "dashmap 6.1.0", + "log", + "opendal-core", + "serde", +] + [[package]] name = "opendal-service-fs" version = "0.55.0" diff --git a/core/Cargo.toml b/core/Cargo.toml index e28afa65c..837cc0389 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -111,7 +111,7 @@ services-cloudflare-kv = ["dep:opendal-service-cloudflare-kv"] services-compfs = ["opendal-core/services-compfs"] services-cos = ["opendal-core/services-cos"] services-d1 = ["opendal-core/services-d1"] -services-dashmap = ["opendal-core/services-dashmap"] +services-dashmap = ["dep:opendal-service-dashmap"] services-dbfs = ["opendal-core/services-dbfs"] services-dropbox = ["opendal-core/services-dropbox"] services-etcd = ["opendal-core/services-etcd"] @@ -208,6 +208,7 @@ opendal-service-azblob = { path = "services/azblob", version = "0.55.0", optiona opendal-service-azdls = { path = "services/azdls", version = "0.55.0", optional = true, default-features = false } opendal-service-azfile = { path = "services/azfile", version = "0.55.0", optional = true, default-features = false } opendal-service-cloudflare-kv = { path = "services/cloudflare-kv", version = "0.55.0", optional = true, default-features = false } +opendal-service-dashmap = { path = "services/dashmap", version = "0.55.0", optional = true, default-features = false } opendal-service-fs = { path = "services/fs", version = "0.55.0", optional = true, default-features = false } opendal-service-ftp = { path = "services/ftp", version = "0.55.0", optional = true, default-features = false } opendal-service-gcs = { path = "services/gcs", version = "0.55.0", optional = true, default-features = false } @@ -220,8 +221,8 @@ opendal-service-obs = { path = "services/obs", version = "0.55.0", optional = tr opendal-service-oss = { path = "services/oss", version = "0.55.0", optional = true, default-features = false } opendal-service-postgresql = { path = "services/postgresql", version = "0.55.0", optional = true, default-features = false } opendal-service-s3 = { path = "services/s3", version = "0.55.0", optional = true, default-features = false } -opendal-service-sqlite = { path = "services/sqlite", version = "0.55.0", optional = true, default-features = false } opendal-service-sled = { path = "services/sled", version = "0.55.0", optional = true, default-features = false } +opendal-service-sqlite = { path = "services/sqlite", version = "0.55.0", optional = true, default-features = false } opendal-service-tikv = { path = "services/tikv", version = "0.55.0", optional = true, default-features = false } opendal-service-vercel-blob = { path = "services/vercel-blob", version = "0.55.0", optional = true, default-features = false } diff --git a/core/core/Cargo.toml b/core/core/Cargo.toml index 855ed1a41..0bc428b89 100644 --- a/core/core/Cargo.toml +++ b/core/core/Cargo.toml @@ -81,7 +81,6 @@ services-cos = [ "reqsign?/reqwest_request", ] services-d1 = [] -services-dashmap = ["dep:dashmap"] services-dbfs = [] services-dropbox = [] services-etcd = ["dep:etcd-client", "dep:fastpool"] @@ -178,8 +177,6 @@ cacache = { version = "13.0", default-features = false, features = [ "tokio-runtime", "mmap", ], optional = true } -# for services-dashmap -dashmap = { version = "6", optional = true } # for services-etcd etcd-client = { version = "0.17", optional = true, features = ["tls"] } # for services-foundationdb diff --git a/core/core/src/services/mod.rs b/core/core/src/services/mod.rs index 2f211a4f5..4dcfa4a66 100644 --- a/core/core/src/services/mod.rs +++ b/core/core/src/services/mod.rs @@ -44,11 +44,6 @@ mod d1; #[cfg(feature = "services-d1")] pub use self::d1::*; -#[cfg(feature = "services-dashmap")] -mod dashmap; -#[cfg(feature = "services-dashmap")] -pub use self::dashmap::*; - #[cfg(feature = "services-dbfs")] mod dbfs; #[cfg(feature = "services-dbfs")] diff --git a/core/services/sqlite/Cargo.toml b/core/services/dashmap/Cargo.toml similarity index 81% copy from core/services/sqlite/Cargo.toml copy to core/services/dashmap/Cargo.toml index 5afc1e0a1..f69d8c79f 100644 --- a/core/services/sqlite/Cargo.toml +++ b/core/services/dashmap/Cargo.toml @@ -16,8 +16,8 @@ # under the License. [package] -description = "Apache OpenDAL SQLite service implementation" -name = "opendal-service-sqlite" +description = "Apache OpenDAL Dashmap service implementation" +name = "opendal-service-dashmap" authors = { workspace = true } edition = { workspace = true } @@ -31,13 +31,8 @@ version = { workspace = true } all-features = true [dependencies] -opendal-core = { path = "../../core", version = "0.55.0", default-features = false } - ctor = { workspace = true } -mea = { version = "0.5.1" } +dashmap = "6" +log = { workspace = true } +opendal-core = { path = "../../core", version = "0.55.0", default-features = false } serde = { workspace = true, features = ["derive"] } -sqlx = { version = "0.8.0", features = ["runtime-tokio-rustls", "sqlite"] } - -[dev-dependencies] -tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } - diff --git a/core/core/src/services/dashmap/backend.rs b/core/services/dashmap/src/backend.rs similarity index 99% rename from core/core/src/services/dashmap/backend.rs rename to core/services/dashmap/src/backend.rs index 638631f0e..365e7e828 100644 --- a/core/core/src/services/dashmap/backend.rs +++ b/core/services/dashmap/src/backend.rs @@ -19,6 +19,8 @@ use std::sync::Arc; use dashmap::DashMap; use log::debug; +use opendal_core::raw::*; +use opendal_core::*; use super::DASHMAP_SCHEME; use super::config::DashmapConfig; @@ -26,8 +28,6 @@ use super::core::DashmapCore; use super::deleter::DashmapDeleter; use super::lister::DashmapLister; use super::writer::DashmapWriter; -use crate::raw::*; -use crate::*; /// [dashmap](https://github.com/xacrimon/dashmap) backend support. #[doc = include_str!("docs.md")] diff --git a/core/core/src/services/dashmap/config.rs b/core/services/dashmap/src/config.rs similarity index 84% rename from core/core/src/services/dashmap/config.rs rename to core/services/dashmap/src/config.rs index d3754ca39..8a49b46f0 100644 --- a/core/core/src/services/dashmap/config.rs +++ b/core/services/dashmap/src/config.rs @@ -15,6 +15,9 @@ // specific language governing permissions and limitations // under the License. +use opendal_core::Configurator; +use opendal_core::OperatorUri; +use opendal_core::Result; use serde::Deserialize; use serde::Serialize; @@ -29,9 +32,9 @@ pub struct DashmapConfig { pub root: Option<String>, } -impl crate::Configurator for DashmapConfig { +impl Configurator for DashmapConfig { type Builder = DashmapBuilder; - fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> { + fn from_uri(uri: &OperatorUri) -> Result<Self> { let mut map = uri.options().clone(); if let Some(root) = uri.root() { @@ -51,14 +54,13 @@ impl crate::Configurator for DashmapConfig { #[cfg(test)] mod tests { use super::*; - use crate::Configurator; - use crate::types::OperatorUri; #[test] - fn from_uri_sets_root() { - let uri = OperatorUri::new("dashmap:///cache", Vec::<(String, String)>::new()).unwrap(); + fn from_uri_sets_root() -> Result<()> { + let uri = OperatorUri::new("dashmap:///cache", Vec::<(String, String)>::new())?; - let cfg = DashmapConfig::from_uri(&uri).unwrap(); + let cfg = DashmapConfig::from_uri(&uri)?; assert_eq!(cfg.root.as_deref(), Some("cache")); + Ok(()) } } diff --git a/core/core/src/services/dashmap/core.rs b/core/services/dashmap/src/core.rs similarity index 98% rename from core/core/src/services/dashmap/core.rs rename to core/services/dashmap/src/core.rs index 173de8bd3..8d7bc8337 100644 --- a/core/core/src/services/dashmap/core.rs +++ b/core/services/dashmap/src/core.rs @@ -18,8 +18,7 @@ use std::fmt::Debug; use dashmap::DashMap; - -use crate::*; +use opendal_core::*; /// Value stored in dashmap cache containing both metadata and content #[derive(Clone)] diff --git a/core/core/src/services/dashmap/deleter.rs b/core/services/dashmap/src/deleter.rs similarity index 95% rename from core/core/src/services/dashmap/deleter.rs rename to core/services/dashmap/src/deleter.rs index 0f4e10e50..49450afbb 100644 --- a/core/core/src/services/dashmap/deleter.rs +++ b/core/services/dashmap/src/deleter.rs @@ -17,9 +17,10 @@ use std::sync::Arc; +use opendal_core::raw::*; +use opendal_core::*; + use super::core::DashmapCore; -use crate::raw::{OpDelete, build_abs_path, oio}; -use crate::*; pub struct DashmapDeleter { core: Arc<DashmapCore>, diff --git a/core/core/src/services/dashmap/docs.md b/core/services/dashmap/src/docs.md similarity index 93% rename from core/core/src/services/dashmap/docs.md rename to core/services/dashmap/src/docs.md index 8c44279fd..4e32f8a15 100644 --- a/core/core/src/services/dashmap/docs.md +++ b/core/services/dashmap/src/docs.md @@ -24,8 +24,8 @@ You can refer to [`DashmapBuilder`]'s docs for more information ```rust,no_run use anyhow::Result; -use opendal_core::services::Dashmap; use opendal_core::Operator; +use opendal_service_dashmap::Dashmap; #[tokio::main] async fn main() -> Result<()> { diff --git a/core/core/src/services/dashmap/mod.rs b/core/services/dashmap/src/lib.rs similarity index 82% rename from core/core/src/services/dashmap/mod.rs rename to core/services/dashmap/src/lib.rs index eff210847..b4051d01a 100644 --- a/core/core/src/services/dashmap/mod.rs +++ b/core/services/dashmap/src/lib.rs @@ -15,10 +15,11 @@ // specific language governing permissions and limitations // under the License. -/// Default scheme for dashmap service. -pub const DASHMAP_SCHEME: &str = "dashmap"; +//! Dashmap service implementation for Apache OpenDAL. -use crate::types::DEFAULT_OPERATOR_REGISTRY; +#![cfg_attr(docsrs, feature(doc_cfg))] +#![deny(missing_docs)] +#![deny(unused_crate_dependencies)] mod backend; mod config; @@ -30,7 +31,10 @@ mod writer; pub use backend::DashmapBuilder as Dashmap; pub use config::DashmapConfig; +/// Default scheme for dashmap service. +pub const DASHMAP_SCHEME: &str = "dashmap"; + #[ctor::ctor] fn register_dashmap_service() { - DEFAULT_OPERATOR_REGISTRY.register::<Dashmap>(DASHMAP_SCHEME); + opendal_core::DEFAULT_OPERATOR_REGISTRY.register::<Dashmap>(DASHMAP_SCHEME); } diff --git a/core/core/src/services/dashmap/lister.rs b/core/services/dashmap/src/lister.rs similarity index 89% rename from core/core/src/services/dashmap/lister.rs rename to core/services/dashmap/src/lister.rs index e276ac3d1..d74cc5891 100644 --- a/core/core/src/services/dashmap/lister.rs +++ b/core/services/dashmap/src/lister.rs @@ -15,13 +15,14 @@ // specific language governing permissions and limitations // under the License. -use super::core::DashmapCore; -use crate::raw::oio::Entry; -use crate::raw::{build_abs_path, build_rel_path, oio}; -use crate::*; use std::sync::Arc; use std::vec::IntoIter; +use opendal_core::raw::*; +use opendal_core::*; + +use super::core::DashmapCore; + pub struct DashmapLister { root: String, path: String, @@ -42,7 +43,7 @@ impl DashmapLister { } impl oio::List for DashmapLister { - async fn next(&mut self) -> Result<Option<Entry>> { + async fn next(&mut self) -> Result<Option<oio::Entry>> { for key in self.iter.by_ref() { if key.starts_with(&self.path) { let path = build_rel_path(&self.root, &key); @@ -53,7 +54,7 @@ impl oio::List for DashmapLister { } else { EntryMode::FILE }; - let entry = Entry::new(&path, Metadata::new(mode)); + let entry = oio::Entry::new(&path, Metadata::new(mode)); return Ok(Some(entry)); } } diff --git a/core/core/src/services/dashmap/writer.rs b/core/services/dashmap/src/writer.rs similarity index 96% rename from core/core/src/services/dashmap/writer.rs rename to core/services/dashmap/src/writer.rs index bb8409ba3..36517238a 100644 --- a/core/core/src/services/dashmap/writer.rs +++ b/core/services/dashmap/src/writer.rs @@ -17,10 +17,10 @@ use std::sync::Arc; -use super::core::DashmapCore; -use super::core::DashmapValue; -use crate::raw::*; -use crate::*; +use opendal_core::raw::*; +use opendal_core::*; + +use super::core::*; pub struct DashmapWriter { core: Arc<DashmapCore>, diff --git a/core/services/sqlite/Cargo.toml b/core/services/sqlite/Cargo.toml index 5afc1e0a1..00867279c 100644 --- a/core/services/sqlite/Cargo.toml +++ b/core/services/sqlite/Cargo.toml @@ -40,4 +40,3 @@ sqlx = { version = "0.8.0", features = ["runtime-tokio-rustls", "sqlite"] } [dev-dependencies] tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } - diff --git a/core/src/lib.rs b/core/src/lib.rs index 100f746b1..3e406c87c 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -39,6 +39,8 @@ pub mod services { pub use opendal_service_azfile::*; #[cfg(feature = "services-cloudflare-kv")] pub use opendal_service_cloudflare_kv::*; + #[cfg(feature = "services-dashmap")] + pub use opendal_service_dashmap::*; #[cfg(feature = "services-fs")] pub use opendal_service_fs::*; #[cfg(feature = "services-ftp")]
