Skip to main content

meta_srv/
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 async_trait::async_trait;
16use common_meta::error::{self, Result};
17use common_meta::leadership_notifier::LeadershipChangeListener;
18use common_procedure::ProcedureManagerRef;
19use snafu::ResultExt;
20
21pub mod drain_datanode;
22pub mod region_migration;
23pub mod repartition;
24#[cfg(any(test, feature = "testing"))]
25pub mod test_util;
26#[cfg(test)]
27mod tests;
28pub mod utils;
29pub mod wal_prune;
30
31#[derive(Clone)]
32pub struct ProcedureManagerListenerAdapter(pub ProcedureManagerRef);
33
34#[async_trait]
35impl LeadershipChangeListener for ProcedureManagerListenerAdapter {
36    fn name(&self) -> &str {
37        "ProcedureManager"
38    }
39
40    async fn on_leader_start(&self) -> Result<()> {
41        self.0
42            .start()
43            .await
44            .context(error::StartProcedureManagerSnafu)
45    }
46
47    async fn on_leader_stop(&self) -> Result<()> {
48        self.0
49            .stop()
50            .await
51            .context(error::StopProcedureManagerSnafu)
52    }
53}