different migrations based on pruning

This commit is contained in:
Robert Habermeier 2016-07-05 19:21:18 +02:00
parent e151fbb071
commit a7103e2870
7 changed files with 27 additions and 20 deletions

View File

@ -2,4 +2,4 @@
mod v7; mod v7;
pub use self::v7::ToV7; pub use self::v7::ArchiveV7;

View File

@ -3,10 +3,10 @@ use util::migration::SimpleMigration;
use util::sha3::Hashable; use util::sha3::Hashable;
/// This migration migrates the state db to use an accountdb which ensures uniqueness /// This migration migrates the state db to use an accountdb which ensures uniqueness
/// using an address' hash as opposed to the address itself. /// using an address' hash as opposed to the address itself. Works only for ArchiveDB.
pub struct ToV7; pub struct ArchiveV7;
impl SimpleMigration for ToV7 { impl SimpleMigration for ArchiveV7 {
fn version(&self) -> u32 { fn version(&self) -> u32 {
7 7
} }

View File

@ -280,7 +280,7 @@ impl Configuration {
ret ret
} }
pub fn find_best_db(&self, spec: &Spec) -> Option<journaldb::Algorithm> { fn find_best_db(&self, spec: &Spec) -> Option<journaldb::Algorithm> {
let mut ret = None; let mut ret = None;
let mut latest_era = None; let mut latest_era = None;
let jdb_types = [journaldb::Algorithm::Archive, journaldb::Algorithm::EarlyMerge, journaldb::Algorithm::OverlayRecent, journaldb::Algorithm::RefCounted]; let jdb_types = [journaldb::Algorithm::Archive, journaldb::Algorithm::EarlyMerge, journaldb::Algorithm::OverlayRecent, journaldb::Algorithm::RefCounted];
@ -299,6 +299,17 @@ impl Configuration {
ret ret
} }
pub fn pruning_algorithm(&self, spec: &Spec) -> journaldb::Algorithm {
match self.args.flag_pruning.as_str() {
"archive" => journaldb::Algorithm::Archive,
"light" => journaldb::Algorithm::EarlyMerge,
"fast" => journaldb::Algorithm::OverlayRecent,
"basic" => journaldb::Algorithm::RefCounted,
"auto" => self.find_best_db(spec).unwrap_or(journaldb::Algorithm::OverlayRecent),
_ => { die!("Invalid pruning method given."); }
}
}
pub fn client_config(&self, spec: &Spec) -> ClientConfig { pub fn client_config(&self, spec: &Spec) -> ClientConfig {
let mut client_config = ClientConfig::default(); let mut client_config = ClientConfig::default();
@ -324,14 +335,7 @@ impl Configuration {
// forced trace db cache size if provided // forced trace db cache size if provided
client_config.tracing.db_cache_size = self.args.flag_db_cache_size.and_then(|cs| Some(cs / 4)); client_config.tracing.db_cache_size = self.args.flag_db_cache_size.and_then(|cs| Some(cs / 4));
client_config.pruning = match self.args.flag_pruning.as_str() { client_config.pruning = self.pruning_algorithm(spec);
"archive" => journaldb::Algorithm::Archive,
"light" => journaldb::Algorithm::EarlyMerge,
"fast" => journaldb::Algorithm::OverlayRecent,
"basic" => journaldb::Algorithm::RefCounted,
"auto" => self.find_best_db(spec).unwrap_or(journaldb::Algorithm::OverlayRecent),
_ => { die!("Invalid pruning method given."); }
};
if self.args.flag_fat_db { if self.args.flag_fat_db {
if let journaldb::Algorithm::Archive = client_config.pruning { if let journaldb::Algorithm::Archive = client_config.pruning {

View File

@ -22,7 +22,7 @@ use std::process::exit;
#[macro_export] #[macro_export]
macro_rules! die { macro_rules! die {
($($arg:tt)*) => (die_with_message(&format!("{}", format_args!($($arg)*)))); ($($arg:tt)*) => (::die::die_with_message(&format!("{}", format_args!($($arg)*))));
} }
pub fn die_with_error(module: &'static str, e: ethcore::error::Error) -> ! { pub fn die_with_error(module: &'static str, e: ethcore::error::Error) -> ! {

View File

@ -173,7 +173,7 @@ fn execute_upgrades(conf: &Configuration, spec: &Spec, client_config: &ClientCon
} }
let db_path = get_db_path(Path::new(&conf.path()), client_config.pruning, spec.genesis_header().hash()); let db_path = get_db_path(Path::new(&conf.path()), client_config.pruning, spec.genesis_header().hash());
let result = migrate(&db_path); let result = migrate(&db_path, client_config.pruning);
if let Err(err) = result { if let Err(err) = result {
die_with_message(&format!("{}", err)); die_with_message(&format!("{}", err));
} }

View File

@ -19,6 +19,7 @@ use std::fs::File;
use std::io::{Read, Write, Error as IoError, ErrorKind}; use std::io::{Read, Write, Error as IoError, ErrorKind};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::fmt::{Display, Formatter, Error as FmtError}; use std::fmt::{Display, Formatter, Error as FmtError};
use util::journaldb::Algorithm;
use util::migration::{Manager as MigrationManager, Config as MigrationConfig, Error as MigrationError}; use util::migration::{Manager as MigrationManager, Config as MigrationConfig, Error as MigrationError};
use ethcore::migrations; use ethcore::migrations;
@ -153,9 +154,12 @@ fn extras_database_migrations() -> Result<MigrationManager, Error> {
} }
/// Migrations on the state database. /// Migrations on the state database.
fn state_database_migrations() -> Result<MigrationManager, Error> { fn state_database_migrations(pruning: Algorithm) -> Result<MigrationManager, Error> {
let mut manager = MigrationManager::new(default_migration_settings()); let mut manager = MigrationManager::new(default_migration_settings());
try!(manager.add_migration(migrations::state::ToV7).map_err(|_| Error::MigrationImpossible)); match pruning {
Algorithm::Archive => try!(manager.add_migration(migrations::state::ArchiveV7).map_err(|_| Error::MigrationImpossible)),
_ => die!("Unsupported pruning method for migration. Delete DB and resync"),
}
Ok(manager) Ok(manager)
} }
@ -194,7 +198,7 @@ fn exists(path: &Path) -> bool {
} }
/// Migrates the database. /// Migrates the database.
pub fn migrate(path: &Path) -> Result<(), Error> { pub fn migrate(path: &Path, pruning: Algorithm) -> Result<(), Error> {
// read version file. // read version file.
let version = try!(current_version(path)); let version = try!(current_version(path));
@ -204,7 +208,7 @@ pub fn migrate(path: &Path) -> Result<(), Error> {
println!("Migrating database from version {} to {}", version, CURRENT_VERSION); println!("Migrating database from version {} to {}", version, CURRENT_VERSION);
try!(migrate_database(version, blocks_database_path(path), try!(blocks_database_migrations()))); try!(migrate_database(version, blocks_database_path(path), try!(blocks_database_migrations())));
try!(migrate_database(version, extras_database_path(path), try!(extras_database_migrations()))); try!(migrate_database(version, extras_database_path(path), try!(extras_database_migrations())));
try!(migrate_database(version, state_database_path(path), try!(state_database_migrations()))); try!(migrate_database(version, state_database_path(path), try!(state_database_migrations(pruning))));
println!("Migration finished"); println!("Migration finished");
} }

View File

@ -18,7 +18,6 @@ use std::collections::BTreeMap;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use die::*;
use ethsync::EthSync; use ethsync::EthSync;
use ethcore::miner::{Miner, ExternalMiner}; use ethcore::miner::{Miner, ExternalMiner};
use ethcore::client::Client; use ethcore::client::Client;