/// Load preserved catalog state from store.
///
/// If no catalog exists yet, a new one will be created.
///
/// **For now, if the catalog is broken, it will be wiped! (https://github.com/influxdata/influxdb_iox/issues/1522)**
Load preserved catalog state from store.
If no catalog exists yet, a new one will be created.

For now, if the catalog is broken, it will be wiped!
Load preserved catalog state from store . If no catalog exists yet a new one will be created . For now if the catalog is broken it will be wiped!
pub async fn load_or_create_preserved_catalog(
    db_name: &str,
    object_store: Arc<ObjectStore>,
    server_id: ServerId,
    metrics_registry: Arc<MetricRegistry>,
) -> std::result::Result<PreservedCatalog<Catalog>, parquet_file::catalog::Error> {
    let metric_labels = vec![
        KeyValue::new("db_name", db_name.to_string()),
        KeyValue::new("svr_id", format!("{}", server_id)),
    ];
    // first try to load existing catalogs
    let metrics_domain =
        metrics_registry.register_domain_with_labels("catalog", metric_labels.clone());
    match PreservedCatalog::load(
        Arc::clone(&object_store),
        server_id,
        db_name.to_string(),
        CatalogEmptyInput {
            domain: metrics_domain,
            metrics_registry: Arc::clone(&metrics_registry),
            metric_labels: metric_labels.clone(),
        },
    )
    .await
    {
        Ok(Some(catalog)) => {
            // successfull load
            info!("Found existing catalog for DB {}", db_name);
            Ok(catalog)
        }
        Ok(None) => {
            // no catalog yet => create one
            info!(
                "Found NO existing catalog for DB {}, creating new one",
                db_name
            );
            let metrics_domain =
                metrics_registry.register_domain_with_labels("catalog", metric_labels.clone());
            PreservedCatalog::new_empty(
                Arc::clone(&object_store),
                server_id,
                db_name.to_string(),
                CatalogEmptyInput {
                    domain: metrics_domain,
                    metrics_registry: Arc::clone(&metrics_registry),
                    metric_labels: metric_labels.clone(),
                },
            )
            .await
        }
        Err(e) => {
            // https://github.com/influxdata/influxdb_iox/issues/1522)
            // broken => wipe for now (at least during early iterations)
            error!("cannot load catalog, so wipe it: {}", e);
            PreservedCatalog::<Catalog>::wipe(&object_store, server_id, db_name).await?;
            let metrics_domain =
                metrics_registry.register_domain_with_labels("catalog", metric_labels.clone());
            PreservedCatalog::new_empty(
                Arc::clone(&object_store),
                server_id,
                db_name.to_string(),
                CatalogEmptyInput {
                    domain: metrics_domain,
                    metrics_registry: Arc::clone(&metrics_registry),
                    metric_labels: metric_labels.clone(),
                },
            )
            .await
        }
    }
}
pub async fn load_or_create_preserved_catalog ( db_name : & str , object_store : Arc < ObjectStore > , server_id : ServerId , metrics_registry : Arc < MetricRegistry > , ) -> std :: result :: Result < PreservedCatalog < Catalog > , parquet_file :: catalog :: Error > { let metric_labels = vec ! [ KeyValue new ( " " db_name to_string ( ) ) KeyValue new ( " " format ( " " server_id ) ) ] ; // first try to load existing catalogs let metrics_domain = metrics_registry . register_domain_with_labels ( " " , metric_labels . clone ( ) ) ; match PreservedCatalog :: load ( Arc :: clone ( & object_store ) , server_id , db_name . to_string ( ) , CatalogEmptyInput { domain : metrics_domain , metrics_registry : Arc :: clone ( & metrics_registry ) , metric_labels : metric_labels . clone ( ) , } , ) . await { Ok ( Some ( catalog ) ) => { // successfull load info ! ( " " db_name ) ; Ok ( catalog ) } Ok ( None ) => { // no catalog yet => create one info ! ( " " db_name ) ; let metrics_domain = metrics_registry . register_domain_with_labels ( " " , metric_labels . clone ( ) ) ; PreservedCatalog :: new_empty ( Arc :: clone ( & object_store ) , server_id , db_name . to_string ( ) , CatalogEmptyInput { domain : metrics_domain , metrics_registry : Arc :: clone ( & metrics_registry ) , metric_labels : metric_labels . clone ( ) , } , ) . await } Err ( e ) => { // https://github.com/influxdata/influxdb_iox/issues/1522) // broken => wipe for now (at least during early iterations) error ! ( " " e ) ; PreservedCatalog :: < Catalog > :: wipe ( & object_store , server_id , db_name ) . await ? ; let metrics_domain = metrics_registry . register_domain_with_labels ( " " , metric_labels . clone ( ) ) ; PreservedCatalog :: new_empty ( Arc :: clone ( & object_store ) , server_id , db_name . to_string ( ) , CatalogEmptyInput { domain : metrics_domain , metrics_registry : Arc :: clone ( & metrics_registry ) , metric_labels : metric_labels . clone ( ) , } , ) . await } } }
Load preserved catalog state from store.
Load preserved catalog state from store .
db_name
&str
object_store
Arc<ObjectStore>
server_id
ServerId
metrics_registry
Arc<MetricRegistry>