Skip to content

Commit

Permalink
refactor: rename region wal options to wal options
Browse files Browse the repository at this point in the history
  • Loading branch information
niebayes committed Dec 15, 2023
1 parent 0c4a798 commit 4ee06f6
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 38 deletions.
7 changes: 4 additions & 3 deletions src/common/meta/src/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -58,7 +59,7 @@ pub struct TableMetadataAllocatorContext {
pub struct TableMetadata {
pub table_id: TableId,
pub region_routes: Vec<RegionRoute>,
pub region_wal_options_map: WalOptionsMap,
pub wal_options_map: HashMap<RegionNumber, WalOptions>,
}

#[async_trait::async_trait]
Expand Down
26 changes: 13 additions & 13 deletions src/common/meta/src/ddl/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -59,12 +59,12 @@ impl CreateTableProcedure {
cluster_id: u64,
task: CreateTableTask,
region_routes: Vec<RegionRoute>,
region_wal_options_map: WalOptionsMap,
wal_options_map: HashMap<RegionNumber, WalOptions>,
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),
}
}

Expand Down Expand Up @@ -96,8 +96,8 @@ impl CreateTableProcedure {
&self.creator.data.region_routes
}

pub fn region_wal_options_map(&self) -> &HashMap<RegionNumber, EncodedWalOptions> {
&self.creator.data.region_wal_options_map
pub fn wal_options_map(&self) -> &HashMap<RegionNumber, EncodedWalOptions> {
&self.creator.data.wal_options_map
}

/// Checks whether the table exists.
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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}");

Expand Down Expand Up @@ -328,9 +328,9 @@ impl TableCreator {
cluster_id: u64,
task: CreateTableTask,
region_routes: Vec<RegionRoute>,
region_wal_options_map: WalOptionsMap,
wal_options_map: HashMap<RegionNumber, WalOptions>,
) -> 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();
Expand All @@ -341,7 +341,7 @@ impl TableCreator {
cluster_id,
task,
region_routes,
region_wal_options_map,
wal_options_map,
},
opening_regions: vec![],
}
Expand Down Expand Up @@ -390,7 +390,7 @@ pub struct CreateTableData {
pub state: CreateTableState,
pub task: CreateTableTask,
pub region_routes: Vec<RegionRoute>,
pub region_wal_options_map: HashMap<RegionNumber, EncodedWalOptions>,
pub wal_options_map: HashMap<RegionNumber, EncodedWalOptions>,
pub cluster_id: u64,
}

Expand Down
20 changes: 11 additions & 9 deletions src/common/meta/src/ddl_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<DdlManager>;

/// The [DdlManager] provides the ability to execute Ddl.
Expand All @@ -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,
}

Expand All @@ -64,15 +66,15 @@ 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<Self> {
let manager = Self {
procedure_manager,
datanode_manager: datanode_clients,
cache_invalidator,
table_metadata_manager,
table_meta_allocator,
table_metadata_allocator,
memory_region_keeper,
};
manager.register_loaders()?;
Expand Down Expand Up @@ -177,15 +179,15 @@ impl DdlManager {
cluster_id: u64,
create_table_task: CreateTableTask,
region_routes: Vec<RegionRoute>,
region_wal_options_map: WalOptionsMap,
wal_options_map: HashMap<RegionNumber, WalOptions>,
) -> Result<ProcedureId> {
let context = self.create_context();

let procedure = CreateTableProcedure::new(
cluster_id,
create_table_task,
region_routes,
region_wal_options_map,
wal_options_map,
context,
);

Expand Down Expand Up @@ -382,7 +384,7 @@ async fn handle_create_table_task(
mut create_table_task: CreateTableTask,
) -> Result<SubmitDdlTaskResponse> {
let table_meta = ddl_manager
.table_meta_allocator
.table_metadata_allocator
.create(
&TableMetadataAllocatorContext { cluster_id },
&mut create_table_task.table_info,
Expand All @@ -393,15 +395,15 @@ 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
.submit_create_table_task(
cluster_id,
create_table_task,
region_routes,
region_wal_options_map,
wal_options_map,
)
.await?;

Expand Down
1 change: 0 additions & 1 deletion src/common/meta/src/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub enum WalOptions {
}

// TODO(niebayes): determine how to encode wal options.
pub type WalOptionsMap = HashMap<RegionNumber, WalOptions>;
pub type EncodedWalOptions = HashMap<String, String>;

impl From<WalOptions> for EncodedWalOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/instance/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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(),
})
}
}
5 changes: 2 additions & 3 deletions src/meta-srv/src/procedure/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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())),
);

Expand Down Expand Up @@ -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),
);

Expand Down
14 changes: 7 additions & 7 deletions src/meta-srv/src/table_meta_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ pub struct MetaSrvTableMetadataAllocator {
ctx: SelectorContext,
selector: SelectorRef,
table_id_sequence: SequenceRef,
region_wal_options_allocator: WalOptionsAllocator,
wal_options_allocator: WalOptionsAllocator,
}

impl MetaSrvTableMetadataAllocator {
pub fn new(
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,
}
}
}
Expand All @@ -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,
})
}
}
Expand Down

0 comments on commit 4ee06f6

Please sign in to comment.