From 2815a680eaf736addea0daccea7f753a1f776470 Mon Sep 17 00:00:00 2001 From: "chunshao.rcs" Date: Sat, 8 Oct 2022 19:25:14 +0800 Subject: [PATCH 1/4] feat: create schema when static topology is set --- server/src/config.rs | 2 +- src/setup.rs | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/server/src/config.rs b/server/src/config.rs index dc69df11a5..7a15305861 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -138,7 +138,7 @@ impl From for SchemaConfig { #[derive(Debug, Default, Deserialize, Clone)] #[serde(default)] pub struct StaticTopologyConfig { - schema_shards: Vec, + pub schema_shards: Vec, } impl From<&StaticTopologyConfig> for ClusterView { diff --git a/src/setup.rs b/src/setup.rs index 76eea40c7a..77b009752d 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -8,6 +8,7 @@ use analytic_engine::{ self, setup::{EngineBuilder, ReplicatedEngineBuilder, RocksEngineBuilder}, }; +use catalog::manager::ManagerRef; use catalog_impls::{table_based::TableBasedManager, volatile, CatalogManagerImpl}; use cluster::cluster_impl::ClusterImpl; use common_util::runtime; @@ -17,7 +18,7 @@ use logger::RuntimeLevel; use meta_client::meta_impl; use query_engine::executor::{Executor, ExecutorImpl}; use server::{ - config::{Config, DeployMode, RuntimeConfig}, + config::{Config, DeployMode, RuntimeConfig, StaticTopologyConfig}, route::{ cluster_based::ClusterBasedRouter, rule_based::{ClusterView, RuleBasedRouter}, @@ -190,6 +191,13 @@ async fn build_in_standalone_mode( // Create catalog manager, use analytic table as backend let catalog_manager = Arc::new(CatalogManagerImpl::new(Arc::new(table_based_manager))); + // Create schema in default catalog. + create_static_topology_schema( + catalog_manager.clone(), + config.static_route.topology.clone(), + ) + .await; + // Build static router and schema config provider let cluster_view = ClusterView::from(&config.static_route.topology); let schema_configs = cluster_view.schema_configs.clone(); @@ -204,3 +212,27 @@ async fn build_in_standalone_mode( .router(router) .schema_config_provider(schema_config_provider) } + +async fn create_static_topology_schema( + catalog_mgr: ManagerRef, + static_topology_config: StaticTopologyConfig, +) { + let default_catalog = catalog_mgr + .catalog_by_name(catalog_mgr.default_catalog_name()) + .expect("Fail to retrieve default catalog") + .expect("Default catalog doesn't exist"); + for schema_shard_view in static_topology_config.schema_shards { + default_catalog + .create_schema(&schema_shard_view.schema) + .await + .expect(&format!( + "Fail to create schema:{}", + schema_shard_view.schema + )); + info!( + "Create static topology in default catalog:{} schema:{}", + catalog_mgr.default_catalog_name(), + &schema_shard_view.schema + ); + } +} From 5cffbeb44349d1f88bbf3daf3678a4ce1291d32f Mon Sep 17 00:00:00 2001 From: "chunshao.rcs" Date: Sun, 9 Oct 2022 15:50:33 +0800 Subject: [PATCH 2/4] chore: return tenant when write fail --- server/src/grpc/write.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/src/grpc/write.rs b/server/src/grpc/write.rs index b6914c8f12..df9bbe5426 100644 --- a/server/src/grpc/write.rs +++ b/server/src/grpc/write.rs @@ -134,7 +134,11 @@ async fn write_request_to_insert_plan( None => { return ErrNoCause { code: StatusCode::BAD_REQUEST, - msg: format!("Table not found, table:{}", table_name), + msg: format!( + "Table not found, tenant:{}, table:{}", + ctx.tenant(), + table_name + ), } .fail(); } From ba74a06f30fc20f50b3257b58e214973297076d3 Mon Sep 17 00:00:00 2001 From: "chunshao.rcs" Date: Sun, 9 Oct 2022 16:00:00 +0800 Subject: [PATCH 3/4] chore: refactor code --- src/setup.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup.rs b/src/setup.rs index 77b009752d..ac86656719 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -230,7 +230,7 @@ async fn create_static_topology_schema( schema_shard_view.schema )); info!( - "Create static topology in default catalog:{} schema:{}", + "Create static topology in default catalog:{}, schema:{}", catalog_mgr.default_catalog_name(), &schema_shard_view.schema ); From 52c0df59d73517523dcacac31bbedc29297d69c6 Mon Sep 17 00:00:00 2001 From: "chunshao.rcs" Date: Sun, 9 Oct 2022 16:45:39 +0800 Subject: [PATCH 4/4] chore: fix clippy --- src/setup.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/setup.rs b/src/setup.rs index ac86656719..a8260cd93d 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -225,10 +225,7 @@ async fn create_static_topology_schema( default_catalog .create_schema(&schema_shard_view.schema) .await - .expect(&format!( - "Fail to create schema:{}", - schema_shard_view.schema - )); + .unwrap_or_else(|_| panic!("Fail to create schema:{}", schema_shard_view.schema)); info!( "Create static topology in default catalog:{}, schema:{}", catalog_mgr.default_catalog_name(),