Skip to content

Commit

Permalink
replace ctor in frontend
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <wangrunji0408@163.com>
  • Loading branch information
wangrunji0408 committed Feb 1, 2024
1 parent ba5c242 commit 3c41911
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ base64 = "0.21"
bk-tree = "0.5.0"
bytes = "1"
clap = { version = "4", features = ["derive"] }
ctor = "0.2"
downcast-rs = "1.2"
dyn-clone = "1.0.14"
easy-ext = "1"
Expand Down
35 changes: 14 additions & 21 deletions src/frontend/src/catalog/system_catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,14 @@ pub fn get_sys_views_in_schema(schema_name: &str) -> Option<Vec<Arc<ViewCatalog>

/// The global registry of all builtin catalogs.
pub static SYS_CATALOGS: LazyLock<SystemCatalog> = LazyLock::new(|| {
// SAFETY: this function is called after all `#[ctor]` functions are called.
let mut table_by_schema_name = HashMap::new();
let mut table_name_by_id = HashMap::new();
let mut view_by_schema_name = HashMap::new();
tracing::info!("found {} catalogs", unsafe { SYS_CATALOGS_INIT.len() });
for (id, catalog) in unsafe { SYS_CATALOGS_INIT.drain(..) } {
tracing::info!("found {} catalogs", SYS_CATALOGS_SLICE.len());
for (id, catalog) in SYS_CATALOGS_SLICE.iter().enumerate() {
let id = (id + 1) as u32;
let catalog = catalog();
assert!(id < NON_RESERVED_SYS_CATALOG_ID as u32);
match catalog {
BuiltinCatalog::Table(table) => {
let sys_table: SystemTableCatalog = table.into();
Expand All @@ -328,28 +330,19 @@ pub static SYS_CATALOGS: LazyLock<SystemCatalog> = LazyLock::new(|| {
}
});

pub static mut SYS_CATALOGS_INIT: Vec<(u32, BuiltinCatalog)> = vec![];

/// Register the catalog to global registry.
///
/// Note: The function is used by macro generated code. Don't call it directly.
#[doc(hidden)]
pub(super) unsafe fn _register(id: u32, builtin_catalog: BuiltinCatalog) {
assert!(id < NON_RESERVED_SYS_CATALOG_ID as u32);

SYS_CATALOGS_INIT.push((id, builtin_catalog));
}
#[linkme::distributed_slice]
pub static SYS_CATALOGS_SLICE: [fn() -> BuiltinCatalog];

macro_rules! prepare_sys_catalog {
($( { $builtin_catalog:expr $(, $func:ident $($await:ident)?)? } ),* $(,)?) => {
paste::paste! {
$(
#[ctor::ctor]
unsafe fn [<register_${index()}>]() {
_register((${index()} + 1) as u32, $builtin_catalog);
$(
const _: () = {
#[linkme::distributed_slice(crate::catalog::system_catalog::SYS_CATALOGS_SLICE)]
fn catalog() -> BuiltinCatalog {
$builtin_catalog
}
)*
}
};
)*

#[async_trait]
impl SysCatalogReader for SysCatalogReaderImpl {
Expand Down

0 comments on commit 3c41911

Please sign in to comment.