From c52efb04531a4d685aa2019a9a480f6be5cbdf3e Mon Sep 17 00:00:00 2001 From: koushiro Date: Thu, 31 Oct 2024 19:46:26 +0800 Subject: [PATCH] chore(core/raw): align info method of kv::Adapter and typed_kv::Adapter --- core/src/raw/adapters/kv/api.rs | 21 +++++---------------- core/src/raw/adapters/kv/backend.rs | 7 +++++-- core/src/raw/adapters/kv/mod.rs | 2 +- core/src/raw/adapters/typed_kv/api.rs | 2 +- core/src/services/atomicserver/backend.rs | 4 ++-- core/src/services/cacache/backend.rs | 4 ++-- core/src/services/cloudflare_kv/backend.rs | 4 ++-- core/src/services/d1/backend.rs | 4 ++-- core/src/services/etcd/backend.rs | 4 ++-- core/src/services/foundationdb/backend.rs | 4 ++-- core/src/services/gridfs/backend.rs | 4 ++-- core/src/services/libsql/backend.rs | 4 ++-- core/src/services/memcached/backend.rs | 4 ++-- core/src/services/mongodb/backend.rs | 4 ++-- core/src/services/mysql/backend.rs | 4 ++-- core/src/services/nebula_graph/backend.rs | 4 ++-- core/src/services/persy/backend.rs | 4 ++-- core/src/services/postgresql/backend.rs | 4 ++-- core/src/services/redb/backend.rs | 4 ++-- core/src/services/redis/backend.rs | 4 ++-- core/src/services/rocksdb/backend.rs | 4 ++-- core/src/services/sled/backend.rs | 4 ++-- core/src/services/sqlite/backend.rs | 4 ++-- core/src/services/surrealdb/backend.rs | 4 ++-- core/src/services/tikv/backend.rs | 4 ++-- 25 files changed, 54 insertions(+), 62 deletions(-) diff --git a/core/src/raw/adapters/kv/api.rs b/core/src/raw/adapters/kv/api.rs index acf449d58bdc..e68ff1b6f4eb 100644 --- a/core/src/raw/adapters/kv/api.rs +++ b/core/src/raw/adapters/kv/api.rs @@ -29,8 +29,8 @@ use crate::*; /// /// By implement this trait, any kv service can work as an OpenDAL Service. pub trait Adapter: Send + Sync + Debug + Unpin + 'static { - /// Return the metadata of this key value accessor. - fn metadata(&self) -> Metadata; + /// Return the info of this key value accessor. + fn info(&self) -> Info; /// Get a key from service. /// @@ -129,14 +129,14 @@ pub trait Adapter: Send + Sync + Debug + Unpin + 'static { } } -/// Metadata for this key value accessor. -pub struct Metadata { +/// Info for this key value accessor. +pub struct Info { scheme: Scheme, name: String, capabilities: Capability, } -impl Metadata { +impl Info { /// Create a new KeyValueAccessorInfo. pub fn new(scheme: Scheme, name: &str, capabilities: Capability) -> Self { Self { @@ -161,14 +161,3 @@ impl Metadata { self.capabilities } } - -impl From for AccessorInfo { - fn from(m: Metadata) -> AccessorInfo { - let mut am = AccessorInfo::default(); - am.set_name(m.name()); - am.set_scheme(m.scheme()); - am.set_native_capability(m.capabilities()); - - am - } -} diff --git a/core/src/raw/adapters/kv/backend.rs b/core/src/raw/adapters/kv/backend.rs index 3a7ea3525d94..b21973ebd49c 100644 --- a/core/src/raw/adapters/kv/backend.rs +++ b/core/src/raw/adapters/kv/backend.rs @@ -72,10 +72,13 @@ impl Access for Backend { type BlockingLister = HierarchyLister; fn info(&self) -> Arc { - let mut am: AccessorInfo = self.kv.metadata().into(); + let kv_info = self.kv.info(); + let mut am: AccessorInfo = AccessorInfo::default(); am.set_root(&self.root); + am.set_scheme(kv_info.scheme()); + am.set_name(kv_info.name()); - let mut cap = am.native_capability(); + let mut cap = kv_info.capabilities(); if cap.read { cap.stat = true; } diff --git a/core/src/raw/adapters/kv/mod.rs b/core/src/raw/adapters/kv/mod.rs index facb6efe1c59..db4d07fce952 100644 --- a/core/src/raw/adapters/kv/mod.rs +++ b/core/src/raw/adapters/kv/mod.rs @@ -21,7 +21,7 @@ mod api; pub use api::Adapter; -pub use api::Metadata; +pub use api::Info; mod backend; pub use backend::Backend; diff --git a/core/src/raw/adapters/typed_kv/api.rs b/core/src/raw/adapters/typed_kv/api.rs index 0fecb9d01299..f1e4a95fc47a 100644 --- a/core/src/raw/adapters/typed_kv/api.rs +++ b/core/src/raw/adapters/typed_kv/api.rs @@ -45,7 +45,7 @@ use crate::Scheme; /// Ideally, we should use `typed_kv::Adapter` instead of `kv::Adapter` for /// in-memory rust libs like moka and dashmap. pub trait Adapter: Send + Sync + Debug + Unpin + 'static { - /// Get the scheme and name of current adapter. + /// Return the info of this key value accessor. fn info(&self) -> Info; /// Get a value from adapter. diff --git a/core/src/services/atomicserver/backend.rs b/core/src/services/atomicserver/backend.rs index ac5655bead01..8390e66a7ba2 100644 --- a/core/src/services/atomicserver/backend.rs +++ b/core/src/services/atomicserver/backend.rs @@ -351,8 +351,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Atomicserver, "atomicserver", Capability { diff --git a/core/src/services/cacache/backend.rs b/core/src/services/cacache/backend.rs index 85914d864fd1..88f2100de788 100644 --- a/core/src/services/cacache/backend.rs +++ b/core/src/services/cacache/backend.rs @@ -85,8 +85,8 @@ impl Debug for Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Cacache, &self.datadir, Capability { diff --git a/core/src/services/cloudflare_kv/backend.rs b/core/src/services/cloudflare_kv/backend.rs index 6a15187c3fa1..fe4de273ab25 100644 --- a/core/src/services/cloudflare_kv/backend.rs +++ b/core/src/services/cloudflare_kv/backend.rs @@ -181,8 +181,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::CloudflareKv, &self.namespace_id, Capability { diff --git a/core/src/services/d1/backend.rs b/core/src/services/d1/backend.rs index f50fd6747425..d51c00bcb5dc 100644 --- a/core/src/services/d1/backend.rs +++ b/core/src/services/d1/backend.rs @@ -258,8 +258,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::D1, &self.table, Capability { diff --git a/core/src/services/etcd/backend.rs b/core/src/services/etcd/backend.rs index 103e7c7abb6b..272f0702e16d 100644 --- a/core/src/services/etcd/backend.rs +++ b/core/src/services/etcd/backend.rs @@ -271,8 +271,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Etcd, &self.endpoints.join(","), Capability { diff --git a/core/src/services/foundationdb/backend.rs b/core/src/services/foundationdb/backend.rs index 4d4adfa52fd2..1a5e82b45e17 100644 --- a/core/src/services/foundationdb/backend.rs +++ b/core/src/services/foundationdb/backend.rs @@ -110,8 +110,8 @@ impl Debug for Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Foundationdb, "foundationdb", Capability { diff --git a/core/src/services/gridfs/backend.rs b/core/src/services/gridfs/backend.rs index db2bf34456ed..4eb00bf58a41 100644 --- a/core/src/services/gridfs/backend.rs +++ b/core/src/services/gridfs/backend.rs @@ -212,8 +212,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Gridfs, &format!("{}/{}", self.database, self.bucket), Capability { diff --git a/core/src/services/libsql/backend.rs b/core/src/services/libsql/backend.rs index ff7b9551e6a8..ae7ac3fdf8e5 100644 --- a/core/src/services/libsql/backend.rs +++ b/core/src/services/libsql/backend.rs @@ -305,8 +305,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Libsql, &self.table, Capability { diff --git a/core/src/services/memcached/backend.rs b/core/src/services/memcached/backend.rs index c89b81ba704a..93dfc97ced0b 100644 --- a/core/src/services/memcached/backend.rs +++ b/core/src/services/memcached/backend.rs @@ -197,8 +197,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Memcached, "memcached", Capability { diff --git a/core/src/services/mongodb/backend.rs b/core/src/services/mongodb/backend.rs index 24abe6fb03ef..fb528a09f28c 100644 --- a/core/src/services/mongodb/backend.rs +++ b/core/src/services/mongodb/backend.rs @@ -226,8 +226,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Mongodb, &format!("{}/{}", self.database, self.collection), Capability { diff --git a/core/src/services/mysql/backend.rs b/core/src/services/mysql/backend.rs index 0b1481ef01ce..e92248d2f45d 100644 --- a/core/src/services/mysql/backend.rs +++ b/core/src/services/mysql/backend.rs @@ -188,8 +188,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Mysql, &self.table, Capability { diff --git a/core/src/services/nebula_graph/backend.rs b/core/src/services/nebula_graph/backend.rs index d03dd5bf2b13..7e3f6d333867 100644 --- a/core/src/services/nebula_graph/backend.rs +++ b/core/src/services/nebula_graph/backend.rs @@ -269,8 +269,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::NebulaGraph, &self.session_config.space.clone().unwrap(), Capability { diff --git a/core/src/services/persy/backend.rs b/core/src/services/persy/backend.rs index 10b48db08137..dd32125546e7 100644 --- a/core/src/services/persy/backend.rs +++ b/core/src/services/persy/backend.rs @@ -152,8 +152,8 @@ impl Debug for Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Persy, &self.datafile, Capability { diff --git a/core/src/services/postgresql/backend.rs b/core/src/services/postgresql/backend.rs index 8b4ea56eb223..03066e310e07 100644 --- a/core/src/services/postgresql/backend.rs +++ b/core/src/services/postgresql/backend.rs @@ -187,8 +187,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Postgresql, &self.table, Capability { diff --git a/core/src/services/redb/backend.rs b/core/src/services/redb/backend.rs index d6dc290e758e..2d8774a2c23b 100644 --- a/core/src/services/redb/backend.rs +++ b/core/src/services/redb/backend.rs @@ -111,8 +111,8 @@ impl Debug for Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Redb, &self.datadir, Capability { diff --git a/core/src/services/redis/backend.rs b/core/src/services/redis/backend.rs index bf8cff201856..4726c1a34295 100644 --- a/core/src/services/redis/backend.rs +++ b/core/src/services/redis/backend.rs @@ -327,8 +327,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Redis, self.addr.as_str(), Capability { diff --git a/core/src/services/rocksdb/backend.rs b/core/src/services/rocksdb/backend.rs index 5ed0f38ec6bc..3b0b09d4f8de 100644 --- a/core/src/services/rocksdb/backend.rs +++ b/core/src/services/rocksdb/backend.rs @@ -108,8 +108,8 @@ impl Debug for Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Rocksdb, &self.db.path().to_string_lossy(), Capability { diff --git a/core/src/services/sled/backend.rs b/core/src/services/sled/backend.rs index d1d1e7f18453..3b45f3fb29cb 100644 --- a/core/src/services/sled/backend.rs +++ b/core/src/services/sled/backend.rs @@ -137,8 +137,8 @@ impl Debug for Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Sled, &self.datadir, Capability { diff --git a/core/src/services/sqlite/backend.rs b/core/src/services/sqlite/backend.rs index 0b5c556f8cb3..d15f3c1dc8c8 100644 --- a/core/src/services/sqlite/backend.rs +++ b/core/src/services/sqlite/backend.rs @@ -189,8 +189,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Sqlite, &self.table, Capability { diff --git a/core/src/services/surrealdb/backend.rs b/core/src/services/surrealdb/backend.rs index a7c098a0ad8e..812cfea32c28 100644 --- a/core/src/services/surrealdb/backend.rs +++ b/core/src/services/surrealdb/backend.rs @@ -283,8 +283,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Surrealdb, &self.table, Capability { diff --git a/core/src/services/tikv/backend.rs b/core/src/services/tikv/backend.rs index 6f23f156ee70..05e37a8e28bb 100644 --- a/core/src/services/tikv/backend.rs +++ b/core/src/services/tikv/backend.rs @@ -185,8 +185,8 @@ impl Adapter { } impl kv::Adapter for Adapter { - fn metadata(&self) -> kv::Metadata { - kv::Metadata::new( + fn info(&self) -> kv::Info { + kv::Info::new( Scheme::Tikv, "TiKV", Capability {