From 640df9199f67b30a333429bc505e1b25684b6898 Mon Sep 17 00:00:00 2001 From: WenyXu Date: Mon, 29 Apr 2024 06:57:27 +0000 Subject: [PATCH] refactor: remove scope.rs --- src/common/meta/src/key.rs | 27 +++++++- src/common/meta/src/key/flow.rs | 3 +- src/common/meta/src/key/flow/flow_info.rs | 5 +- src/common/meta/src/key/flow/flow_name.rs | 5 +- src/common/meta/src/key/flow/flownode_flow.rs | 5 +- src/common/meta/src/key/flow/table_flow.rs | 3 +- src/common/meta/src/key/scope.rs | 65 ------------------- 7 files changed, 36 insertions(+), 77 deletions(-) delete mode 100644 src/common/meta/src/key/scope.rs diff --git a/src/common/meta/src/key.rs b/src/common/meta/src/key.rs index f84e1e9b18ed..7e09b3dc33d7 100644 --- a/src/common/meta/src/key.rs +++ b/src/common/meta/src/key.rs @@ -83,7 +83,6 @@ pub mod datanode_table; #[allow(unused)] pub mod flow; pub mod schema_name; -pub mod scope; pub mod table_info; pub mod table_name; // TODO(weny): removes it. @@ -193,6 +192,32 @@ pub trait TableMetaKey { fn as_raw_key(&self) -> Vec; } +/// The key of metadata. +pub trait MetaKey { + fn to_bytes(&self) -> Vec; + + fn from_bytes(bytes: &[u8]) -> Result; +} + +#[derive(Debug, Clone, PartialEq)] +pub struct BytesAdapter(Vec); + +impl From> for BytesAdapter { + fn from(value: Vec) -> Self { + Self(value) + } +} + +impl MetaKey for BytesAdapter { + fn to_bytes(&self) -> Vec { + self.0.clone() + } + + fn from_bytes(bytes: &[u8]) -> Result { + Ok(BytesAdapter(bytes.to_vec())) + } +} + pub(crate) trait TableMetaKeyGetTxnOp { fn build_get_op( &self, diff --git a/src/common/meta/src/key/flow.rs b/src/common/meta/src/key/flow.rs index 648ae09aeeed..8d3660a42e51 100644 --- a/src/common/meta/src/key/flow.rs +++ b/src/common/meta/src/key/flow.rs @@ -30,9 +30,8 @@ use crate::key::flow::flow_info::FlowInfoManager; use crate::key::flow::flow_name::FlowNameManager; use crate::key::flow::flownode_flow::FlownodeFlowManager; use crate::key::flow::table_flow::TableFlowManager; -use crate::key::scope::MetaKey; use crate::key::txn_helper::TxnOpGetResponseSet; -use crate::key::FlowId; +use crate::key::{FlowId, MetaKey}; use crate::kv_backend::txn::Txn; use crate::kv_backend::KvBackendRef; diff --git a/src/common/meta/src/key/flow/flow_info.rs b/src/common/meta/src/key/flow/flow_info.rs index b3ae9c78dca6..359b0595c13c 100644 --- a/src/common/meta/src/key/flow/flow_info.rs +++ b/src/common/meta/src/key/flow/flow_info.rs @@ -22,9 +22,10 @@ use table::metadata::TableId; use crate::error::{self, Result}; use crate::key::flow::FlowScoped; -use crate::key::scope::MetaKey; use crate::key::txn_helper::TxnOpGetResponseSet; -use crate::key::{txn_helper, DeserializedValueWithBytes, FlowId, FlowPartitionId, TableMetaValue}; +use crate::key::{ + txn_helper, DeserializedValueWithBytes, FlowId, FlowPartitionId, MetaKey, TableMetaValue, +}; use crate::kv_backend::txn::Txn; use crate::kv_backend::KvBackendRef; use crate::table_name::TableName; diff --git a/src/common/meta/src/key/flow/flow_name.rs b/src/common/meta/src/key/flow/flow_name.rs index 5dc0a7454041..63af877d406e 100644 --- a/src/common/meta/src/key/flow/flow_name.rs +++ b/src/common/meta/src/key/flow/flow_name.rs @@ -20,9 +20,10 @@ use snafu::OptionExt; use crate::error::{self, Result}; use crate::key::flow::FlowScoped; -use crate::key::scope::MetaKey; use crate::key::txn_helper::TxnOpGetResponseSet; -use crate::key::{txn_helper, DeserializedValueWithBytes, FlowId, TableMetaValue, NAME_PATTERN}; +use crate::key::{ + txn_helper, DeserializedValueWithBytes, FlowId, MetaKey, TableMetaValue, NAME_PATTERN, +}; use crate::kv_backend::txn::Txn; use crate::kv_backend::KvBackendRef; diff --git a/src/common/meta/src/key/flow/flownode_flow.rs b/src/common/meta/src/key/flow/flownode_flow.rs index 2e0471cce052..d9ae8a215fb5 100644 --- a/src/common/meta/src/key/flow/flownode_flow.rs +++ b/src/common/meta/src/key/flow/flownode_flow.rs @@ -22,8 +22,7 @@ use snafu::OptionExt; use crate::error::{self, Result}; use crate::key::flow::FlowScoped; -use crate::key::scope::{BytesAdapter, MetaKey}; -use crate::key::{FlowId, FlowPartitionId}; +use crate::key::{BytesAdapter, FlowId, FlowPartitionId, MetaKey}; use crate::kv_backend::txn::{Txn, TxnOp}; use crate::kv_backend::KvBackendRef; use crate::range_stream::{PaginationStream, DEFAULT_PAGE_SIZE}; @@ -214,7 +213,7 @@ impl FlownodeFlowManager { #[cfg(test)] mod tests { use crate::key::flow::flownode_flow::FlownodeFlowKey; - use crate::key::scope::MetaKey; + use crate::key::MetaKey; #[test] fn test_key_serialization() { diff --git a/src/common/meta/src/key/flow/table_flow.rs b/src/common/meta/src/key/flow/table_flow.rs index bd6b44493108..f05866447823 100644 --- a/src/common/meta/src/key/flow/table_flow.rs +++ b/src/common/meta/src/key/flow/table_flow.rs @@ -22,8 +22,7 @@ use table::metadata::TableId; use crate::error::{self, Result}; use crate::key::flow::FlowScoped; -use crate::key::scope::{BytesAdapter, MetaKey}; -use crate::key::{FlowId, FlowPartitionId}; +use crate::key::{BytesAdapter, FlowId, FlowPartitionId, MetaKey}; use crate::kv_backend::txn::{Txn, TxnOp}; use crate::kv_backend::KvBackendRef; use crate::range_stream::{PaginationStream, DEFAULT_PAGE_SIZE}; diff --git a/src/common/meta/src/key/scope.rs b/src/common/meta/src/key/scope.rs deleted file mode 100644 index 7eed98fe1d50..000000000000 --- a/src/common/meta/src/key/scope.rs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2023 Greptime Team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::error::Result; - -/// The key of metadata. -pub trait MetaKey { - fn to_bytes(&self) -> Vec; - - fn from_bytes(bytes: &[u8]) -> Result; -} - -#[derive(Debug, Clone, PartialEq)] -pub struct BytesAdapter(Vec); - -impl From> for BytesAdapter { - fn from(value: Vec) -> Self { - Self(value) - } -} - -impl MetaKey for BytesAdapter { - fn to_bytes(&self) -> Vec { - self.0.clone() - } - - fn from_bytes(bytes: &[u8]) -> Result { - Ok(BytesAdapter(bytes.to_vec())) - } -} - -#[cfg(test)] -mod tests { - - use super::*; - use crate::error::Result; - - #[derive(Debug)] - struct MockKey { - inner: Vec, - } - - impl MetaKey for MockKey { - fn to_bytes(&self) -> Vec { - self.inner.clone() - } - - fn from_bytes(bytes: &[u8]) -> Result { - Ok(MockKey { - inner: bytes.to_vec(), - }) - } - } -}