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§
Provided Methods§
Sourcefn expensive(&self) -> bool
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.
Sourcefn run_in_background(&self) -> bool
fn run_in_background(&self) -> bool
Will this migration be executed in background.
Sourcefn stop_background(&self) -> bool
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.
Sourcefn can_resume(&self) -> bool
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.