From eb4b0a2bc669f6f4c1af6306e0c405c2e853f332 Mon Sep 17 00:00:00 2001 From: Jiacai Liu Date: Tue, 28 Mar 2023 17:34:35 +0800 Subject: [PATCH] feat: add default schema config (#782) --- cluster/src/config.rs | 2 +- server/src/config.rs | 5 ++++- server/src/schema_config_provider/config_based.rs | 14 +++++++++++--- src/setup.rs | 5 ++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cluster/src/config.rs b/cluster/src/config.rs index cb7006ca44..4e87d735b7 100644 --- a/cluster/src/config.rs +++ b/cluster/src/config.rs @@ -5,7 +5,7 @@ use meta_client::meta_impl::MetaClientConfig; use serde::{Deserialize, Serialize}; use table_engine::ANALYTIC_ENGINE_TYPE; -#[derive(Debug, Clone, Deserialize)] +#[derive(Debug, Clone, Deserialize, Serialize)] #[serde(default)] // TODO: move this to table_engine crates pub struct SchemaConfig { diff --git a/server/src/config.rs b/server/src/config.rs index ea614e2506..c6dff8c12d 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -111,6 +111,8 @@ pub struct ServerConfig { /// used in gRPC pub auto_create_table: bool, + pub default_schema_config: SchemaConfig, + // Config of route pub route_cache: router::RouteCacheConfig, } @@ -118,7 +120,7 @@ pub struct ServerConfig { impl Default for ServerConfig { fn default() -> Self { Self { - bind_addr: String::from("0.0.0.0"), + bind_addr: String::from("127.0.0.1"), http_port: 5440, mysql_port: 3307, grpc_port: 8831, @@ -128,6 +130,7 @@ impl Default for ServerConfig { resp_compress_min_length: ReadableSize::mb(4), forward: forward::Config::default(), auto_create_table: true, + default_schema_config: Default::default(), route_cache: router::RouteCacheConfig::default(), } } diff --git a/server/src/schema_config_provider/config_based.rs b/server/src/schema_config_provider/config_based.rs index 0bfa61188d..d7e8c0b933 100644 --- a/server/src/schema_config_provider/config_based.rs +++ b/server/src/schema_config_provider/config_based.rs @@ -14,16 +14,24 @@ pub type SchemaConfigs = HashMap; #[derive(Debug)] pub struct ConfigBasedProvider { schema_configs: SchemaConfigs, + default: SchemaConfig, } impl ConfigBasedProvider { - pub fn new(schema_configs: SchemaConfigs) -> Self { - Self { schema_configs } + pub fn new(schema_configs: SchemaConfigs, default: SchemaConfig) -> Self { + Self { + schema_configs, + default, + } } } impl SchemaConfigProvider for ConfigBasedProvider { fn schema_config(&self, schema_name: &str) -> Result> { - Ok(self.schema_configs.get(schema_name)) + Ok(Some( + self.schema_configs + .get(schema_name) + .unwrap_or(&self.default), + )) } } diff --git a/src/setup.rs b/src/setup.rs index 7e98f64fe1..ebf74d79ad 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -311,7 +311,10 @@ async fn build_without_meta( cluster_view, static_route_config.rules.clone(), )); - let schema_config_provider = Arc::new(ConfigBasedProvider::new(schema_configs)); + let schema_config_provider = Arc::new(ConfigBasedProvider::new( + schema_configs, + config.server.default_schema_config.clone(), + )); builder .table_engine(engine_proxy)