Merge pull request #1956 from ethcore/db-cache
Apply settings to column families
This commit is contained in:
commit
0c38197b43
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1223,7 +1223,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rocksdb"
|
name = "rocksdb"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
source = "git+https://github.com/ethcore/rust-rocksdb#84c5ac0bbd6901b6279a5480708e93eb3da6caa4"
|
source = "git+https://github.com/ethcore/rust-rocksdb#485dd747a2c9a9f910fc8ac696fc9edf5fa22aa3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rocksdb-sys 0.3.0 (git+https://github.com/ethcore/rust-rocksdb)",
|
"rocksdb-sys 0.3.0 (git+https://github.com/ethcore/rust-rocksdb)",
|
||||||
@ -1232,7 +1232,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rocksdb-sys"
|
name = "rocksdb-sys"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
source = "git+https://github.com/ethcore/rust-rocksdb#84c5ac0bbd6901b6279a5480708e93eb3da6caa4"
|
source = "git+https://github.com/ethcore/rust-rocksdb#485dd747a2c9a9f910fc8ac696fc9edf5fa22aa3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
|
"gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -214,20 +214,29 @@ impl Database {
|
|||||||
opts.create_if_missing(true);
|
opts.create_if_missing(true);
|
||||||
opts.set_use_fsync(false);
|
opts.set_use_fsync(false);
|
||||||
|
|
||||||
|
opts.set_max_background_flushes(DB_BACKGROUND_FLUSHES);
|
||||||
|
opts.set_max_background_compactions(DB_BACKGROUND_COMPACTIONS);
|
||||||
|
|
||||||
// compaction settings
|
// compaction settings
|
||||||
opts.set_compaction_style(DBCompactionStyle::DBUniversalCompaction);
|
opts.set_compaction_style(DBCompactionStyle::DBUniversalCompaction);
|
||||||
opts.set_target_file_size_base(config.compaction.initial_file_size);
|
opts.set_target_file_size_base(config.compaction.initial_file_size);
|
||||||
opts.set_target_file_size_multiplier(config.compaction.file_size_multiplier);
|
opts.set_target_file_size_multiplier(config.compaction.file_size_multiplier);
|
||||||
|
|
||||||
opts.set_max_background_flushes(DB_BACKGROUND_FLUSHES);
|
let mut cf_options = Vec::with_capacity(config.columns.unwrap_or(0) as usize);
|
||||||
opts.set_max_background_compactions(DB_BACKGROUND_COMPACTIONS);
|
|
||||||
|
|
||||||
|
for _ in 0 .. config.columns.unwrap_or(0) {
|
||||||
|
let mut opts = Options::new();
|
||||||
|
opts.set_compaction_style(DBCompactionStyle::DBUniversalCompaction);
|
||||||
|
opts.set_target_file_size_base(config.compaction.initial_file_size);
|
||||||
|
opts.set_target_file_size_multiplier(config.compaction.file_size_multiplier);
|
||||||
if let Some(cache_size) = config.cache_size {
|
if let Some(cache_size) = config.cache_size {
|
||||||
let mut block_opts = BlockBasedOptions::new();
|
let mut block_opts = BlockBasedOptions::new();
|
||||||
// all goes to read cache
|
// all goes to read cache
|
||||||
block_opts.set_cache(Cache::new(cache_size * 1024 * 1024));
|
block_opts.set_cache(Cache::new(cache_size * 1024 * 1024));
|
||||||
opts.set_block_based_table_factory(&block_opts);
|
opts.set_block_based_table_factory(&block_opts);
|
||||||
}
|
}
|
||||||
|
cf_options.push(opts);
|
||||||
|
}
|
||||||
|
|
||||||
let mut write_opts = WriteOptions::new();
|
let mut write_opts = WriteOptions::new();
|
||||||
if !config.wal {
|
if !config.wal {
|
||||||
@ -239,7 +248,7 @@ impl Database {
|
|||||||
Some(columns) => {
|
Some(columns) => {
|
||||||
let cfnames: Vec<_> = (0..columns).map(|c| format!("col{}", c)).collect();
|
let cfnames: Vec<_> = (0..columns).map(|c| format!("col{}", c)).collect();
|
||||||
let cfnames: Vec<&str> = cfnames.iter().map(|n| n as &str).collect();
|
let cfnames: Vec<&str> = cfnames.iter().map(|n| n as &str).collect();
|
||||||
match DB::open_cf(&opts, path, &cfnames) {
|
match DB::open_cf(&opts, path, &cfnames, &cf_options) {
|
||||||
Ok(db) => {
|
Ok(db) => {
|
||||||
cfs = cfnames.iter().map(|n| db.cf_handle(n).unwrap()).collect();
|
cfs = cfnames.iter().map(|n| db.cf_handle(n).unwrap()).collect();
|
||||||
assert!(cfs.len() == columns as usize);
|
assert!(cfs.len() == columns as usize);
|
||||||
@ -247,9 +256,9 @@ impl Database {
|
|||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// retry and create CFs
|
// retry and create CFs
|
||||||
match DB::open_cf(&opts, path, &[]) {
|
match DB::open_cf(&opts, path, &[], &[]) {
|
||||||
Ok(mut db) => {
|
Ok(mut db) => {
|
||||||
cfs = cfnames.iter().map(|n| db.create_cf(n, &opts).unwrap()).collect();
|
cfs = cfnames.iter().enumerate().map(|(i, n)| db.create_cf(n, &cf_options[i]).unwrap()).collect();
|
||||||
Ok(db)
|
Ok(db)
|
||||||
},
|
},
|
||||||
err @ Err(_) => err,
|
err @ Err(_) => err,
|
||||||
|
Loading…
Reference in New Issue
Block a user