async fn try_advance_database_init_process(
    handle: &mut DatabaseHandle<'_>,
    root: &Path,
    wipe_on_error: bool,
    skip_replay_and_seek_instead: bool,
) -> Result<InitProgress> {
    match handle.state_code() {
        DatabaseStateCode::Known => {
            // known => load DB rules
            let path = object_store_path_for_database_config(root, &handle.db_name());
            let rules = load_database_rules(handle.object_store(), &path).await?;
            handle
                .advance_rules_loaded(rules)
                .map_err(Box::new)
                .context(InitDbError)?;

            // there is still more work to do for this DB
            Ok(InitProgress::Unfinished)
        }
        DatabaseStateCode::RulesLoaded => {
            // rules already loaded => continue with loading preserved catalog
            let (preserved_catalog, catalog, replay_plan) = load_or_create_preserved_catalog(
                &handle.db_name(),
                handle.object_store(),
                handle.server_id(),
                handle.metrics_registry(),
                wipe_on_error,
            )
            .await
            .map_err(|e| Box::new(e) as _)
            .context(CatalogLoadError)?;

            let rules = handle
                .rules()
                .expect("in this state rules should be loaded");
            let write_buffer = WriteBufferConfig::new(handle.server_id(), &rules)
                .await
                .context(CreateWriteBuffer {
                    config: rules.write_buffer_connection.clone(),
                })?;

            info!(write_buffer_enabled=?write_buffer.is_some(), db_name=rules.db_name(), "write buffer configured");
            handle
                .advance_replay(preserved_catalog, catalog, replay_plan, write_buffer)
                .map_err(Box::new)
                .context(InitDbError)?;

            // there is still more work to do for this DB
            Ok(InitProgress::Unfinished)
        }
        DatabaseStateCode::Replay => {
            let db = handle
                .db_any_state()
                .expect("DB should be available in this state");
            let replay_plan = handle
                .replay_plan()
                .expect("replay plan should exist in this state");
            db.perform_replay(&replay_plan, skip_replay_and_seek_instead)
                .await
                .map_err(Box::new)
                .context(ReplayError)?;
            db.unsuppress_persistence().await;
            db.allow_write_buffer_read();

            handle
                .advance_init()
                .map_err(Box::new)
                .context(InitDbError)?;

            // there is still more work to do for this DB
            Ok(InitProgress::Unfinished)
        }
        DatabaseStateCode::Initialized => {
            // database fully initialized => nothing to do
            Ok(InitProgress::Done)
        }
    }
}
/// Try to make some progress in the DB init.
Try to make some progress in the DB init.
Try to make some progress in the DB init .
async fn try_advance_database_init_process(
    handle: &mut DatabaseHandle<'_>,
    root: &Path,
    wipe_on_error: bool,
    skip_replay_and_seek_instead: bool,
) -> Result<InitProgress> {
    match handle.state_code() {
        DatabaseStateCode::Known => {
            // known => load DB rules
            let path = object_store_path_for_database_config(root, &handle.db_name());
            let rules = load_database_rules(handle.object_store(), &path).await?;
            handle
                .advance_rules_loaded(rules)
                .map_err(Box::new)
                .context(InitDbError)?;
            // there is still more work to do for this DB
            Ok(InitProgress::Unfinished)
        }
        DatabaseStateCode::RulesLoaded => {
            // rules already loaded => continue with loading preserved catalog
            let (preserved_catalog, catalog, replay_plan) = load_or_create_preserved_catalog(
                &handle.db_name(),
                handle.object_store(),
                handle.server_id(),
                handle.metrics_registry(),
                wipe_on_error,
            )
            .await
            .map_err(|e| Box::new(e) as _)
            .context(CatalogLoadError)?;
            let rules = handle
                .rules()
                .expect("in this state rules should be loaded");
            let write_buffer = WriteBufferConfig::new(handle.server_id(), &rules)
                .await
                .context(CreateWriteBuffer {
                    config: rules.write_buffer_connection.clone(),
                })?;
            info!(write_buffer_enabled=?write_buffer.is_some(), db_name=rules.db_name(), "write buffer configured");
            handle
                .advance_replay(preserved_catalog, catalog, replay_plan, write_buffer)
                .map_err(Box::new)
                .context(InitDbError)?;
            // there is still more work to do for this DB
            Ok(InitProgress::Unfinished)
        }
        DatabaseStateCode::Replay => {
            let db = handle
                .db_any_state()
                .expect("DB should be available in this state");
            let replay_plan = handle
                .replay_plan()
                .expect("replay plan should exist in this state");
            db.perform_replay(&replay_plan, skip_replay_and_seek_instead)
                .await
                .map_err(Box::new)
                .context(ReplayError)?;
            db.unsuppress_persistence().await;
            db.allow_write_buffer_read();
            handle
                .advance_init()
                .map_err(Box::new)
                .context(InitDbError)?;
            // there is still more work to do for this DB
            Ok(InitProgress::Unfinished)
        }
        DatabaseStateCode::Initialized => {
            // database fully initialized => nothing to do
            Ok(InitProgress::Done)
        }
    }
}
async fn try_advance_database_init_process ( handle : & mut DatabaseHandle < ' _ > , root : & Path , wipe_on_error : bool , skip_replay_and_seek_instead : bool , ) -> Result < InitProgress > { match handle . state_code ( ) { DatabaseStateCode :: Known => { // known => load DB rules let path = object_store_path_for_database_config ( root , & handle . db_name ( ) ) ; let rules = load_database_rules ( handle . object_store ( ) , & path ) . await ? ; handle . advance_rules_loaded ( rules ) . map_err ( Box :: new ) . context ( InitDbError ) ? ; // there is still more work to do for this DB Ok ( InitProgress :: Unfinished ) } DatabaseStateCode :: RulesLoaded => { // rules already loaded => continue with loading preserved catalog let ( preserved_catalog , catalog , replay_plan ) = load_or_create_preserved_catalog ( & handle . db_name ( ) , handle . object_store ( ) , handle . server_id ( ) , handle . metrics_registry ( ) , wipe_on_error , ) . await . map_err ( | e | Box :: new ( e ) as _ ) . context ( CatalogLoadError ) ? ; let rules = handle . rules ( ) . expect ( " " ) ; let write_buffer = WriteBufferConfig :: new ( handle . server_id ( ) , & rules ) . await . context ( CreateWriteBuffer { config : rules . write_buffer_connection . clone ( ) , } ) ? ; info ! ( write_buffer_enabled write_buffer is_some ( ) db_name rules db_name ( ) " " ) ; handle . advance_replay ( preserved_catalog , catalog , replay_plan , write_buffer ) . map_err ( Box :: new ) . context ( InitDbError ) ? ; // there is still more work to do for this DB Ok ( InitProgress :: Unfinished ) } DatabaseStateCode :: Replay => { let db = handle . db_any_state ( ) . expect ( " " ) ; let replay_plan = handle . replay_plan ( ) . expect ( " " ) ; db . perform_replay ( & replay_plan , skip_replay_and_seek_instead ) . await . map_err ( Box :: new ) . context ( ReplayError ) ? ; db . unsuppress_persistence ( ) . await ; db . allow_write_buffer_read ( ) ; handle . advance_init ( ) . map_err ( Box :: new ) . context ( InitDbError ) ? ; // there is still more work to do for this DB Ok ( InitProgress :: Unfinished ) } DatabaseStateCode :: Initialized => { // database fully initialized => nothing to do Ok ( InitProgress :: Done ) } } }
Try to make some progress in the DB init.
Try to make some progress in the DB init .
handle
&mut DatabaseHandle<'_>
root
&Path
wipe_on_error
bool
skip_replay_and_seek_instead
bool
handle
&mut DatabaseHandle<'_>
root
&Path
wipe_on_error
bool
skip_replay_and_seek_instead
bool