Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add default schema config #782

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cluster/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,16 @@ pub struct ServerConfig {
/// used in gRPC
pub auto_create_table: bool,

pub default_schema_config: SchemaConfig,

// Config of route
pub route_cache: router::RouteCacheConfig,
}

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,
Expand All @@ -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(),
}
}
Expand Down
14 changes: 11 additions & 3 deletions server/src/schema_config_provider/config_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ pub type SchemaConfigs = HashMap<String, SchemaConfig>;
#[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<Option<&SchemaConfig>> {
Ok(self.schema_configs.get(schema_name))
Ok(Some(
self.schema_configs
.get(schema_name)
.unwrap_or(&self.default),
))
}
}
5 changes: 4 additions & 1 deletion src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ async fn build_without_meta<Q: Executor + 'static, T: WalsOpener>(
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)
Expand Down