From 57faa376235f6c766173b079593d43eb7c143220 Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Fri, 29 Jul 2016 15:36:00 +0200 Subject: [PATCH] Disable WAL (#1765) * Disable WAL * Make WAL optional * Fix tests. * Update cli.rs --- ethcore/src/client/client.rs | 1 + ethcore/src/client/config.rs | 2 ++ parity/blockchain.rs | 6 ++++-- parity/cli.rs | 5 +++-- parity/configuration.rs | 7 +++++++ parity/helpers.rs | 2 ++ parity/migration.rs | 1 + parity/run.rs | 2 ++ util/src/kvdb.rs | 7 ++++++- util/src/migration/mod.rs | 1 + 10 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 3ff6b9733..3b4a40d90 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -176,6 +176,7 @@ impl Client { let mut db_config = DatabaseConfig::with_columns(DB_NO_OF_COLUMNS); db_config.cache_size = config.db_cache_size; db_config.compaction = config.db_compaction.compaction_profile(); + db_config.wal = config.db_wal; let db = Arc::new(Database::open(&db_config, &path.to_str().unwrap()).expect("Error opening database")); let chain = Arc::new(BlockChain::new(config.blockchain, &gb, db.clone())); diff --git a/ethcore/src/client/config.rs b/ethcore/src/client/config.rs index 220f6f1eb..504ca4de7 100644 --- a/ethcore/src/client/config.rs +++ b/ethcore/src/client/config.rs @@ -101,6 +101,8 @@ pub struct ClientConfig { pub db_cache_size: Option, /// State db compaction profile pub db_compaction: DatabaseCompactionProfile, + /// Should db have WAL enabled? + pub db_wal: bool, /// Operating mode pub mode: Mode, /// Type of block verifier used by client. diff --git a/parity/blockchain.rs b/parity/blockchain.rs index 0e036cf35..90ca809c1 100644 --- a/parity/blockchain.rs +++ b/parity/blockchain.rs @@ -76,6 +76,7 @@ pub struct ImportBlockchain { pub format: Option, pub pruning: Pruning, pub compaction: DatabaseCompactionProfile, + pub wal: bool, pub mode: Mode, pub tracing: Switch, pub vm_type: VMType, @@ -91,6 +92,7 @@ pub struct ExportBlockchain { pub format: Option, pub pruning: Pruning, pub compaction: DatabaseCompactionProfile, + pub wal: bool, pub mode: Mode, pub tracing: Switch, pub from_block: BlockID, @@ -129,7 +131,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result { try!(execute_upgrades(&cmd.dirs, genesis_hash, spec.fork_name.as_ref(), algorithm, cmd.compaction.compaction_profile())); // prepare client config - let client_config = to_client_config(&cmd.cache_config, &cmd.dirs, genesis_hash, cmd.mode, cmd.tracing, cmd.pruning, cmd.compaction, cmd.vm_type, "".into(), spec.fork_name.as_ref()); + let client_config = to_client_config(&cmd.cache_config, &cmd.dirs, genesis_hash, cmd.mode, cmd.tracing, cmd.pruning, cmd.compaction, cmd.wal, cmd.vm_type, "".into(), spec.fork_name.as_ref()); // build client let service = try!(ClientService::start( @@ -240,7 +242,7 @@ fn execute_export(cmd: ExportBlockchain) -> Result { try!(execute_upgrades(&cmd.dirs, genesis_hash, spec.fork_name.as_ref(), algorithm, cmd.compaction.compaction_profile())); // prepare client config - let client_config = to_client_config(&cmd.cache_config, &cmd.dirs, genesis_hash, cmd.mode, cmd.tracing, cmd.pruning, cmd.compaction, VMType::default(), "".into(), spec.fork_name.as_ref()); + let client_config = to_client_config(&cmd.cache_config, &cmd.dirs, genesis_hash, cmd.mode, cmd.tracing, cmd.pruning, cmd.compaction, cmd.wal, VMType::default(), "".into(), spec.fork_name.as_ref()); let service = try!(ClientService::start( client_config, diff --git a/parity/cli.rs b/parity/cli.rs index eeab2563a..650c19f94 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -210,8 +210,8 @@ Footprint Options: --cache-size MB Set total amount of discretionary memory to use for the entire system, overrides other cache and queue options. - -Database Options: + --fast-and-loose Disables DB WAL, which gives a significant speed up + but means an unclean exit is unrecoverable. --db-compaction TYPE Database compaction type. TYPE may be one of: ssd - suitable for SSDs and fast HDDs; hdd - suitable for slow HDDs [default: ssd]. @@ -314,6 +314,7 @@ pub struct Args { pub flag_cache_size_queue: u32, pub flag_cache_size: Option, pub flag_cache: Option, + pub flag_fast_and_loose: bool, pub flag_no_jsonrpc: bool, pub flag_jsonrpc_interface: String, diff --git a/parity/configuration.rs b/parity/configuration.rs index 9e779ef91..d366da2a6 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -81,6 +81,7 @@ impl Configuration { let spec = try!(self.chain().parse()); let tracing = try!(self.args.flag_tracing.parse()); let compaction = try!(self.args.flag_db_compaction.parse()); + let wal = !self.args.flag_fast_and_loose; let enable_network = self.enable_network(&mode); let geth_compatibility = self.args.flag_geth; let signer_port = self.signer_port(); @@ -129,6 +130,7 @@ impl Configuration { format: None, pruning: pruning, compaction: compaction, + wal: wal, mode: mode, tracing: tracing, vm_type: vm_type, @@ -144,6 +146,7 @@ impl Configuration { format: None, pruning: pruning, compaction: compaction, + wal: wal, mode: mode, tracing: tracing, from_block: try!(to_block_id(&self.args.flag_from)), @@ -175,6 +178,7 @@ impl Configuration { mode: mode, tracing: tracing, compaction: compaction, + wal: wal, vm_type: vm_type, enable_network: enable_network, geth_compatibility: geth_compatibility, @@ -613,6 +617,7 @@ mod tests { format: None, pruning: Default::default(), compaction: Default::default(), + wal: true, mode: Default::default(), tracing: Default::default(), vm_type: VMType::Interpreter, @@ -632,6 +637,7 @@ mod tests { pruning: Default::default(), format: Default::default(), compaction: Default::default(), + wal: true, mode: Default::default(), tracing: Default::default(), from_block: BlockID::Number(1), @@ -669,6 +675,7 @@ mod tests { mode: Default::default(), tracing: Default::default(), compaction: Default::default(), + wal: true, vm_type: Default::default(), enable_network: true, geth_compatibility: false, diff --git a/parity/helpers.rs b/parity/helpers.rs index 881dd9c8f..b7b56df32 100644 --- a/parity/helpers.rs +++ b/parity/helpers.rs @@ -193,6 +193,7 @@ pub fn to_client_config( tracing: Switch, pruning: Pruning, compaction: DatabaseCompactionProfile, + wal: bool, vm_type: VMType, name: String, fork_name: Option<&String>, @@ -215,6 +216,7 @@ pub fn to_client_config( client_config.tracing.enabled = tracing; client_config.pruning = pruning.to_algorithm(dirs, genesis_hash, fork_name); client_config.db_compaction = compaction; + client_config.db_wal = wal; client_config.vm_type = vm_type; client_config.name = name; client_config diff --git a/parity/migration.rs b/parity/migration.rs index cbfa78ccc..b073b8dbf 100644 --- a/parity/migration.rs +++ b/parity/migration.rs @@ -163,6 +163,7 @@ fn consolidate_database( cache_size: None, compaction: config.compaction_profile.clone(), columns: None, + wal: true, }; let old_path_str = try!(old_db_path.to_str().ok_or(Error::MigrationImpossible)); diff --git a/parity/run.rs b/parity/run.rs index 03690e8f9..45b844ef0 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -67,6 +67,7 @@ pub struct RunCmd { pub mode: Mode, pub tracing: Switch, pub compaction: DatabaseCompactionProfile, + pub wal: bool, pub vm_type: VMType, pub enable_network: bool, pub geth_compatibility: bool, @@ -153,6 +154,7 @@ pub fn execute(cmd: RunCmd) -> Result<(), String> { cmd.tracing, cmd.pruning, cmd.compaction, + cmd.wal, cmd.vm_type, cmd.name, fork_name.as_ref(), diff --git a/util/src/kvdb.rs b/util/src/kvdb.rs index 744966de4..a87796324 100644 --- a/util/src/kvdb.rs +++ b/util/src/kvdb.rs @@ -93,6 +93,8 @@ pub struct DatabaseConfig { pub compaction: CompactionProfile, /// Set number of columns pub columns: Option, + /// Should we keep WAL enabled? + pub wal: bool, } impl DatabaseConfig { @@ -111,6 +113,7 @@ impl Default for DatabaseConfig { max_open_files: 1024, compaction: CompactionProfile::default(), columns: None, + wal: true, } } } @@ -167,7 +170,9 @@ impl Database { } let mut write_opts = WriteOptions::new(); - write_opts.disable_wal(true); // TODO: make sure this is safe + if !config.wal { + write_opts.disable_wal(true); + } let mut cfs: Vec = Vec::new(); let db = match config.columns { diff --git a/util/src/migration/mod.rs b/util/src/migration/mod.rs index 5a4ba2ecc..6072041a3 100644 --- a/util/src/migration/mod.rs +++ b/util/src/migration/mod.rs @@ -213,6 +213,7 @@ impl Manager { cache_size: None, compaction: config.compaction_profile, columns: columns, + wal: true, }; let db_root = database_path(old_path);