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

koushiro 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 0ebefe6ab refactor(services/rocksdb): split rocksdb service as a crate 
(#7081)
0ebefe6ab is described below

commit 0ebefe6abcccf7bc00e8539a88b7602f114ded1a
Author: KarinaMilet <[email protected]>
AuthorDate: Mon Dec 22 17:41:27 2025 +0800

    refactor(services/rocksdb): split rocksdb service as a crate (#7081)
    
    * migrate rocksdb into crate
    
    * run toml formatter
    
    * add license
    
    * downgrade rocksdb version
    
    * fix dependency error
    
    * re-export rocksdb service
    
    * follow review advice
    
    * follow review advice
    
    * fix typo in docs.md
    
    * revert some changes
    
    * update config
    
    ---------
    
    Co-authored-by: koushiro <[email protected]>
---
 core/Cargo.lock                                    | 13 ++++++-
 core/Cargo.toml                                    |  3 +-
 core/core/Cargo.toml                               |  3 --
 core/core/src/services/mod.rs                      |  5 ---
 core/services/rocksdb/Cargo.toml                   | 40 ++++++++++++++++++++++
 .../rocksdb => services/rocksdb/src}/backend.rs    | 10 +++---
 .../rocksdb => services/rocksdb/src}/config.rs     | 15 ++++----
 .../rocksdb => services/rocksdb/src}/core.rs       |  2 +-
 .../rocksdb => services/rocksdb/src}/deleter.rs    |  8 ++---
 .../rocksdb => services/rocksdb/src}/docs.md       |  4 +--
 .../rocksdb/mod.rs => services/rocksdb/src/lib.rs} |  6 ++--
 .../rocksdb => services/rocksdb/src}/lister.rs     |  6 ++--
 .../rocksdb => services/rocksdb/src}/writer.rs     |  5 +--
 core/src/lib.rs                                    |  2 ++
 14 files changed, 84 insertions(+), 38 deletions(-)

