Disable WAL (#1765)

* Disable WAL

* Make WAL optional

* Fix tests.

* Update cli.rs
This commit is contained in:
Arkadiy Paronyan 2016-07-29 15:36:00 +02:00 committed by GitHub
parent 29e07755e9
commit 57faa37623
10 changed files with 29 additions and 5 deletions

View File

@ -176,6 +176,7 @@ impl Client {
let mut db_config = DatabaseConfig::with_columns(DB_NO_OF_COLUMNS); let mut db_config = DatabaseConfig::with_columns(DB_NO_OF_COLUMNS);
db_config.cache_size = config.db_cache_size; db_config.cache_size = config.db_cache_size;
db_config.compaction = config.db_compaction.compaction_profile(); 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 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())); let chain = Arc::new(BlockChain::new(config.blockchain, &gb, db.clone()));

View File

@ -101,6 +101,8 @@ pub struct ClientConfig {
pub db_cache_size: Option<usize>, pub db_cache_size: Option<usize>,
/// State db compaction profile /// State db compaction profile
pub db_compaction: DatabaseCompactionProfile, pub db_compaction: DatabaseCompactionProfile,
/// Should db have WAL enabled?
pub db_wal: bool,
/// Operating mode /// Operating mode
pub mode: Mode, pub mode: Mode,
/// Type of block verifier used by client. /// Type of block verifier used by client.

View File

@ -76,6 +76,7 @@ pub struct ImportBlockchain {
pub format: Option<DataFormat>, pub format: Option<DataFormat>,
pub pruning: Pruning, pub pruning: Pruning,
pub compaction: DatabaseCompactionProfile, pub compaction: DatabaseCompactionProfile,
pub wal: bool,
pub mode: Mode, pub mode: Mode,
pub tracing: Switch, pub tracing: Switch,
pub vm_type: VMType, pub vm_type: VMType,
@ -91,6 +92,7 @@ pub struct ExportBlockchain {
pub format: Option<DataFormat>, pub format: Option<DataFormat>,
pub pruning: Pruning, pub pruning: Pruning,
pub compaction: DatabaseCompactionProfile, pub compaction: DatabaseCompactionProfile,
pub wal: bool,
pub mode: Mode, pub mode: Mode,
pub tracing: Switch, pub tracing: Switch,
pub from_block: BlockID, pub from_block: BlockID,
@ -129,7 +131,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
try!(execute_upgrades(&cmd.dirs, genesis_hash, spec.fork_name.as_ref(), algorithm, cmd.compaction.compaction_profile())); try!(execute_upgrades(&cmd.dirs, genesis_hash, spec.fork_name.as_ref(), algorithm, cmd.compaction.compaction_profile()));
// prepare client config // 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 // build client
let service = try!(ClientService::start( let service = try!(ClientService::start(
@ -240,7 +242,7 @@ fn execute_export(cmd: ExportBlockchain) -> Result<String, String> {
try!(execute_upgrades(&cmd.dirs, genesis_hash, spec.fork_name.as_ref(), algorithm, cmd.compaction.compaction_profile())); try!(execute_upgrades(&cmd.dirs, genesis_hash, spec.fork_name.as_ref(), algorithm, cmd.compaction.compaction_profile()));
// prepare client config // 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( let service = try!(ClientService::start(
client_config, client_config,

View File

@ -210,8 +210,8 @@ Footprint Options:
--cache-size MB Set total amount of discretionary memory to use for --cache-size MB Set total amount of discretionary memory to use for
the entire system, overrides other cache and queue the entire system, overrides other cache and queue
options. options.
--fast-and-loose Disables DB WAL, which gives a significant speed up
Database Options: but means an unclean exit is unrecoverable.
--db-compaction TYPE Database compaction type. TYPE may be one of: --db-compaction TYPE Database compaction type. TYPE may be one of:
ssd - suitable for SSDs and fast HDDs; ssd - suitable for SSDs and fast HDDs;
hdd - suitable for slow HDDs [default: ssd]. hdd - suitable for slow HDDs [default: ssd].
@ -314,6 +314,7 @@ pub struct Args {
pub flag_cache_size_queue: u32, pub flag_cache_size_queue: u32,
pub flag_cache_size: Option<u32>, pub flag_cache_size: Option<u32>,
pub flag_cache: Option<u32>, pub flag_cache: Option<u32>,
pub flag_fast_and_loose: bool,
pub flag_no_jsonrpc: bool, pub flag_no_jsonrpc: bool,
pub flag_jsonrpc_interface: String, pub flag_jsonrpc_interface: String,

View File

@ -81,6 +81,7 @@ impl Configuration {
let spec = try!(self.chain().parse()); let spec = try!(self.chain().parse());
let tracing = try!(self.args.flag_tracing.parse()); let tracing = try!(self.args.flag_tracing.parse());
let compaction = try!(self.args.flag_db_compaction.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 enable_network = self.enable_network(&mode);
let geth_compatibility = self.args.flag_geth; let geth_compatibility = self.args.flag_geth;
let signer_port = self.signer_port(); let signer_port = self.signer_port();
@ -129,6 +130,7 @@ impl Configuration {
format: None, format: None,
pruning: pruning, pruning: pruning,
compaction: compaction, compaction: compaction,
wal: wal,
mode: mode, mode: mode,
tracing: tracing, tracing: tracing,
vm_type: vm_type, vm_type: vm_type,
@ -144,6 +146,7 @@ impl Configuration {
format: None, format: None,
pruning: pruning, pruning: pruning,
compaction: compaction, compaction: compaction,
wal: wal,
mode: mode, mode: mode,
tracing: tracing, tracing: tracing,
from_block: try!(to_block_id(&self.args.flag_from)), from_block: try!(to_block_id(&self.args.flag_from)),
@ -175,6 +178,7 @@ impl Configuration {
mode: mode, mode: mode,
tracing: tracing, tracing: tracing,
compaction: compaction, compaction: compaction,
wal: wal,
vm_type: vm_type, vm_type: vm_type,
enable_network: enable_network, enable_network: enable_network,
geth_compatibility: geth_compatibility, geth_compatibility: geth_compatibility,
@ -613,6 +617,7 @@ mod tests {
format: None, format: None,
pruning: Default::default(), pruning: Default::default(),
compaction: Default::default(), compaction: Default::default(),
wal: true,
mode: Default::default(), mode: Default::default(),
tracing: Default::default(), tracing: Default::default(),
vm_type: VMType::Interpreter, vm_type: VMType::Interpreter,
@ -632,6 +637,7 @@ mod tests {
pruning: Default::default(), pruning: Default::default(),
format: Default::default(), format: Default::default(),
compaction: Default::default(), compaction: Default::default(),
wal: true,
mode: Default::default(), mode: Default::default(),
tracing: Default::default(), tracing: Default::default(),
from_block: BlockID::Number(1), from_block: BlockID::Number(1),
@ -669,6 +675,7 @@ mod tests {
mode: Default::default(), mode: Default::default(),
tracing: Default::default(), tracing: Default::default(),
compaction: Default::default(), compaction: Default::default(),
wal: true,
vm_type: Default::default(), vm_type: Default::default(),
enable_network: true, enable_network: true,
geth_compatibility: false, geth_compatibility: false,

View File

@ -193,6 +193,7 @@ pub fn to_client_config(
tracing: Switch, tracing: Switch,
pruning: Pruning, pruning: Pruning,
compaction: DatabaseCompactionProfile, compaction: DatabaseCompactionProfile,
wal: bool,
vm_type: VMType, vm_type: VMType,
name: String, name: String,
fork_name: Option<&String>, fork_name: Option<&String>,
@ -215,6 +216,7 @@ pub fn to_client_config(
client_config.tracing.enabled = tracing; client_config.tracing.enabled = tracing;
client_config.pruning = pruning.to_algorithm(dirs, genesis_hash, fork_name); client_config.pruning = pruning.to_algorithm(dirs, genesis_hash, fork_name);
client_config.db_compaction = compaction; client_config.db_compaction = compaction;
client_config.db_wal = wal;
client_config.vm_type = vm_type; client_config.vm_type = vm_type;
client_config.name = name; client_config.name = name;
client_config client_config

View File

@ -163,6 +163,7 @@ fn consolidate_database(
cache_size: None, cache_size: None,
compaction: config.compaction_profile.clone(), compaction: config.compaction_profile.clone(),
columns: None, columns: None,
wal: true,
}; };
let old_path_str = try!(old_db_path.to_str().ok_or(Error::MigrationImpossible)); let old_path_str = try!(old_db_path.to_str().ok_or(Error::MigrationImpossible));

View File

@ -67,6 +67,7 @@ pub struct RunCmd {
pub mode: Mode, pub mode: Mode,
pub tracing: Switch, pub tracing: Switch,
pub compaction: DatabaseCompactionProfile, pub compaction: DatabaseCompactionProfile,
pub wal: bool,
pub vm_type: VMType, pub vm_type: VMType,
pub enable_network: bool, pub enable_network: bool,
pub geth_compatibility: bool, pub geth_compatibility: bool,
@ -153,6 +154,7 @@ pub fn execute(cmd: RunCmd) -> Result<(), String> {
cmd.tracing, cmd.tracing,
cmd.pruning, cmd.pruning,
cmd.compaction, cmd.compaction,
cmd.wal,
cmd.vm_type, cmd.vm_type,
cmd.name, cmd.name,
fork_name.as_ref(), fork_name.as_ref(),

View File

@ -93,6 +93,8 @@ pub struct DatabaseConfig {
pub compaction: CompactionProfile, pub compaction: CompactionProfile,
/// Set number of columns /// Set number of columns
pub columns: Option<u32>, pub columns: Option<u32>,
/// Should we keep WAL enabled?
pub wal: bool,
} }
impl DatabaseConfig { impl DatabaseConfig {
@ -111,6 +113,7 @@ impl Default for DatabaseConfig {
max_open_files: 1024, max_open_files: 1024,
compaction: CompactionProfile::default(), compaction: CompactionProfile::default(),
columns: None, columns: None,
wal: true,
} }
} }
} }
@ -167,7 +170,9 @@ impl Database {
} }
let mut write_opts = WriteOptions::new(); 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<Column> = Vec::new(); let mut cfs: Vec<Column> = Vec::new();
let db = match config.columns { let db = match config.columns {

View File

@ -213,6 +213,7 @@ impl Manager {
cache_size: None, cache_size: None,
compaction: config.compaction_profile, compaction: config.compaction_profile,
columns: columns, columns: columns,
wal: true,
}; };
let db_root = database_path(old_path); let db_root = database_path(old_path);