Merge pull request #1594 from rphmeier/migration_progress

V7 Migration progress indicator
This commit is contained in:
Tomasz Drwięga 2016-07-12 17:23:03 +02:00 committed by GitHub
commit 4cf8df87e5
2 changed files with 17 additions and 3 deletions

View File

@ -61,8 +61,9 @@ fn attempt_migrate(mut key_h: H256, val: &[u8]) -> Option<H256> {
}
}
/// Version for `ArchiveDB`.
pub struct ArchiveV7;
/// Version for ArchiveDB.
#[derive(Default)]
pub struct ArchiveV7(usize);
impl SimpleMigration for ArchiveV7 {
fn version(&self) -> u32 {
@ -70,6 +71,12 @@ impl SimpleMigration for ArchiveV7 {
}
fn simple_migrate(&mut self, key: Vec<u8>, value: Vec<u8>) -> Option<(Vec<u8>, Vec<u8>)> {
self.0 += 1;
if self.0 == 100_000 {
self.0 = 0;
flush!(".");
}
if key.len() != 32 {
// metadata key, ignore.
return Some((key, value));
@ -228,7 +235,14 @@ impl Migration for OverlayRecentV7 {
_ => return Err(Error::MigrationImpossible), // missing or wrong version
}
let mut count = 0;
for (key, value) in source.iter() {
count += 1;
if count == 100_000 {
count = 0;
flush!(".");
}
let mut key = key.into_vec();
if key.len() == 32 {
let key_h = H256::from_slice(&key[..]);

View File

@ -157,7 +157,7 @@ fn extras_database_migrations() -> Result<MigrationManager, Error> {
fn state_database_migrations(pruning: Algorithm) -> Result<MigrationManager, Error> {
let mut manager = MigrationManager::new(default_migration_settings());
let res = match pruning {
Algorithm::Archive => manager.add_migration(migrations::state::ArchiveV7),
Algorithm::Archive => manager.add_migration(migrations::state::ArchiveV7::default()),
Algorithm::OverlayRecent => manager.add_migration(migrations::state::OverlayRecentV7::default()),
_ => die!("Unsupported pruning method for migration. Delete DB and resync"),
};