diff --git a/Cargo.lock b/Cargo.lock index 8d6a25ec2c33..4a1598e321c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2852,7 +2852,6 @@ dependencies = [ "databend-common-meta-store", "databend-common-meta-types", "databend-common-proto-conv", - "databend-common-protos", "databend-common-storage", "enumflags2", "log", @@ -2877,7 +2876,6 @@ dependencies = [ "databend-common-meta-stoerr", "databend-common-meta-types", "databend-common-proto-conv", - "databend-common-protos", "enumflags2", "futures", "log", diff --git a/src/meta/api/src/id_generator.rs b/src/meta/api/src/id_generator.rs index 0c8e274a29bc..364dd8257de4 100644 --- a/src/meta/api/src/id_generator.rs +++ b/src/meta/api/src/id_generator.rs @@ -99,6 +99,8 @@ impl IdGenerator { impl kvapi::Key for IdGenerator { const PREFIX: &'static str = PREFIX_ID_GEN; + type ValueType = (); + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_raw(&self.resource) diff --git a/src/meta/api/src/schema_api_impl.rs b/src/meta/api/src/schema_api_impl.rs index e93ea3a848a1..4aeab9f5bf8c 100644 --- a/src/meta/api/src/schema_api_impl.rs +++ b/src/meta/api/src/schema_api_impl.rs @@ -1704,7 +1704,7 @@ impl + ?Sized> SchemaApi for KV { let db_meta = { let d = data.remove(0); - let (k, v) = deserialize_struct_get_response::(d)?; + let (k, v) = deserialize_struct_get_response::(d)?; assert_eq!(key_dbid, k); v.ok_or_else(|| { @@ -1744,7 +1744,7 @@ impl + ?Sized> SchemaApi for KV { let mut tb_id_list = { let d = data.remove(0); - let (k, v) = deserialize_struct_get_response::(d)?; + let (k, v) = deserialize_struct_get_response::(d)?; assert_eq!(key_table_id_list, k); v.unwrap_or_default() diff --git a/src/meta/api/src/util.rs b/src/meta/api/src/util.rs index e12e39bf6fe9..99f68fae3737 100644 --- a/src/meta/api/src/util.rs +++ b/src/meta/api/src/util.rs @@ -102,12 +102,13 @@ pub async fn get_u64_value( } } -pub fn deserialize_struct_get_response( +#[allow(clippy::type_complexity)] +pub fn deserialize_struct_get_response( resp: TxnGetResponse, -) -> Result<(K, Option>), MetaError> +) -> Result<(K, Option>), MetaError> where K: kvapi::Key, - T: FromToProto, + K::ValueType: FromToProto, { let key = K::from_str_key(&resp.key).map_err(|e| { let inv = InvalidReply::new( @@ -119,7 +120,7 @@ where if let Some(pb_seqv) = resp.value { let seqv = SeqV::from(pb_seqv); - let value = deserialize_struct::(&seqv.data)?; + let value = deserialize_struct::(&seqv.data)?; let seqv = SeqV::with_meta(seqv.seq, seqv.meta, value); Ok((key, Some(seqv))) } else { @@ -152,13 +153,13 @@ where K: kvapi::Key { /// Get value that are encoded with FromToProto. /// /// It returns seq number and the data. -pub async fn get_pb_value( +pub async fn get_pb_value( kv_api: &(impl kvapi::KVApi + ?Sized), k: &K, -) -> Result<(u64, Option), MetaError> +) -> Result<(u64, Option), MetaError> where K: kvapi::Key, - T: FromToProto, + K::ValueType: FromToProto, { let res = kv_api.get_kv(&k.to_string_key()).await?; diff --git a/src/meta/app/src/background/background_job.rs b/src/meta/app/src/background/background_job.rs index 950f6e97b9d4..c48150adce35 100644 --- a/src/meta/app/src/background/background_job.rs +++ b/src/meta/app/src/background/background_job.rs @@ -382,6 +382,8 @@ mod kvapi_key_impl { use crate::background::background_job::BackgroundJobId; use crate::background::background_job::BackgroundJobIdent; + use crate::background::BackgroundJobInfo; + const PREFIX_BACKGROUND_JOB: &str = "__fd_background_job"; const PREFIX_BACKGROUND_JOB_BY_ID: &str = "__fd_background_job_by_id"; @@ -389,6 +391,8 @@ mod kvapi_key_impl { impl kvapi::Key for BackgroundJobIdent { const PREFIX: &'static str = PREFIX_BACKGROUND_JOB; + type ValueType = BackgroundJobId; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_str(&self.tenant) @@ -410,6 +414,8 @@ mod kvapi_key_impl { impl kvapi::Key for BackgroundJobId { const PREFIX: &'static str = PREFIX_BACKGROUND_JOB_BY_ID; + type ValueType = BackgroundJobInfo; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.id) diff --git a/src/meta/app/src/background/background_task.rs b/src/meta/app/src/background/background_task.rs index eb753bf03fee..7a2df521e97a 100644 --- a/src/meta/app/src/background/background_task.rs +++ b/src/meta/app/src/background/background_task.rs @@ -219,6 +219,8 @@ mod kvapi_key_impl { use databend_common_meta_kvapi::kvapi; use crate::background::background_task::BackgroundTaskIdent; + use crate::background::BackgroundTaskInfo; + const PREFIX_BACKGROUND: &str = "__fd_background_task_by_name"; // task is named by id, and will not encounter renaming issue. @@ -226,6 +228,8 @@ mod kvapi_key_impl { impl kvapi::Key for BackgroundTaskIdent { const PREFIX: &'static str = PREFIX_BACKGROUND; + type ValueType = BackgroundTaskInfo; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_str(&self.tenant) diff --git a/src/meta/app/src/data_mask/mod.rs b/src/meta/app/src/data_mask/mod.rs index df256611e06d..83f64e87b921 100644 --- a/src/meta/app/src/data_mask/mod.rs +++ b/src/meta/app/src/data_mask/mod.rs @@ -131,11 +131,15 @@ mod kvapi_key_impl { use super::PREFIX_DATAMASK; use super::PREFIX_DATAMASK_BY_ID; use super::PREFIX_DATAMASK_ID_LIST; + use crate::data_mask::DatamaskMeta; + use crate::data_mask::MaskpolicyTableIdList; /// __fd_database// -> impl kvapi::Key for DatamaskNameIdent { const PREFIX: &'static str = PREFIX_DATAMASK; + type ValueType = DatamaskId; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_str(&self.tenant) @@ -158,6 +162,8 @@ mod kvapi_key_impl { impl kvapi::Key for DatamaskId { const PREFIX: &'static str = PREFIX_DATAMASK_BY_ID; + type ValueType = DatamaskMeta; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.id) @@ -177,6 +183,8 @@ mod kvapi_key_impl { impl kvapi::Key for MaskpolicyTableIdListKey { const PREFIX: &'static str = PREFIX_DATAMASK_ID_LIST; + type ValueType = MaskpolicyTableIdList; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_str(&self.tenant) diff --git a/src/meta/app/src/schema/catalog.rs b/src/meta/app/src/schema/catalog.rs index 5f306d05656c..3f86b86fa779 100644 --- a/src/meta/app/src/schema/catalog.rs +++ b/src/meta/app/src/schema/catalog.rs @@ -235,6 +235,7 @@ mod kvapi_key_impl { use super::CatalogId; use super::CatalogIdToName; use super::CatalogNameIdent; + use crate::schema::CatalogMeta; use crate::schema::PREFIX_CATALOG; use crate::schema::PREFIX_CATALOG_BY_ID; use crate::schema::PREFIX_CATALOG_ID_TO_NAME; @@ -243,6 +244,8 @@ mod kvapi_key_impl { impl kvapi::Key for CatalogNameIdent { const PREFIX: &'static str = PREFIX_CATALOG; + type ValueType = CatalogId; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_str(&self.tenant) @@ -268,6 +271,8 @@ mod kvapi_key_impl { impl kvapi::Key for CatalogId { const PREFIX: &'static str = PREFIX_CATALOG_BY_ID; + type ValueType = CatalogMeta; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.catalog_id) @@ -288,6 +293,8 @@ mod kvapi_key_impl { impl kvapi::Key for CatalogIdToName { const PREFIX: &'static str = PREFIX_CATALOG_ID_TO_NAME; + type ValueType = CatalogNameIdent; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.catalog_id) diff --git a/src/meta/app/src/schema/database.rs b/src/meta/app/src/schema/database.rs index 0df52f372902..ba11f1a09587 100644 --- a/src/meta/app/src/schema/database.rs +++ b/src/meta/app/src/schema/database.rs @@ -320,7 +320,9 @@ mod kvapi_key_impl { use crate::schema::DatabaseId; use crate::schema::DatabaseIdToName; + use crate::schema::DatabaseMeta; use crate::schema::DatabaseNameIdent; + use crate::schema::DbIdList; use crate::schema::DbIdListKey; use crate::schema::PREFIX_DATABASE; use crate::schema::PREFIX_DATABASE_BY_ID; @@ -331,6 +333,8 @@ mod kvapi_key_impl { impl kvapi::Key for DatabaseNameIdent { const PREFIX: &'static str = PREFIX_DATABASE; + type ValueType = DatabaseId; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_str(&self.tenant) @@ -353,6 +357,8 @@ mod kvapi_key_impl { impl kvapi::Key for DatabaseId { const PREFIX: &'static str = PREFIX_DATABASE_BY_ID; + type ValueType = DatabaseMeta; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.db_id) @@ -373,6 +379,8 @@ mod kvapi_key_impl { impl kvapi::Key for DatabaseIdToName { const PREFIX: &'static str = PREFIX_DATABASE_ID_TO_NAME; + type ValueType = DatabaseNameIdent; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.db_id) @@ -393,6 +401,8 @@ mod kvapi_key_impl { impl kvapi::Key for DbIdListKey { const PREFIX: &'static str = PREFIX_DB_ID_LIST; + type ValueType = DbIdList; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_str(&self.tenant) diff --git a/src/meta/app/src/schema/index.rs b/src/meta/app/src/schema/index.rs index 9947a8218575..606ea3828637 100644 --- a/src/meta/app/src/schema/index.rs +++ b/src/meta/app/src/schema/index.rs @@ -230,6 +230,7 @@ mod kvapi_key_impl { use crate::schema::IndexId; use crate::schema::IndexIdToName; + use crate::schema::IndexMeta; use crate::schema::IndexNameIdent; use crate::schema::PREFIX_INDEX; use crate::schema::PREFIX_INDEX_BY_ID; @@ -239,6 +240,8 @@ mod kvapi_key_impl { impl kvapi::Key for IndexNameIdent { const PREFIX: &'static str = PREFIX_INDEX; + type ValueType = IndexId; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_str(&self.tenant) @@ -261,6 +264,8 @@ mod kvapi_key_impl { impl kvapi::Key for IndexId { const PREFIX: &'static str = PREFIX_INDEX_BY_ID; + type ValueType = IndexMeta; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.index_id) @@ -281,6 +286,8 @@ mod kvapi_key_impl { impl kvapi::Key for IndexIdToName { const PREFIX: &'static str = PREFIX_INDEX_ID_TO_NAME; + type ValueType = IndexNameIdent; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.index_id) diff --git a/src/meta/app/src/schema/lock.rs b/src/meta/app/src/schema/lock.rs index 44551275466a..4f3f82e3cb71 100644 --- a/src/meta/app/src/schema/lock.rs +++ b/src/meta/app/src/schema/lock.rs @@ -102,7 +102,7 @@ impl LockKey { } } - pub fn gen_key(&self, revision: u64) -> impl Key { + pub fn gen_key(&self, revision: u64) -> TableLockKey { match self { LockKey::Table { table_id } => TableLockKey { table_id: *table_id, @@ -181,6 +181,7 @@ pub struct TableLockKey { mod kvapi_key_impl { use databend_common_meta_kvapi::kvapi; + use crate::schema::LockMeta; use crate::schema::TableLockKey; use crate::schema::PREFIX_TABLE_LOCK; @@ -188,6 +189,8 @@ mod kvapi_key_impl { impl kvapi::Key for TableLockKey { const PREFIX: &'static str = PREFIX_TABLE_LOCK; + type ValueType = LockMeta; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.table_id) diff --git a/src/meta/app/src/schema/mod.rs b/src/meta/app/src/schema/mod.rs index 95ef5f105837..03b3c687c4d4 100644 --- a/src/meta/app/src/schema/mod.rs +++ b/src/meta/app/src/schema/mod.rs @@ -86,7 +86,6 @@ pub use table::SetTableColumnMaskPolicyAction; pub use table::SetTableColumnMaskPolicyReply; pub use table::SetTableColumnMaskPolicyReq; pub use table::TableCopiedFileInfo; -pub use table::TableCopiedFileLockKey; pub use table::TableCopiedFileNameIdent; pub use table::TableId; pub use table::TableIdList; @@ -134,7 +133,6 @@ const PREFIX_TABLE_ID_LIST: &str = "__fd_table_id_list"; const PREFIX_TABLE_COUNT: &str = "__fd_table_count"; const PREFIX_TABLE_ID_TO_NAME: &str = "__fd_table_id_to_name"; const PREFIX_TABLE_COPIED_FILES: &str = "__fd_table_copied_files"; -const PREFIX_TABLE_COPIED_FILES_LOCK: &str = "__fd_table_copied_file_lock"; const PREFIX_INDEX: &str = "__fd_index"; const PREFIX_INDEX_ID_TO_NAME: &str = "__fd_index_id_to_name"; const PREFIX_INDEX_BY_ID: &str = "__fd_index_by_id"; diff --git a/src/meta/app/src/schema/table.rs b/src/meta/app/src/schema/table.rs index adca0f0df293..03f94259036f 100644 --- a/src/meta/app/src/schema/table.rs +++ b/src/meta/app/src/schema/table.rs @@ -863,29 +863,27 @@ pub struct TruncateTableReq { #[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)] pub struct TruncateTableReply {} -#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)] -pub struct TableCopiedFileLockKey { - pub table_id: u64, -} - #[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)] pub struct EmptyProto {} mod kvapi_key_impl { use databend_common_meta_kvapi::kvapi; + use crate::primitive::Id; use crate::schema::CountTablesKey; use crate::schema::DBIdTableName; + use crate::schema::LeastVisibleTime; use crate::schema::LeastVisibleTimeKey; - use crate::schema::TableCopiedFileLockKey; + use crate::schema::TableCopiedFileInfo; use crate::schema::TableCopiedFileNameIdent; use crate::schema::TableId; + use crate::schema::TableIdList; use crate::schema::TableIdListKey; use crate::schema::TableIdToName; + use crate::schema::TableMeta; use crate::schema::PREFIX_TABLE; use crate::schema::PREFIX_TABLE_BY_ID; use crate::schema::PREFIX_TABLE_COPIED_FILES; - use crate::schema::PREFIX_TABLE_COPIED_FILES_LOCK; use crate::schema::PREFIX_TABLE_COUNT; use crate::schema::PREFIX_TABLE_ID_LIST; use crate::schema::PREFIX_TABLE_ID_TO_NAME; @@ -895,6 +893,8 @@ mod kvapi_key_impl { impl kvapi::Key for DBIdTableName { const PREFIX: &'static str = PREFIX_TABLE; + type ValueType = TableId; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.db_id) @@ -917,6 +917,8 @@ mod kvapi_key_impl { impl kvapi::Key for TableIdToName { const PREFIX: &'static str = PREFIX_TABLE_ID_TO_NAME; + type ValueType = DBIdTableName; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.table_id) @@ -937,6 +939,8 @@ mod kvapi_key_impl { impl kvapi::Key for TableId { const PREFIX: &'static str = PREFIX_TABLE_BY_ID; + type ValueType = TableMeta; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.table_id) @@ -957,6 +961,8 @@ mod kvapi_key_impl { impl kvapi::Key for TableIdListKey { const PREFIX: &'static str = PREFIX_TABLE_ID_LIST; + type ValueType = TableIdList; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.db_id) @@ -979,6 +985,8 @@ mod kvapi_key_impl { impl kvapi::Key for CountTablesKey { const PREFIX: &'static str = PREFIX_TABLE_COUNT; + type ValueType = Id; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_raw(&self.tenant) @@ -999,6 +1007,8 @@ mod kvapi_key_impl { impl kvapi::Key for TableCopiedFileNameIdent { const PREFIX: &'static str = PREFIX_TABLE_COPIED_FILES; + type ValueType = TableCopiedFileInfo; + fn to_string_key(&self) -> String { // TODO: file is not escaped!!! // There already are non escaped data stored on disk. @@ -1019,30 +1029,12 @@ mod kvapi_key_impl { } } - /// __fd_table_copied_file_lock/table_id -> "" - impl kvapi::Key for TableCopiedFileLockKey { - const PREFIX: &'static str = PREFIX_TABLE_COPIED_FILES_LOCK; - - fn to_string_key(&self) -> String { - kvapi::KeyBuilder::new_prefixed(Self::PREFIX) - .push_u64(self.table_id) - .done() - } - - fn from_str_key(s: &str) -> Result { - let mut p = kvapi::KeyParser::new_prefixed(s, Self::PREFIX)?; - - let table_id = p.next_u64()?; - p.done()?; - - Ok(TableCopiedFileLockKey { table_id }) - } - } - /// "__fd_table_lvt/table_id" impl kvapi::Key for LeastVisibleTimeKey { const PREFIX: &'static str = PREFIX_TABLE_LVT; + type ValueType = LeastVisibleTime; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.table_id) diff --git a/src/meta/app/src/schema/virtual_column.rs b/src/meta/app/src/schema/virtual_column.rs index f4dda52d65f1..79ca0b93a2e7 100644 --- a/src/meta/app/src/schema/virtual_column.rs +++ b/src/meta/app/src/schema/virtual_column.rs @@ -127,6 +127,7 @@ impl ListVirtualColumnsReq { mod kvapi_key_impl { use databend_common_meta_kvapi::kvapi; + use crate::schema::VirtualColumnMeta; use crate::schema::VirtualColumnNameIdent; use crate::schema::PREFIX_VIRTUAL_COLUMN; @@ -134,6 +135,8 @@ mod kvapi_key_impl { impl kvapi::Key for VirtualColumnNameIdent { const PREFIX: &'static str = PREFIX_VIRTUAL_COLUMN; + type ValueType = VirtualColumnMeta; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_str(&self.tenant) diff --git a/src/meta/app/src/share/share.rs b/src/meta/app/src/share/share.rs index 4fab40b9e306..526c648be852 100644 --- a/src/meta/app/src/share/share.rs +++ b/src/meta/app/src/share/share.rs @@ -749,12 +749,16 @@ mod kvapi_key_impl { use databend_common_meta_kvapi::kvapi; use super::ShareEndpointId; + use crate::share::ObjectSharedByShareIds; + use crate::share::ShareAccountMeta; use crate::share::ShareAccountNameIdent; use crate::share::ShareEndpointIdToName; use crate::share::ShareEndpointIdent; + use crate::share::ShareEndpointMeta; use crate::share::ShareGrantObject; use crate::share::ShareId; use crate::share::ShareIdToName; + use crate::share::ShareMeta; use crate::share::ShareNameIdent; const PREFIX_SHARE: &str = "__fd_share"; @@ -770,6 +774,8 @@ mod kvapi_key_impl { impl kvapi::Key for ShareGrantObject { const PREFIX: &'static str = PREFIX_SHARE_BY; + type ValueType = ObjectSharedByShareIds; + fn to_string_key(&self) -> String { match *self { ShareGrantObject::Database(db_id) => kvapi::KeyBuilder::new_prefixed(Self::PREFIX) @@ -808,6 +814,8 @@ mod kvapi_key_impl { impl kvapi::Key for ShareNameIdent { const PREFIX: &'static str = PREFIX_SHARE; + type ValueType = ShareId; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_str(&self.tenant) @@ -830,6 +838,8 @@ mod kvapi_key_impl { impl kvapi::Key for ShareId { const PREFIX: &'static str = PREFIX_SHARE_ID; + type ValueType = ShareMeta; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.share_id) @@ -850,6 +860,8 @@ mod kvapi_key_impl { impl kvapi::Key for ShareAccountNameIdent { const PREFIX: &'static str = PREFIX_SHARE_ACCOUNT_ID; + type ValueType = ShareAccountMeta; + fn to_string_key(&self) -> String { if self.share_id != 0 { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) @@ -878,6 +890,8 @@ mod kvapi_key_impl { impl kvapi::Key for ShareIdToName { const PREFIX: &'static str = PREFIX_SHARE_ID_TO_NAME; + type ValueType = ShareNameIdent; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.share_id) @@ -898,6 +912,8 @@ mod kvapi_key_impl { impl kvapi::Key for ShareEndpointIdent { const PREFIX: &'static str = PREFIX_SHARE_ENDPOINT; + type ValueType = ShareEndpointId; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_str(&self.tenant) @@ -920,6 +936,8 @@ mod kvapi_key_impl { impl kvapi::Key for ShareEndpointId { const PREFIX: &'static str = PREFIX_SHARE_ENDPOINT_ID; + type ValueType = ShareEndpointMeta; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.share_endpoint_id) @@ -940,6 +958,8 @@ mod kvapi_key_impl { impl kvapi::Key for ShareEndpointIdToName { const PREFIX: &'static str = PREFIX_SHARE_ENDPOINT_ID_TO_NAME; + type ValueType = ShareEndpointIdent; + fn to_string_key(&self) -> String { kvapi::KeyBuilder::new_prefixed(Self::PREFIX) .push_u64(self.share_endpoint_id) diff --git a/src/meta/kvapi/src/kvapi/key.rs b/src/meta/kvapi/src/kvapi/key.rs index 660888c63d43..175486cb556e 100644 --- a/src/meta/kvapi/src/kvapi/key.rs +++ b/src/meta/kvapi/src/kvapi/key.rs @@ -14,6 +14,7 @@ //! Defines kvapi::KVApi key behaviors. +use std::convert::Infallible; use std::fmt::Debug; use std::string::FromUtf8Error; @@ -50,6 +51,8 @@ where Self: Sized { const PREFIX: &'static str; + type ValueType; + /// Encode structured key into a string. fn to_string_key(&self) -> String; @@ -60,6 +63,9 @@ where Self: Sized impl kvapi::Key for String { const PREFIX: &'static str = ""; + /// For a non structured key, the value type can never be used. + type ValueType = Infallible; + fn to_string_key(&self) -> String { self.clone() } diff --git a/src/query/management/src/serde/pb_serde.rs b/src/query/management/src/serde/pb_serde.rs index 27b16797b283..94a97f65cb14 100644 --- a/src/query/management/src/serde/pb_serde.rs +++ b/src/query/management/src/serde/pb_serde.rs @@ -60,15 +60,15 @@ where Ok(v) } -pub async fn check_and_upgrade_to_pb<'a, T, ErrFn, CtxFn, D>( +pub async fn check_and_upgrade_to_pb( key: String, - seq_value: &'a SeqV, + seq_value: &SeqV, kv_api: Arc + Send + Sync>, err_code_fn: ErrFn, context_fn: CtxFn, ) -> std::result::Result, ErrorCode> where - T: FromToProto + serde::de::DeserializeOwned + 'a + 'static, + T: FromToProto + serde::de::DeserializeOwned + 'static, ErrFn: FnOnce(String) -> ErrorCode + Copy, D: Display, CtxFn: FnOnce() -> D + Copy,