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