common_meta/reconciliation/reconcile_catalog/
start.rs1use std::any::Any;
16
17use common_procedure::{Context as ProcedureContext, Status};
18use serde::{Deserialize, Serialize};
19use snafu::ensure;
20
21use crate::error::{self, Result};
22use crate::key::catalog_name::CatalogNameKey;
23use crate::reconciliation::reconcile_catalog::reconcile_databases::ReconcileDatabases;
24use crate::reconciliation::reconcile_catalog::{ReconcileCatalogContext, State};
25
26#[derive(Debug, Serialize, Deserialize)]
27pub(crate) struct ReconcileCatalogStart;
28
29#[async_trait::async_trait]
30#[typetag::serde]
31impl State for ReconcileCatalogStart {
32 async fn next(
33 &mut self,
34 ctx: &mut ReconcileCatalogContext,
35 _procedure_ctx: &ProcedureContext,
36 ) -> Result<(Box<dyn State>, Status)> {
37 let exists = ctx
38 .table_metadata_manager
39 .catalog_manager()
40 .exists(CatalogNameKey {
41 catalog: &ctx.persistent_ctx.catalog,
42 })
43 .await?;
44
45 ensure!(
46 exists,
47 error::CatalogNotFoundSnafu {
48 catalog: &ctx.persistent_ctx.catalog
49 },
50 );
51
52 Ok((Box::new(ReconcileDatabases), Status::executing(true)))
53 }
54
55 fn as_any(&self) -> &dyn Any {
56 self
57 }
58}