diff --git a/src/common/meta/src/ddl.rs b/src/common/meta/src/ddl.rs index d915829441d8..b353372b7031 100644 --- a/src/common/meta/src/ddl.rs +++ b/src/common/meta/src/ddl.rs @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::collections::HashMap; use std::sync::Arc; use api::v1::meta::Partition; use common_telemetry::tracing_context::W3cTrace; -use store_api::storage::TableId; +use store_api::storage::{RegionNumber, TableId}; use table::metadata::RawTableInfo; use crate::cache_invalidator::CacheInvalidatorRef; @@ -26,7 +27,7 @@ use crate::key::TableMetadataManagerRef; use crate::region_keeper::MemoryRegionKeeperRef; use crate::rpc::ddl::{SubmitDdlTaskRequest, SubmitDdlTaskResponse}; use crate::rpc::router::RegionRoute; -use crate::wal::WalOptionsMap; +use crate::wal::WalOptions; pub mod alter_table; pub mod create_table; @@ -58,7 +59,7 @@ pub struct TableMetadataAllocatorContext { pub struct TableMetadata { pub table_id: TableId, pub region_routes: Vec, - pub region_wal_options_map: WalOptionsMap, + pub wal_options_map: HashMap, } #[async_trait::async_trait] diff --git a/src/common/meta/src/ddl/create_table.rs b/src/common/meta/src/ddl/create_table.rs index 7611f5cda2f8..bf8a22e09b10 100644 --- a/src/common/meta/src/ddl/create_table.rs +++ b/src/common/meta/src/ddl/create_table.rs @@ -45,7 +45,7 @@ use crate::rpc::ddl::CreateTableTask; use crate::rpc::router::{ find_leader_regions, find_leaders, operating_leader_regions, RegionRoute, }; -use crate::wal::{EncodedWalOptions, WalOptionsMap}; +use crate::wal::{EncodedWalOptions, WalOptions}; pub struct CreateTableProcedure { pub context: DdlContext, @@ -59,12 +59,12 @@ impl CreateTableProcedure { cluster_id: u64, task: CreateTableTask, region_routes: Vec, - region_wal_options_map: WalOptionsMap, + wal_options_map: HashMap, context: DdlContext, ) -> Self { Self { context, - creator: TableCreator::new(cluster_id, task, region_routes, region_wal_options_map), + creator: TableCreator::new(cluster_id, task, region_routes, wal_options_map), } } @@ -96,8 +96,8 @@ impl CreateTableProcedure { &self.creator.data.region_routes } - pub fn region_wal_options_map(&self) -> &HashMap { - &self.creator.data.region_wal_options_map + pub fn wal_options_map(&self) -> &HashMap { + &self.creator.data.wal_options_map } /// Checks whether the table exists. @@ -197,7 +197,7 @@ impl CreateTableProcedure { let create_table_data = &self.creator.data; let region_routes = &create_table_data.region_routes; - let region_wal_options_map = &create_table_data.region_wal_options_map; + let wal_options_map = &create_table_data.wal_options_map; let create_table_expr = &create_table_data.task.create_table; let catalog = &create_table_expr.catalog_name; @@ -221,7 +221,7 @@ impl CreateTableProcedure { let mut create_region_request = request_template.clone(); create_region_request.region_id = region_id.as_u64(); create_region_request.path = storage_path.clone(); - create_region_request.wal_options = region_wal_options_map + create_region_request.wal_options = wal_options_map .get(region_number) .cloned() .unwrap_or_default(); @@ -269,9 +269,9 @@ impl CreateTableProcedure { let raw_table_info = self.table_info().clone(); let region_routes = self.region_routes().clone(); - let region_wal_options_map = self.region_wal_options_map().clone(); + let wal_options_map = self.wal_options_map().clone(); manager - .create_table_metadata(raw_table_info, region_routes, region_wal_options_map) + .create_table_metadata(raw_table_info, region_routes, wal_options_map) .await?; info!("Created table metadata for table {table_id}"); @@ -328,9 +328,9 @@ impl TableCreator { cluster_id: u64, task: CreateTableTask, region_routes: Vec, - region_wal_options_map: WalOptionsMap, + wal_options_map: HashMap, ) -> Self { - let region_wal_options_map = region_wal_options_map + let wal_options_map = wal_options_map .into_iter() .map(|(region_number, wal_options)| (region_number, wal_options.into())) .collect(); @@ -341,7 +341,7 @@ impl TableCreator { cluster_id, task, region_routes, - region_wal_options_map, + wal_options_map, }, opening_regions: vec![], } @@ -390,7 +390,7 @@ pub struct CreateTableData { pub state: CreateTableState, pub task: CreateTableTask, pub region_routes: Vec, - pub region_wal_options_map: HashMap, + pub wal_options_map: HashMap, pub cluster_id: u64, } diff --git a/src/common/meta/src/ddl_manager.rs b/src/common/meta/src/ddl_manager.rs index 0fac1a437015..7482929d39cf 100644 --- a/src/common/meta/src/ddl_manager.rs +++ b/src/common/meta/src/ddl_manager.rs @@ -12,12 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::collections::HashMap; use std::sync::Arc; use common_procedure::{watcher, ProcedureId, ProcedureManagerRef, ProcedureWithId}; use common_telemetry::tracing_context::{FutureExt, TracingContext}; use common_telemetry::{info, tracing}; use snafu::{OptionExt, ResultExt}; +use store_api::storage::RegionNumber; use crate::cache_invalidator::CacheInvalidatorRef; use crate::datanode_manager::DatanodeManagerRef; @@ -44,7 +46,7 @@ use crate::rpc::ddl::{ TruncateTableTask, }; use crate::rpc::router::RegionRoute; -use crate::wal::WalOptionsMap; +use crate::wal::WalOptions; pub type DdlManagerRef = Arc; /// The [DdlManager] provides the ability to execute Ddl. @@ -53,7 +55,7 @@ pub struct DdlManager { datanode_manager: DatanodeManagerRef, cache_invalidator: CacheInvalidatorRef, table_metadata_manager: TableMetadataManagerRef, - table_meta_allocator: TableMetadataAllocatorRef, + table_metadata_allocator: TableMetadataAllocatorRef, memory_region_keeper: MemoryRegionKeeperRef, } @@ -64,7 +66,7 @@ impl DdlManager { datanode_clients: DatanodeManagerRef, cache_invalidator: CacheInvalidatorRef, table_metadata_manager: TableMetadataManagerRef, - table_meta_allocator: TableMetadataAllocatorRef, + table_metadata_allocator: TableMetadataAllocatorRef, memory_region_keeper: MemoryRegionKeeperRef, ) -> Result { let manager = Self { @@ -72,7 +74,7 @@ impl DdlManager { datanode_manager: datanode_clients, cache_invalidator, table_metadata_manager, - table_meta_allocator, + table_metadata_allocator, memory_region_keeper, }; manager.register_loaders()?; @@ -177,7 +179,7 @@ impl DdlManager { cluster_id: u64, create_table_task: CreateTableTask, region_routes: Vec, - region_wal_options_map: WalOptionsMap, + wal_options_map: HashMap, ) -> Result { let context = self.create_context(); @@ -185,7 +187,7 @@ impl DdlManager { cluster_id, create_table_task, region_routes, - region_wal_options_map, + wal_options_map, context, ); @@ -382,7 +384,7 @@ async fn handle_create_table_task( mut create_table_task: CreateTableTask, ) -> Result { let table_meta = ddl_manager - .table_meta_allocator + .table_metadata_allocator .create( &TableMetadataAllocatorContext { cluster_id }, &mut create_table_task.table_info, @@ -393,7 +395,7 @@ async fn handle_create_table_task( let TableMetadata { table_id, region_routes, - region_wal_options_map, + wal_options_map, } = table_meta; let id = ddl_manager @@ -401,7 +403,7 @@ async fn handle_create_table_task( cluster_id, create_table_task, region_routes, - region_wal_options_map, + wal_options_map, ) .await?; diff --git a/src/common/meta/src/wal.rs b/src/common/meta/src/wal.rs index 9c87d8b6f54e..67c70bc6d7cb 100644 --- a/src/common/meta/src/wal.rs +++ b/src/common/meta/src/wal.rs @@ -44,7 +44,6 @@ pub enum WalOptions { } // TODO(niebayes): determine how to encode wal options. -pub type WalOptionsMap = HashMap; pub type EncodedWalOptions = HashMap; impl From for EncodedWalOptions { diff --git a/src/frontend/src/instance/standalone.rs b/src/frontend/src/instance/standalone.rs index 13d85b262068..5c0a0796a455 100644 --- a/src/frontend/src/instance/standalone.rs +++ b/src/frontend/src/instance/standalone.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::collections::HashMap; use std::sync::Arc; use api::v1::meta::Partition; @@ -26,7 +27,6 @@ use common_meta::kv_backend::KvBackendRef; use common_meta::peer::Peer; use common_meta::rpc::router::{Region, RegionRoute}; use common_meta::sequence::{Sequence, SequenceRef}; -use common_meta::wal::WalOptionsMap; use common_recordbatch::SendableRecordBatchStream; use common_telemetry::tracing; use common_telemetry::tracing_context::{FutureExt, TracingContext}; @@ -154,7 +154,7 @@ impl TableMetadataAllocator for StandaloneTableMetadataCreator { Ok(TableMetadata { table_id, region_routes, - region_wal_options_map: WalOptionsMap::default(), + wal_options_map: HashMap::default(), }) } } diff --git a/src/meta-srv/src/procedure/tests.rs b/src/meta-srv/src/procedure/tests.rs index 1f55576f48f3..18aaeb1f8648 100644 --- a/src/meta-srv/src/procedure/tests.rs +++ b/src/meta-srv/src/procedure/tests.rs @@ -34,7 +34,6 @@ use common_meta::key::table_route::TableRouteValue; use common_meta::key::DeserializedValueWithBytes; use common_meta::rpc::ddl::{AlterTableTask, CreateTableTask, DropTableTask}; use common_meta::rpc::router::{find_leaders, RegionRoute}; -use common_meta::wal::WalOptionsMap; use common_procedure::Status; use store_api::storage::RegionId; @@ -102,7 +101,7 @@ fn test_create_region_request_template() { 1, create_table_task(), test_data::new_region_routes(), - WalOptionsMap::default(), + HashMap::default(), test_data::new_ddl_context(Arc::new(DatanodeClients::default())), ); @@ -194,7 +193,7 @@ async fn test_on_datanode_create_regions() { 1, create_table_task(), region_routes, - WalOptionsMap::default(), + HashMap::default(), test_data::new_ddl_context(datanode_manager), ); diff --git a/src/meta-srv/src/table_meta_alloc.rs b/src/meta-srv/src/table_meta_alloc.rs index 86f48b326ef4..c782c0bdbc3d 100644 --- a/src/meta-srv/src/table_meta_alloc.rs +++ b/src/meta-srv/src/table_meta_alloc.rs @@ -33,7 +33,7 @@ pub struct MetaSrvTableMetadataAllocator { ctx: SelectorContext, selector: SelectorRef, table_id_sequence: SequenceRef, - region_wal_options_allocator: WalOptionsAllocator, + wal_options_allocator: WalOptionsAllocator, } impl MetaSrvTableMetadataAllocator { @@ -41,13 +41,13 @@ impl MetaSrvTableMetadataAllocator { ctx: SelectorContext, selector: SelectorRef, table_id_sequence: SequenceRef, - region_wal_options_allocator: WalOptionsAllocator, + wal_options_allocator: WalOptionsAllocator, ) -> Self { Self { ctx, selector, table_id_sequence, - region_wal_options_allocator, + wal_options_allocator, } } } @@ -73,17 +73,17 @@ impl TableMetadataAllocator for MetaSrvTableMetadataAllocator { .context(meta_error::ExternalSnafu)?; let num_regions = region_routes.len(); - let region_wal_options = self.region_wal_options_allocator.alloc_batch(num_regions); - let region_wal_options_map = region_routes + let wal_options = self.wal_options_allocator.alloc_batch(num_regions); + let wal_options_map = region_routes .iter() .map(|route| route.region.id.region_number()) - .zip(region_wal_options) + .zip(wal_options) .collect(); Ok(TableMetadata { table_id, region_routes, - region_wal_options_map, + wal_options_map, }) } }