Skip to content

Commit

Permalink
refactor: system tables in FrontendCatalogManager (#2358)
Browse files Browse the repository at this point in the history
* rename method names

Signed-off-by: Ruihang Xia <[email protected]>

* remove system table, table engine, register/deregister

Signed-off-by: Ruihang Xia <[email protected]>

* add system catalog

Signed-off-by: Ruihang Xia <[email protected]>

* run nextest

Signed-off-by: Ruihang Xia <[email protected]>

* some documents

Signed-off-by: Ruihang Xia <[email protected]>

* fix: fix clippy

---------

Signed-off-by: Ruihang Xia <[email protected]>
Co-authored-by: WenyXu <[email protected]>
  • Loading branch information
waynexia and WenyXu committed Sep 12, 2023
1 parent 6734c68 commit 2b603ec
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 1,039 deletions.
84 changes: 2 additions & 82 deletions src/catalog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ use std::fmt::{Debug, Formatter};
use std::sync::Arc;

use api::v1::meta::RegionStat;
use common_telemetry::{info, warn};
use common_telemetry::warn;
use futures::future::BoxFuture;
use snafu::ResultExt;
use table::engine::{EngineContext, TableEngineRef};
use table::metadata::{TableId, TableType};
use table::requests::CreateTableRequest;
use table::TableRef;

use crate::error::{CreateTableSnafu, Result};
use crate::error::Result;

pub mod error;
pub mod information_schema;
Expand All @@ -38,47 +36,11 @@ mod metrics;
pub mod remote;
pub mod system;
pub mod table_source;
pub mod tables;

#[async_trait::async_trait]
pub trait CatalogManager: Send + Sync {
fn as_any(&self) -> &dyn Any;

/// Register a local catalog.
///
/// # Returns
///
/// Whether the catalog is registered.
fn register_local_catalog(&self, name: &str) -> Result<bool>;

/// Register a local schema.
///
/// # Returns
///
/// Whether the schema is registered.
///
/// # Errors
///
/// This method will/should fail if catalog not exist
fn register_local_schema(&self, request: RegisterSchemaRequest) -> Result<bool>;

/// Deregisters a database within given catalog/schema to catalog manager
fn deregister_local_schema(&self, request: DeregisterSchemaRequest) -> Result<bool>;

/// Registers a local table.
///
/// # Returns
///
/// Whether the table is registered.
///
/// # Errors
///
/// This method will/should fail if catalog or schema not exist
fn register_local_table(&self, request: RegisterTableRequest) -> Result<bool>;

/// Deregisters a table within given catalog/schema to catalog manager
fn deregister_local_table(&self, request: DeregisterTableRequest) -> Result<()>;

async fn catalog_names(&self) -> Result<Vec<String>>;

async fn schema_names(&self, catalog: &str) -> Result<Vec<String>>;
Expand Down Expand Up @@ -164,48 +126,6 @@ pub struct RegisterSchemaRequest {
pub schema: String,
}

pub(crate) async fn handle_system_table_request<'a, M: CatalogManager + ?Sized>(
manager: &'a M,
engine: TableEngineRef,
sys_table_requests: &'a mut Vec<RegisterSystemTableRequest>,
) -> Result<()> {
for req in sys_table_requests.drain(..) {
let catalog_name = &req.create_table_request.catalog_name;
let schema_name = &req.create_table_request.schema_name;
let table_name = &req.create_table_request.table_name;
let table_id = req.create_table_request.id;

let table = manager.table(catalog_name, schema_name, table_name).await?;
let table = if let Some(table) = table {
table
} else {
let table = engine
.create_table(&EngineContext::default(), req.create_table_request.clone())
.await
.with_context(|_| CreateTableSnafu {
table_info: common_catalog::format_full_table_name(
catalog_name,
schema_name,
table_name,
),
})?;
manager.register_local_table(RegisterTableRequest {
catalog: catalog_name.clone(),
schema: schema_name.clone(),
table_name: table_name.clone(),
table_id,
table: table.clone(),
})?;
info!("Created and registered system table: {table_name}");
table
};
if let Some(hook) = req.open_hook {
(hook)(table).await?;
}
}
Ok(())
}

/// The stat of regions in the datanode node.
/// The number of regions can be got from len of vec.
///
Expand Down
1 change: 0 additions & 1 deletion src/catalog/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod manager;
pub mod memory;

pub use memory::{new_memory_catalog_manager, MemoryCatalogManager};
Loading

0 comments on commit 2b603ec

Please sign in to comment.