pub fn wipe_preserved_catalog(
        &self,
        db_name: &DatabaseName<'static>,
    ) -> Result<TaskTracker<Job>> {
        // Can only wipe catalog of database that failed to initialize
        let config = match &*self.stage.read() {
            ServerStage::Initialized {
                config,
                database_errors,
            } => {
                if config.db_initialized(db_name).is_some() {
                    return Err(Error::DatabaseAlreadyExists {
                        db_name: db_name.to_string(),
                    });
                }

                if !database_errors.contains_key(db_name.as_str()) {
                    // TODO: Should this be an error? Some end-to-end tests assume it is non-fatal
                    warn!(%db_name, "wiping database not present at startup");
                }
                Arc::clone(config)
            }
            ServerStage::Startup { .. } => return Err(Error::IdNotSet),
            ServerStage::Initializing { config, .. } | ServerStage::InitReady { config, .. } => {
                return Err(Error::ServerNotInitialized {
                    server_id: config.server_id(),
                })
            }
        };

        let (tracker, registration) =
            self.application
                .job_registry()
                .register(Job::WipePreservedCatalog {
                    db_name: Arc::from(db_name.as_str()),
                });

        let state = Arc::clone(&self.stage);
        let db_name = db_name.clone();

        let task = async move {
            let result = init::wipe_preserved_catalog_and_maybe_recover(config, &db_name).await;

            match &mut *state.write() {
                ServerStage::Initialized {
                    database_errors, ..
                } => match result {
                    Ok(_) => {
                        info!(%db_name, "wiped preserved catalog of registered database and recovered");
                        database_errors.remove(db_name.as_str());
                        Ok(())
                    }
                    Err(e) => {
                        warn!(%db_name, %e, "wiped preserved catalog of registered database but still cannot recover");
                        let e = Arc::new(e);
                        database_errors.insert(db_name.to_string(), Arc::clone(&e));
                        Err(e)
                    }
                },
                _ => unreachable!("server cannot become uninitialized"),
            }
        };
        tokio::spawn(task.track(registration));

        Ok(tracker)
    }
/// Wipe preserved catalog of specific DB.
///
/// The DB must not yet exist within this server for this to work! This is done to prevent race conditions between
/// DB jobs and this command.
Wipe preserved catalog of specific DB.
The DB must not yet exist within this server for this to work. This is done to prevent race conditions between
DB jobs and this command.
Wipe preserved catalog of specific DB . The DB must not yet exist within this server for this to work . This is done to prevent race conditions between DB jobs and this command .
pub fn wipe_preserved_catalog(
        &self,
        db_name: &DatabaseName<'static>,
    ) -> Result<TaskTracker<Job>> {
        // Can only wipe catalog of database that failed to initialize
        let config = match &*self.stage.read() {
            ServerStage::Initialized {
                config,
                database_errors,
            } => {
                if config.db_initialized(db_name).is_some() {
                    return Err(Error::DatabaseAlreadyExists {
                        db_name: db_name.to_string(),
                    });
                }
                if !database_errors.contains_key(db_name.as_str()) {
                    // TODO: Should this be an error? Some end-to-end tests assume it is non-fatal
                    warn!(%db_name, "wiping database not present at startup");
                }
                Arc::clone(config)
            }
            ServerStage::Startup { .. } => return Err(Error::IdNotSet),
            ServerStage::Initializing { config, .. } | ServerStage::InitReady { config, .. } => {
                return Err(Error::ServerNotInitialized {
                    server_id: config.server_id(),
                })
            }
        };
        let (tracker, registration) =
            self.application
                .job_registry()
                .register(Job::WipePreservedCatalog {
                    db_name: Arc::from(db_name.as_str()),
                });
        let state = Arc::clone(&self.stage);
        let db_name = db_name.clone();
        let task = async move {
            let result = init::wipe_preserved_catalog_and_maybe_recover(config, &db_name).await;
            match &mut *state.write() {
                ServerStage::Initialized {
                    database_errors, ..
                } => match result {
                    Ok(_) => {
                        info!(%db_name, "wiped preserved catalog of registered database and recovered");
                        database_errors.remove(db_name.as_str());
                        Ok(())
                    }
                    Err(e) => {
                        warn!(%db_name, %e, "wiped preserved catalog of registered database but still cannot recover");
                        let e = Arc::new(e);
                        database_errors.insert(db_name.to_string(), Arc::clone(&e));
                        Err(e)
                    }
                },
                _ => unreachable!("server cannot become uninitialized"),
            }
        };
        tokio::spawn(task.track(registration));
        Ok(tracker)
    }
pub fn wipe_preserved_catalog ( & self , db_name : & DatabaseName < ' static > , ) -> Result < TaskTracker < Job > > { // Can only wipe catalog of database that failed to initialize let config = match & * self . stage . read ( ) { ServerStage :: Initialized { config , database_errors , } => { if config . db_initialized ( db_name ) . is_some ( ) { return Err ( Error :: DatabaseAlreadyExists { db_name : db_name . to_string ( ) , } ) ; } if ! database_errors . contains_key ( db_name . as_str ( ) ) { // TODO: Should this be an error? Some end-to-end tests assume it is non-fatal warn ! ( db_name " " ) ; } Arc :: clone ( config ) } ServerStage :: Startup { .. } => return Err ( Error :: IdNotSet ) , ServerStage :: Initializing { config , .. } | ServerStage :: InitReady { config , .. } => { return Err ( Error :: ServerNotInitialized { server_id : config . server_id ( ) , } ) } } ; let ( tracker , registration ) = self . application . job_registry ( ) . register ( Job :: WipePreservedCatalog { db_name : Arc :: from ( db_name . as_str ( ) ) , } ) ; let state = Arc :: clone ( & self . stage ) ; let db_name = db_name . clone ( ) ; let task = async move { let result = init :: wipe_preserved_catalog_and_maybe_recover ( config , & db_name ) . await ; match & mut * state . write ( ) { ServerStage :: Initialized { database_errors , .. } => match result { Ok ( _ ) => { info ! ( db_name " " ) ; database_errors . remove ( db_name . as_str ( ) ) ; Ok ( ( ) ) } Err ( e ) => { warn ! ( db_name e " " ) ; let e = Arc :: new ( e ) ; database_errors . insert ( db_name . to_string ( ) , Arc :: clone ( & e ) ) ; Err ( e ) } } , _ => unreachable ! ( " " ) , } } ; tokio :: spawn ( task . track ( registration ) ) ; Ok ( tracker ) }
Wipe preserved catalog of specific DB.
Wipe preserved catalog of specific DB .
&self
db_name
&DatabaseName<'static>
&self
db_name
&DatabaseName<'static>