Skip to main content

common_function/
admin.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15mod build_index_table;
16mod flush_compact_region;
17mod flush_compact_table;
18mod gc;
19mod migrate_region;
20#[cfg(feature = "enterprise")]
21mod purge_table;
22mod reconcile_catalog;
23mod reconcile_database;
24mod reconcile_table;
25
26use flush_compact_region::{CompactRegionFunction, FlushRegionFunction};
27use flush_compact_table::{CompactTableFunction, FlushTableFunction};
28use gc::{GcRegionsFunction, GcTableFunction};
29use migrate_region::MigrateRegionFunction;
30#[cfg(feature = "enterprise")]
31use purge_table::PurgeTableFunction;
32use reconcile_catalog::ReconcileCatalogFunction;
33use reconcile_database::ReconcileDatabaseFunction;
34use reconcile_table::ReconcileTableFunction;
35
36use crate::admin::build_index_table::BuildIndexFunction;
37use crate::flush_flow::FlushFlowFunction;
38use crate::function_registry::FunctionRegistry;
39
40/// Administration functions
41pub(crate) struct AdminFunction;
42
43impl AdminFunction {
44    /// Register all admin functions to [`FunctionRegistry`].
45    pub fn register(registry: &FunctionRegistry) {
46        registry.register(MigrateRegionFunction::factory());
47        registry.register(FlushRegionFunction::factory());
48        registry.register(CompactRegionFunction::factory());
49        registry.register(FlushTableFunction::factory());
50        registry.register(CompactTableFunction::factory());
51        registry.register(GcRegionsFunction::factory());
52        registry.register(GcTableFunction::factory());
53        registry.register(BuildIndexFunction::factory());
54        registry.register(FlushFlowFunction::factory());
55        registry.register(ReconcileCatalogFunction::factory());
56        registry.register(ReconcileDatabaseFunction::factory());
57        registry.register(ReconcileTableFunction::factory());
58    }
59
60    /// Register functions that must only be resolved by an ADMIN statement.
61    #[cfg_attr(not(feature = "enterprise"), allow(unused_variables))]
62    pub fn register_admin_only(registry: &FunctionRegistry) {
63        #[cfg(feature = "enterprise")]
64        registry.register(PurgeTableFunction::factory());
65    }
66}