standalone/
procedure.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
15use std::sync::Arc;
16
17use common_error::ext::BoxedError;
18use common_meta::ddl::DdlContext;
19use common_meta::ddl_manager::RepartitionProcedureFactory;
20use common_meta::key::runtime_switch::RuntimeSwitchManager;
21use common_meta::kv_backend::KvBackendRef;
22use common_meta::state_store::KvStateStore;
23use common_procedure::local::{LocalManager, ManagerConfig};
24use common_procedure::options::ProcedureConfig;
25use common_procedure::{BoxedProcedure, ProcedureManagerRef};
26use store_api::storage::TableId;
27use table::table_name::TableName;
28
29use crate::error::NoSupportRepartitionProcedureSnafu;
30
31/// Builds the procedure manager.
32pub fn build_procedure_manager(
33    kv_backend: KvBackendRef,
34    procedure_config: ProcedureConfig,
35) -> ProcedureManagerRef {
36    let kv_state_store = Arc::new(KvStateStore::new(kv_backend.clone()));
37
38    let manager_config = ManagerConfig {
39        max_retry_times: procedure_config.max_retry_times,
40        retry_delay: procedure_config.retry_delay,
41        max_running_procedures: procedure_config.max_running_procedures,
42        ..Default::default()
43    };
44    let runtime_switch_manager = Arc::new(RuntimeSwitchManager::new(kv_backend));
45    Arc::new(LocalManager::new(
46        manager_config,
47        kv_state_store.clone(),
48        kv_state_store,
49        Some(runtime_switch_manager),
50        None,
51    ))
52}
53
54/// No-op implementation of [`RepartitionProcedureFactory`] for standalone mode.
55///
56/// In standalone deployments, repartition operations are not supported, so
57/// this factory always returns a `NoSupportRepartitionProcedure` error
58/// from [`RepartitionProcedureFactory::create`] and performs no registration
59/// work in [`RepartitionProcedureFactory::register_loaders`].
60pub struct StandaloneRepartitionProcedureFactory;
61
62impl RepartitionProcedureFactory for StandaloneRepartitionProcedureFactory {
63    fn create(
64        &self,
65        _ddl_ctx: &DdlContext,
66        _table_name: TableName,
67        _table_id: TableId,
68        _from_exprs: Vec<String>,
69        _to_exprs: Vec<String>,
70    ) -> std::result::Result<BoxedProcedure, BoxedError> {
71        Err(BoxedError::new(NoSupportRepartitionProcedureSnafu.build()))
72    }
73
74    fn register_loaders(
75        &self,
76        _ddl_ctx: &DdlContext,
77        _procedure_manager: &ProcedureManagerRef,
78    ) -> std::result::Result<(), BoxedError> {
79        Ok(())
80    }
81}