diff --git a/core/Cargo.lock b/core/Cargo.lock
index c5ca7a3a8..74a986bac 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -5601,6 +5601,7 @@ dependencies = [
  "opendal-service-persy",
  "opendal-service-postgresql",
  "opendal-service-redb",
+ "opendal-service-rocksdb",
  "opendal-service-s3",
  "opendal-service-seafile",
  "opendal-service-sftp",
@@ -5682,7 +5683,6 @@ dependencies = [
  "redis",
  "reqsign",
  "reqwest",
- "rocksdb",
  "serde",
  "serde_json",
  "sha2",
@@ -6590,6 +6590,17 @@ dependencies = [
  "tokio",
 ]
 
+[[package]]
+name = "opendal-service-rocksdb"
+version = "0.55.0"
+dependencies = [
+ "ctor",
+ "opendal-core",
+ "rocksdb",
+ "serde",
+ "tokio",
+]
+
 [[package]]
 name = "opendal-service-s3"
 version = "0.55.0"
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 43b061a1e..6906c60c1 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -161,7 +161,7 @@ services-postgresql = ["dep:opendal-service-postgresql"]
 services-redb = ["dep:opendal-service-redb"]
 services-redis = ["opendal-core/services-redis"]
 services-redis-native-tls = ["opendal-core/services-redis-native-tls"]
-services-rocksdb = ["opendal-core/services-rocksdb"]
+services-rocksdb = ["dep:opendal-service-rocksdb"]
 services-s3 = ["dep:opendal-service-s3"]
 services-seafile = ["dep:opendal-service-seafile"]
 services-sftp = ["dep:opendal-service-sftp"]
@@ -264,6 +264,7 @@ opendal-service-pcloud = { path = "services/pcloud", 
version = "0.55.0", optiona
 opendal-service-persy = { path = "services/persy", 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-redb = { path = "services/redb", version = "0.55.0", optional 
= true, default-features = false }
+opendal-service-rocksdb = { path = "services/rocksdb", 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-seafile = { path = "services/seafile", version = "0.55.0", 
optional = true, default-features = false }
 opendal-service-sftp = { path = "services/sftp", version = "0.55.0", optional 
= true, default-features = false }
diff --git a/core/core/Cargo.toml b/core/core/Cargo.toml
index 058a720a5..e372b3b2f 100644
--- a/core/core/Cargo.toml
+++ b/core/core/Cargo.toml
@@ -57,7 +57,6 @@ executors-tokio = ["tokio/rt"]
 services-memory = []
 services-redis = ["dep:redis", "dep:fastpool", "redis?/tokio-rustls-comp"]
 services-redis-native-tls = ["services-redis", "redis?/tokio-native-tls-comp"]
-services-rocksdb = ["dep:rocksdb", "internal-tokio-rt"]
 
 [lib]
 bench = false
@@ -105,8 +104,6 @@ redis = { version = "1.0", features = [
   "tokio-comp",
   "connection-manager",
 ], optional = true }
-# for services-rocksdb
-rocksdb = { version = "0.21.0", default-features = false, optional = true }
 
 [target.'cfg(target_arch = "wasm32")'.dependencies]
 backon = { version = "1.6", features = ["gloo-timers-sleep"] }
diff --git a/core/core/src/services/mod.rs b/core/core/src/services/mod.rs
index 7bb1ab8c7..ec77723ab 100644
--- a/core/core/src/services/mod.rs
+++ b/core/core/src/services/mod.rs
@@ -28,8 +28,3 @@ pub use self::memory::*;
 mod redis;
 #[cfg(feature = "services-redis")]
 pub use self::redis::*;
-
-#[cfg(feature = "services-rocksdb")]
-mod rocksdb;
-#[cfg(feature = "services-rocksdb")]
-pub use self::rocksdb::*;
diff --git a/core/services/rocksdb/Cargo.toml b/core/services/rocksdb/Cargo.toml
new file mode 100644
index 000000000..55433205a
--- /dev/null
+++ b/core/services/rocksdb/Cargo.toml
@@ -0,0 +1,40 @@
+# 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.
+
+[package]
+description = "Apache OpenDAL RocksDB service implementation"
+name = "opendal-service-rocksdb"
+
+authors = { workspace = true }
+edition = { workspace = true }
+homepage = { workspace = true }
+license = { workspace = true }
+repository = { workspace = true }
+rust-version = { workspace = true }
+version = { workspace = true }
+
+[package.metadata.docs.rs]
+all-features = true
+
+[dependencies]
+ctor = { workspace = true }
+opendal-core = { path = "../../core", version = "0.55.0", default-features = 
false }
+rocksdb = { version = "0.21.0", default-features = false }
+serde = { workspace = true, features = ["derive"] }
+
+[dev-dependencies]
+tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
diff --git a/core/core/src/services/rocksdb/backend.rs 
b/core/services/rocksdb/src/backend.rs
similarity index 96%
rename from core/core/src/services/rocksdb/backend.rs
rename to core/services/rocksdb/src/backend.rs
index 277118d25..c3a27e2b6 100644
--- a/core/core/src/services/rocksdb/backend.rs
+++ b/core/services/rocksdb/src/backend.rs
@@ -17,6 +17,8 @@
 
 use std::sync::Arc;
 
+use opendal_core::raw::*;
+use opendal_core::*;
 use rocksdb::DB;
 
 use super::ROCKSDB_SCHEME;
@@ -25,8 +27,6 @@ use super::core::*;
 use super::deleter::RocksdbDeleter;
 use super::lister::RocksdbLister;
 use super::writer::RocksdbWriter;
-use crate::raw::*;
-use crate::*;
 
 /// RocksDB service support.
 #[doc = include_str!("docs.md")]
@@ -36,13 +36,13 @@ pub struct RocksdbBuilder {
 }
 
 impl RocksdbBuilder {
-    /// Set the path to the rocksdb data directory. Will create if not exists.
+    /// Set the path to the rocksdb data directory. Creates if not exists.
     pub fn datadir(mut self, path: &str) -> Self {
         self.config.datadir = Some(path.into());
         self
     }
 
-    /// set the working directory, all operations will be performed under it.
+    /// Set the working directory, all operations will be performed under it.
     ///
     /// default: "/"
     pub fn root(mut self, root: &str) -> Self {
@@ -77,7 +77,7 @@ impl Builder for RocksdbBuilder {
     }
 }
 
-/// Backend for rocksdb services.
+/// Backend for rocksdb service.
 #[derive(Clone, Debug)]
 pub struct RocksdbBackend {
     core: Arc<RocksdbCore>,
diff --git a/core/core/src/services/rocksdb/config.rs 
b/core/services/rocksdb/src/config.rs
similarity index 86%
rename from core/core/src/services/rocksdb/config.rs
rename to core/services/rocksdb/src/config.rs
index 659748fad..933735d71 100644
--- a/core/core/src/services/rocksdb/config.rs
+++ b/core/services/rocksdb/src/config.rs
@@ -15,6 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use opendal_core::*;
 use serde::Deserialize;
 use serde::Serialize;
 
@@ -33,10 +34,10 @@ pub struct RocksdbConfig {
     pub root: Option<String>,
 }
 
-impl crate::Configurator for RocksdbConfig {
+impl Configurator for RocksdbConfig {
     type Builder = RocksdbBuilder;
 
-    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(path) = uri.root() {
@@ -57,19 +58,17 @@ impl crate::Configurator for RocksdbConfig {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::Configurator;
-    use crate::types::OperatorUri;
 
     #[test]
-    fn from_uri_sets_datadir_and_root() {
+    fn from_uri_sets_datadir_and_root() -> Result<()> {
         let uri = OperatorUri::new(
             "rocksdb:///var/db?root=namespace",
             Vec::<(String, String)>::new(),
-        )
-        .unwrap();
+        )?;
 
-        let cfg = RocksdbConfig::from_uri(&uri).unwrap();
+        let cfg = RocksdbConfig::from_uri(&uri)?;
         assert_eq!(cfg.datadir.as_deref(), Some("/var/db"));
         assert_eq!(cfg.root.as_deref(), Some("namespace"));
+        Ok(())
     }
 }
diff --git a/core/core/src/services/rocksdb/core.rs 
b/core/services/rocksdb/src/core.rs
similarity index 99%
rename from core/core/src/services/rocksdb/core.rs
rename to core/services/rocksdb/src/core.rs
index 4962b11ce..6beb2d63d 100644
--- a/core/core/src/services/rocksdb/core.rs
+++ b/core/services/rocksdb/src/core.rs
@@ -20,7 +20,7 @@ use std::sync::Arc;
 
 use rocksdb::DB;
 
-use crate::*;
+use opendal_core::*;
 
 #[derive(Clone)]
 pub struct RocksdbCore {
diff --git a/core/core/src/services/rocksdb/deleter.rs 
b/core/services/rocksdb/src/deleter.rs
similarity index 94%
rename from core/core/src/services/rocksdb/deleter.rs
rename to core/services/rocksdb/src/deleter.rs
index a42c62144..a6f14b9b7 100644
--- a/core/core/src/services/rocksdb/deleter.rs
+++ b/core/services/rocksdb/src/deleter.rs
@@ -17,10 +17,10 @@
 
 use std::sync::Arc;
 
-use super::core::*;
-use crate::raw::oio;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
+
+use super::core::RocksdbCore;
 
 pub struct RocksdbDeleter {
     core: Arc<RocksdbCore>,
diff --git a/core/core/src/services/rocksdb/docs.md 
b/core/services/rocksdb/src/docs.md
similarity index 94%
rename from core/core/src/services/rocksdb/docs.md
rename to core/services/rocksdb/src/docs.md
index aa419f475..6ca0655fb 100644
--- a/core/core/src/services/rocksdb/docs.md
+++ b/core/services/rocksdb/src/docs.md
@@ -38,9 +38,9 @@ You can refer to [`RocksdbBuilder`]'s docs for more 
information.
 ### Via Builder
 
 ```rust,no_run
-use anyhow::Result;
-use opendal_core::services::Rocksdb;
 use opendal_core::Operator;
+use opendal_core::Result;
+use opendal_service_rocksdb::Rocksdb;
 
 #[tokio::main]
 async fn main() -> Result<()> {
diff --git a/core/core/src/services/rocksdb/mod.rs 
b/core/services/rocksdb/src/lib.rs
similarity index 88%
rename from core/core/src/services/rocksdb/mod.rs
rename to core/services/rocksdb/src/lib.rs
index 4447dc778..344a5f310 100644
--- a/core/core/src/services/rocksdb/mod.rs
+++ b/core/services/rocksdb/src/lib.rs
@@ -18,7 +18,7 @@
 /// Default scheme for rocksdb service.
 pub const ROCKSDB_SCHEME: &str = "rocksdb";
 
-use crate::types::DEFAULT_OPERATOR_REGISTRY;
+use opendal_core::DEFAULT_OPERATOR_REGISTRY;
 
 mod backend;
 mod config;
@@ -27,8 +27,8 @@ mod deleter;
 mod lister;
 mod writer;
 
-pub use backend::RocksdbBuilder as Rocksdb;
-pub use config::RocksdbConfig;
+pub use crate::backend::RocksdbBuilder as Rocksdb;
+pub use crate::config::RocksdbConfig;
 
 #[ctor::ctor]
 fn register_rocksdb_service() {
diff --git a/core/core/src/services/rocksdb/lister.rs 
b/core/services/rocksdb/src/lister.rs
similarity index 97%
rename from core/core/src/services/rocksdb/lister.rs
rename to core/services/rocksdb/src/lister.rs
index e5eb0422b..b39548cec 100644
--- a/core/core/src/services/rocksdb/lister.rs
+++ b/core/services/rocksdb/src/lister.rs
@@ -18,10 +18,10 @@
 use std::sync::Arc;
 use std::vec::IntoIter;
 
+use opendal_core::raw::*;
+use opendal_core::*;
+
 use super::core::*;
-use crate::raw::oio;
-use crate::raw::*;
-use crate::*;
 
 pub struct RocksdbLister {
     root: String,
diff --git a/core/core/src/services/rocksdb/writer.rs 
b/core/services/rocksdb/src/writer.rs
similarity index 97%
rename from core/core/src/services/rocksdb/writer.rs
rename to core/services/rocksdb/src/writer.rs
index 40c19e9cf..58699e8ed 100644
--- a/core/core/src/services/rocksdb/writer.rs
+++ b/core/services/rocksdb/src/writer.rs
@@ -17,9 +17,10 @@
 
 use std::sync::Arc;
 
+use opendal_core::raw::*;
+use opendal_core::*;
+
 use super::core::*;
-use crate::raw::oio;
-use crate::*;
 
 pub struct RocksdbWriter {
     core: Arc<RocksdbCore>,
diff --git a/core/src/lib.rs b/core/src/lib.rs
index a17f8f792..c58e39325 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -120,6 +120,8 @@ pub mod services {
     pub use opendal_service_postgresql::*;
     #[cfg(feature = "services-redb")]
     pub use opendal_service_redb::*;
+    #[cfg(feature = "services-rocksdb")]
+    pub use opendal_service_rocksdb::*;
     #[cfg(feature = "services-s3")]
     pub use opendal_service_s3::*;
     #[cfg(feature = "services-seafile")]

Reply via email to