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