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 210afefdc refactor: Split immutable-index layer to new crate (#6967)
210afefdc is described below

commit 210afefdc1583e813c7468d9a5936dc7417ec123
Author: Qinxuan Chen <[email protected]>
AuthorDate: Fri Dec 12 18:35:00 2025 +0800

    refactor: Split immutable-index layer to new crate (#6967)
    
    * refactor: Split immutable-index layer to new crate
    
    * use mock service instead of http service
---
 core/Cargo.lock                                    | 13 ++++
 core/Cargo.toml                                    |  2 +
 core/core/src/layers/mod.rs                        |  3 -
 core/layers/immutable-index/Cargo.toml             | 42 +++++++++++
 .../immutable-index/src/lib.rs}                    | 82 +++++++++-------------
 core/src/lib.rs                                    |  2 +
 6 files changed, 93 insertions(+), 51 deletions(-)

diff --git a/core/Cargo.lock b/core/Cargo.lock
index f3192f4f1..ca3723756 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -5486,6 +5486,7 @@ dependencies = [
  "opendal-layer-capability-check",
  "opendal-layer-fastmetrics",
  "opendal-layer-fastrace",
+ "opendal-layer-immutable-index",
  "opendal-layer-metrics",
  "opendal-layer-mime-guess",
  "opendal-layer-observe-metrics-common",
@@ -5708,6 +5709,18 @@ dependencies = [
  "tokio",
 ]
 
+[[package]]
+name = "opendal-layer-immutable-index"
+version = "0.55.0"
+dependencies = [
+ "anyhow",
+ "futures",
+ "log",
+ "opendal-core",
+ "tokio",
+ "tracing-subscriber",
+]
+
 [[package]]
 name = "opendal-layer-metrics"
 version = "0.55.0"
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 2cad7d6c6..9fff946ec 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -94,6 +94,7 @@ layers-dtrace = ["opendal-core/layers-dtrace"]
 layers-fastmetrics = ["dep:opendal-layer-fastmetrics"]
 layers-fastrace = ["dep:opendal-layer-fastrace"]
 layers-metrics = ["dep:opendal-layer-metrics"]
+layers-immutable-index = ["dep:opendal-layer-immutable-index"]
 layers-mime-guess = ["dep:opendal-layer-mime-guess"]
 layers-otel-metrics = ["dep:opendal-layer-otelmetrics"]
 layers-otel-trace = ["dep:opendal-layer-oteltrace"]
@@ -193,6 +194,7 @@ opendal-layer-await-tree = { path = "layers/await-tree", 
version = "0.55.0", opt
 opendal-layer-capability-check = { path = "layers/capability-check", version = 
"0.55.0", optional = true, default-features = false }
 opendal-layer-fastmetrics = { path = "layers/fastmetrics", version = "0.55.0", 
optional = true, default-features = false }
 opendal-layer-fastrace = { path = "layers/fastrace", version = "0.55.0", 
optional = true, default-features = false }
+opendal-layer-immutable-index = { path = "layers/immutable-index", version = 
"0.55.0", optional = true, default-features = false }
 opendal-layer-metrics = { path = "layers/metrics", version = "0.55.0", 
optional = true, default-features = false }
 opendal-layer-mime-guess = { path = "layers/mime-guess", version = "0.55.0", 
optional = true, default-features = false }
 opendal-layer-observe-metrics-common = { path = 
"layers/observe-metrics-common", version = "0.55.0", optional = true, 
default-features = false }
diff --git a/core/core/src/layers/mod.rs b/core/core/src/layers/mod.rs
index 813601ed3..a4acf2c10 100644
--- a/core/core/src/layers/mod.rs
+++ b/core/core/src/layers/mod.rs
@@ -32,9 +32,6 @@ pub use simulate::SimulateLayer;
 mod concurrent_limit;
 pub use concurrent_limit::ConcurrentLimitLayer;
 
-mod immutable_index;
-pub use immutable_index::ImmutableIndexLayer;
-
 mod logging;
 pub use logging::LoggingInterceptor;
 pub use logging::LoggingLayer;
diff --git a/core/layers/immutable-index/Cargo.toml 
b/core/layers/immutable-index/Cargo.toml
new file mode 100644
index 000000000..b45debe6f
--- /dev/null
+++ b/core/layers/immutable-index/Cargo.toml
@@ -0,0 +1,42 @@
+# 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 immutable-index layer"
+name = "opendal-layer-immutable-index"
+
+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]
+opendal-core = { path = "../../core", version = "0.55.0", default-features = 
false }
+
+[dev-dependencies]
+anyhow = { version = "1.0.100", features = ["std"] }
+futures = { workspace = true, default-features = true }
+log = { workspace = true }
+opendal-core = { path = "../../core", version = "0.55.0" }
+tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
+tracing-subscriber = { version = "0.3", features = ["env-filter", 
"tracing-log"] }
diff --git a/core/core/src/layers/immutable_index.rs 
b/core/layers/immutable-index/src/lib.rs
similarity index 87%
rename from core/core/src/layers/immutable_index.rs
rename to core/layers/immutable-index/src/lib.rs
index b3fc17b03..e43f27e83 100644
--- a/core/core/src/layers/immutable_index.rs
+++ b/core/layers/immutable-index/src/lib.rs
@@ -19,8 +19,8 @@ use std::collections::HashSet;
 use std::fmt::Debug;
 use std::vec::IntoIter;
 
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
 
 /// Add an immutable in-memory index for underlying storage services.
 ///
@@ -30,12 +30,12 @@ use crate::*;
 ///
 /// ```rust, no_run
 /// # use std::collections::HashMap;
-///
-/// # use opendal_core::layers::ImmutableIndexLayer;
+/// #
 /// # use opendal_core::services;
 /// # use opendal_core::Operator;
 /// # use opendal_core::Result;
-///
+/// # use opendal_layer_immutable_index::ImmutableIndexLayer;
+/// #
 /// # fn main() -> Result<()> {
 /// let mut iil = ImmutableIndexLayer::default();
 ///
@@ -46,7 +46,7 @@ use crate::*;
 /// let op = Operator::from_iter::<services::Memory>(HashMap::<_, 
_>::default())?
 ///     .layer(iil)
 ///     .finish();
-/// Ok(())
+/// # Ok(())
 /// # }
 /// ```
 #[derive(Default, Debug, Clone)]
@@ -211,20 +211,38 @@ impl oio::List for ImmutableDir {
 }
 
 #[cfg(test)]
-#[cfg(feature = "services-http")]
 mod tests {
     use std::collections::HashMap;
-    use std::collections::HashSet;
+    use std::sync::Arc;
 
     use anyhow::Result;
     use futures::TryStreamExt;
     use log::debug;
+    use opendal_core::EntryMode;
+    use opendal_core::Operator;
+    use opendal_core::raw::*;
 
     use super::*;
-    use crate::EntryMode;
-    use crate::Operator;
-    use crate::layers::LoggingLayer;
-    use crate::services::HttpConfig;
+
+    #[derive(Debug)]
+    struct MockService;
+
+    impl Access for MockService {
+        type Reader = oio::Reader;
+        type Writer = oio::Writer;
+        type Lister = oio::Lister;
+        type Deleter = oio::Deleter;
+
+        fn info(&self) -> Arc<AccessorInfo> {
+            let info = AccessorInfo::default();
+            info.set_scheme("mock");
+            info.into()
+        }
+    }
+
+    fn build_operator(layer: ImmutableIndexLayer) -> Operator {
+        Operator::from_inner(Arc::new(MockService)).layer(layer)
+    }
 
     #[tokio::test]
     async fn test_list() -> Result<()> {
@@ -235,15 +253,7 @@ mod tests {
             iil.insert(i.to_string())
         }
 
-        let op = HttpConfig::from_iter({
-            let mut map = HashMap::new();
-            map.insert("endpoint".to_string(), 
"https://xuanwo.io".to_string());
-            map
-        })
-        .and_then(Operator::from_config)?
-        .layer(LoggingLayer::default())
-        .layer(iil)
-        .finish();
+        let op = build_operator(iil);
 
         let mut map = HashMap::new();
         let mut set = HashSet::new();
@@ -273,15 +283,7 @@ mod tests {
             iil.insert(i.to_string())
         }
 
-        let op = HttpConfig::from_iter({
-            let mut map = HashMap::new();
-            map.insert("endpoint".to_string(), 
"https://xuanwo.io".to_string());
-            map
-        })
-        .and_then(Operator::from_config)?
-        .layer(LoggingLayer::default())
-        .layer(iil)
-        .finish();
+        let op = build_operator(iil);
 
         let mut ds = op.lister_with("/").recursive(true).await?;
         let mut set = HashSet::new();
@@ -317,15 +319,7 @@ mod tests {
             iil.insert(i.to_string())
         }
 
-        let op = HttpConfig::from_iter({
-            let mut map = HashMap::new();
-            map.insert("endpoint".to_string(), 
"https://xuanwo.io".to_string());
-            map
-        })
-        .and_then(Operator::from_config)?
-        .layer(LoggingLayer::default())
-        .layer(iil)
-        .finish();
+        let op = build_operator(iil);
 
         //  List /
         let mut map = HashMap::new();
@@ -375,15 +369,7 @@ mod tests {
             iil.insert(i.to_string())
         }
 
-        let op = HttpConfig::from_iter({
-            let mut map = HashMap::new();
-            map.insert("endpoint".to_string(), 
"https://xuanwo.io".to_string());
-            map
-        })
-        .and_then(Operator::from_config)?
-        .layer(LoggingLayer::default())
-        .layer(iil)
-        .finish();
+        let op = build_operator(iil);
 
         let mut ds = op.lister_with("/").recursive(true).await?;
 
diff --git a/core/src/lib.rs b/core/src/lib.rs
index ce3c042cf..609052e02 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -66,6 +66,8 @@ pub mod layers {
     pub use opendal_layer_fastmetrics::*;
     #[cfg(feature = "layers-fastrace")]
     pub use opendal_layer_fastrace::*;
+    #[cfg(feature = "layers-immutable-index")]
+    pub use opendal_layer_immutable_index::*;
     #[cfg(feature = "layers-metrics")]
     pub use opendal_layer_metrics::*;
     #[cfg(feature = "layers-mime-guess")]

Reply via email to