From 39fe5b3287a5929219e87f48f318fda61562aa2c Mon Sep 17 00:00:00 2001 From: zwang28 <70626450+zwang28@users.noreply.github.com> Date: Mon, 28 Nov 2022 18:55:40 +0800 Subject: [PATCH] refactor(meta_store): include keys in snapshot list response (#6632) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- src/meta/src/storage/etcd_meta_store.rs | 12 ++++++++---- src/meta/src/storage/mem_meta_store.rs | 4 ++-- src/meta/src/storage/meta_store.rs | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/meta/src/storage/etcd_meta_store.rs b/src/meta/src/storage/etcd_meta_store.rs index 51b2e87763d79..ba93a10af3048 100644 --- a/src/meta/src/storage/etcd_meta_store.rs +++ b/src/meta/src/storage/etcd_meta_store.rs @@ -122,7 +122,7 @@ struct ListViewer { } impl SnapshotViewer for ListViewer { - type Output = Vec>; + type Output = Vec<(Vec, Vec)>; type OutputFuture<'a> = impl Future> + 'a; @@ -141,15 +141,19 @@ impl SnapshotViewer for ListViewer { "Etcd response missing header" ))); }; - let value = res.kvs().iter().map(|kv| kv.value().to_vec()).collect(); - Ok((new_revision, value)) + let kv = res + .kvs() + .iter() + .map(|kv| (kv.key().to_vec(), kv.value().to_vec())) + .collect(); + Ok((new_revision, kv)) } } } #[async_trait] impl Snapshot for EtcdSnapshot { - async fn list_cf(&self, cf: &str) -> MetaStoreResult>> { + async fn list_cf(&self, cf: &str) -> MetaStoreResult, Vec)>> { let view = ListViewer { key: encode_etcd_key(cf, &[]), }; diff --git a/src/meta/src/storage/mem_meta_store.rs b/src/meta/src/storage/mem_meta_store.rs index 61553241d3916..86d943a9a13f2 100644 --- a/src/meta/src/storage/mem_meta_store.rs +++ b/src/meta/src/storage/mem_meta_store.rs @@ -51,9 +51,9 @@ impl MemStoreInner { #[async_trait] impl Snapshot for MemSnapshot { #[inline(always)] - async fn list_cf(&self, cf: &str) -> MetaStoreResult> { + async fn list_cf(&self, cf: &str) -> MetaStoreResult> { Ok(match self.0.cf_ref(cf) { - Some(cf) => cf.values().cloned().collect(), + Some(cf) => cf.iter().map(|(k, v)| (k.clone(), v.clone())).collect(), None => vec![], }) } diff --git a/src/meta/src/storage/meta_store.rs b/src/meta/src/storage/meta_store.rs index 06d0abd5c83ca..d498e17c8b6bb 100644 --- a/src/meta/src/storage/meta_store.rs +++ b/src/meta/src/storage/meta_store.rs @@ -22,7 +22,7 @@ pub const DEFAULT_COLUMN_FAMILY: &str = "default"; #[async_trait] pub trait Snapshot: Sync + Send + 'static { - async fn list_cf(&self, cf: &str) -> MetaStoreResult>>; + async fn list_cf(&self, cf: &str) -> MetaStoreResult, Vec)>>; async fn get_cf(&self, cf: &str, key: &[u8]) -> MetaStoreResult>; } @@ -38,7 +38,8 @@ pub trait MetaStore: Clone + Sync + Send + 'static { async fn txn(&self, trx: Transaction) -> MetaStoreResult<()>; async fn list_cf(&self, cf: &str) -> MetaStoreResult>> { - self.snapshot().await.list_cf(cf).await + let kvs = self.snapshot().await.list_cf(cf).await?; + Ok(kvs.into_iter().map(|(_k, v)| v).collect()) } async fn get_cf(&self, cf: &str, key: &[u8]) -> MetaStoreResult> {