Trait ckb_db_migration::Migration

source ·
pub trait Migration: Send + Sync {
    // Required methods
    fn migrate(
        &self,
        _db: RocksDB,
        _pb: Arc<dyn Fn(u64) -> ProgressBar + Send + Sync>
    ) -> Result<RocksDB, Error>;
    fn version(&self) -> &str;

    // Provided methods
    fn expensive(&self) -> bool { ... }
    fn run_in_background(&self) -> bool { ... }
    fn stop_background(&self) -> bool { ... }
    fn can_resume(&self) -> bool { ... }
}
Expand description

TODO(doc): @quake

Required Methods§

source

fn migrate( &self, _db: RocksDB, _pb: Arc<dyn Fn(u64) -> ProgressBar + Send + Sync> ) -> Result<RocksDB, Error>

TODO(doc): @quake

source

fn version(&self) -> &str

returns migration version, use date +'%Y%m%d%H%M%S' timestamp format

Provided Methods§

source

fn expensive(&self) -> bool

Will cost a lot of time to perform this migration operation.

Override this function for Migrations which could be executed very fast.

source

fn run_in_background(&self) -> bool

Will this migration be executed in background.

source

fn stop_background(&self) -> bool

Check if the background migration should be stopped. If a migration need to implement the recovery logic, it should check this flag periodically, store the migration progress when exiting and recover from the current progress when restarting.

source

fn can_resume(&self) -> bool

Check if the background migration can be resumed.

If a migration can be resumed, it should implement the recovery logic in migrate function. and the MigirateWorker will add the migration’s handler with register_thread, so that then main thread can wait for the background migration to store the progress and exit.

Otherwise, the migration will be restarted from the beginning.

Implementors§