Skip to content

Commit

Permalink
chore(core/raw): align info method of kv::Adapter and `typed_kv::…
Browse files Browse the repository at this point in the history
…Adapter` (#5259)
  • Loading branch information
koushiro authored Nov 5, 2024
1 parent 259a19e commit f93c619
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 64 deletions.
4 changes: 2 additions & 2 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 5 additions & 16 deletions core/src/raw/adapters/kv/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ pub trait Adapter: Send + Sync + Debug + Unpin + 'static {
/// TODO: use default associate type `= ()` after stablized
type Scanner: Scan;

/// 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.
///
Expand Down Expand Up @@ -196,14 +196,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 {
Expand All @@ -228,14 +228,3 @@ impl Metadata {
self.capabilities
}
}

impl From<Metadata> 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
}
}
7 changes: 5 additions & 2 deletions core/src/raw/adapters/kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ impl<S: Adapter> Access for Backend<S> {
type BlockingLister = HierarchyLister<BlockingKvLister>;

fn info(&self) -> Arc<AccessorInfo> {
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;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/raw/adapters/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
mod api;
pub use api::Adapter;
pub use api::Metadata;
pub use api::Info;
pub use api::Scan;
#[cfg(any(
feature = "services-cloudflare-kv",
Expand Down
2 changes: 1 addition & 1 deletion core/src/raw/adapters/typed_kv/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/atomicserver/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Atomicserver,
"atomicserver",
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/cacache/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ impl Debug for Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Cacache,
&self.datadir,
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/cloudflare_kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = kv::Scanner;

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::CloudflareKv,
&self.namespace_id,
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/d1/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::D1,
&self.table,
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/etcd/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = kv::ScanStdIter<vec::IntoIter<Result<String>>>;

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Etcd,
&self.endpoints.join(","),
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/foundationdb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ impl Debug for Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Foundationdb,
"foundationdb",
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/gridfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Gridfs,
&format!("{}/{}", self.database, self.bucket),
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/libsql/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Libsql,
&self.table,
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/memcached/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Memcached,
"memcached",
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/mongodb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Mongodb,
&format!("{}/{}", self.database, self.collection),
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/mysql/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Mysql,
&self.table,
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/nebula_graph/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = kv::ScanStdIter<vec::IntoIter<Result<String>>>;

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 {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/persy/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ impl Debug for Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Persy,
&self.datafile,
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/postgresql/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Postgresql,
&self.table,
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/redb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ impl Debug for Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Redb,
&self.datadir,
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/redis/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Redis,
self.addr.as_str(),
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/rocksdb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ impl Debug for Adapter {
impl kv::Adapter for Adapter {
type Scanner = kv::Scanner;

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 {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/sled/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl Debug for Adapter {
impl kv::Adapter for Adapter {
type Scanner = kv::Scanner;

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Sled,
&self.datadir,
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/sqlite/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ impl kv::Scan for SqliteScanner {
impl kv::Adapter for Adapter {
type Scanner = SqliteScanner;

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Sqlite,
&self.table,
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/surrealdb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Surrealdb,
&self.table,
Capability {
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/tikv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ impl Adapter {
impl kv::Adapter for Adapter {
type Scanner = ();

fn metadata(&self) -> kv::Metadata {
kv::Metadata::new(
fn info(&self) -> kv::Info {
kv::Info::new(
Scheme::Tikv,
"TiKV",
Capability {
Expand Down

0 comments on commit f93c619

Please sign in to comment.