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