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/03/19 10:40:21 UTC

(opendal) branch main updated: feat : Implement config for services/foundationdb (#4355)

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 4bb1d7614e feat : Implement config for services/foundationdb (#4355)
4bb1d7614e is described below

commit 4bb1d7614ed62a6739fea6757555d37ccc35e5b7
Author: Anurag Naik <12...@users.noreply.github.com>
AuthorDate: Tue Mar 19 16:10:15 2024 +0530

    feat : Implement config for services/foundationdb (#4355)
    
    * feat : Implement config for module in services
    
    Requesting a review of the PR. I have added the functionalities as I have understood from the described issue.
    
    * Delete mod.rs
    
    * Delete backend.rs
    
    * Update backend.rs
    
    * Update mod.rs
    
    * Update mod.rs
    
    * formatted backend.rs as suggested
    
    * fix linting errors with cargo fmt
    
    * fix linting errors with cargo fmt
    
    * feat : add config for services/foundationdb
    
    * add Debug method for FoundatonConfig
    
    * Update backend.rs
    
    * update backend.rs
    
    * Update mod.rs
    
    * formatted using cargo fmt
---
 core/src/services/foundationdb/backend.rs | 46 +++++++++++++++++++++++--------
 core/src/services/foundationdb/mod.rs     |  1 +
 core/src/services/mod.rs                  |  2 ++
 3 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/core/src/services/foundationdb/backend.rs b/core/src/services/foundationdb/backend.rs
index f7686ddee9..c95d9f9297 100644
--- a/core/src/services/foundationdb/backend.rs
+++ b/core/src/services/foundationdb/backend.rs
@@ -25,31 +25,54 @@ use foundationdb::api::NetworkAutoStop;
 use foundationdb::Database;
 
 use crate::raw::adapters::kv;
-use crate::raw::normalize_root;
+use crate::raw::*;
 use crate::Builder;
 use crate::Error;
 use crate::ErrorKind;
 use crate::Scheme;
 use crate::*;
 
+use serde::Deserialize;
+
 /// [foundationdb](https://www.foundationdb.org/) service support.
+///Config for FoundationDB.
+#[derive(Default, Deserialize)]
+#[serde(default)]
+#[non_exhaustive]
+pub struct FoundationConfig {
+    ///root of the backend.
+    pub root: Option<String>,
+    ///config_path for the backend.
+    pub config_path: Option<String>,
+}
+
+impl Debug for FoundationConfig {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        let mut ds = f.debug_struct("FoundationConfig");
+
+        ds.field("root", &self.root);
+        ds.field("config_path", &self.config_path);
+
+        ds.finish()
+    }
+}
+
 #[doc = include_str!("docs.md")]
 #[derive(Default)]
 pub struct FoundationdbBuilder {
-    root: Option<String>,
-    config_path: Option<String>,
+    config: FoundationConfig,
 }
 
 impl FoundationdbBuilder {
     /// Set the root for Foundationdb.
     pub fn root(&mut self, path: &str) -> &mut Self {
-        self.root = Some(path.into());
+        self.config.root = Some(path.into());
         self
     }
 
     /// Set the config path for Foundationdb. If not set, will fallback to use default
     pub fn config_path(&mut self, path: &str) -> &mut Self {
-        self.config_path = Some(path.into());
+        self.config.config_path = Some(path.into());
         self
     }
 }
@@ -59,18 +82,16 @@ impl Builder for FoundationdbBuilder {
     type Accessor = FoundationdbBackend;
 
     fn from_map(map: HashMap<String, String>) -> Self {
-        let mut builder = FoundationdbBuilder::default();
-
-        map.get("root").map(|v| builder.root(v));
-        map.get("config_path").map(|v| builder.config_path(v));
+        let config = FoundationConfig::deserialize(ConfigDeserializer::new(map))
+            .expect("config deserialize must succeed");
 
-        builder
+        Self { config }
     }
 
     fn build(&mut self) -> Result<Self::Accessor> {
         let _network = Arc::new(unsafe { foundationdb::boot() });
         let db;
-        if let Some(cfg_path) = &self.config_path {
+        if let Some(cfg_path) = &self.config.config_path {
             db = Database::from_path(cfg_path).map_err(|e| {
                 Error::new(ErrorKind::ConfigInvalid, "open foundation db")
                     .with_context("service", Scheme::Foundationdb)
@@ -87,7 +108,8 @@ impl Builder for FoundationdbBuilder {
         let db = Arc::new(db);
 
         let root = normalize_root(
-            self.root
+            self.config
+                .root
                 .clone()
                 .unwrap_or_else(|| "/".to_string())
                 .as_str(),
diff --git a/core/src/services/foundationdb/mod.rs b/core/src/services/foundationdb/mod.rs
index 1c63d12826..10d196dff7 100644
--- a/core/src/services/foundationdb/mod.rs
+++ b/core/src/services/foundationdb/mod.rs
@@ -17,4 +17,5 @@
 
 mod backend;
 
+pub use backend::FoundationConfig;
 pub use backend::FoundationdbBuilder as Foundationdb;
diff --git a/core/src/services/mod.rs b/core/src/services/mod.rs
index 1cdb39f01a..71cd71b808 100644
--- a/core/src/services/mod.rs
+++ b/core/src/services/mod.rs
@@ -269,6 +269,8 @@ pub use self::tikv::TikvConfig;
 #[cfg(feature = "services-foundationdb")]
 mod foundationdb;
 #[cfg(feature = "services-foundationdb")]
+pub use self::foundationdb::FoundationConfig;
+#[cfg(feature = "services-foundationdb")]
 pub use self::foundationdb::Foundationdb;
 
 #[cfg(feature = "services-postgresql")]