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: create schema in static routing #285

Merged
merged 4 commits into from
Oct 9, 2022
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 server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl From<SchemaShardView> for SchemaConfig {
#[derive(Debug, Default, Deserialize, Clone)]
#[serde(default)]
pub struct StaticTopologyConfig {
schema_shards: Vec<SchemaShardView>,
pub schema_shards: Vec<SchemaShardView>,
}

impl From<&StaticTopologyConfig> for ClusterView {
Expand Down
6 changes: 5 additions & 1 deletion server/src/grpc/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ async fn write_request_to_insert_plan<Q: QueryExecutor + 'static>(
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();
}
Expand Down
31 changes: 30 additions & 1 deletion src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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},
Expand Down Expand Up @@ -190,6 +191,13 @@ async fn build_in_standalone_mode<Q: Executor + 'static>(
// 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();
Expand All @@ -204,3 +212,24 @@ async fn build_in_standalone_mode<Q: Executor + 'static>(
.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 {
chunshao90 marked this conversation as resolved.
Show resolved Hide resolved
chunshao90 marked this conversation as resolved.
Show resolved Hide resolved
default_catalog
.create_schema(&schema_shard_view.schema)
.await
.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(),
&schema_shard_view.schema
);
}
}