jdb to new settings config

This commit is contained in:
Nikolay Volf 2016-06-27 13:23:50 +02:00
parent 07098fd16f
commit 627b67db0a
6 changed files with 18 additions and 35 deletions

View File

@ -43,13 +43,8 @@ const DB_VERSION : u32 = 0x103;
impl ArchiveDB { impl ArchiveDB {
/// Create a new instance from file /// Create a new instance from file
pub fn new(path: &str, cache_size: Option<usize>) -> ArchiveDB { pub fn new(path: &str, config: DatabaseConfig) -> ArchiveDB {
let opts = DatabaseConfig { let opts = config.prefix(DB_PREFIX_LEN);
// this must match account_db prefix
prefix_size: Some(DB_PREFIX_LEN),
max_open_files: 256,
cache_size: cache_size,
};
let backing = Database::open(&opts, path).unwrap_or_else(|e| { let backing = Database::open(&opts, path).unwrap_or_else(|e| {
panic!("Error opening state db: {}", e); panic!("Error opening state db: {}", e);
}); });

View File

@ -73,13 +73,8 @@ const PADDING : [u8; 10] = [ 0u8; 10 ];
impl EarlyMergeDB { impl EarlyMergeDB {
/// Create a new instance from file /// Create a new instance from file
pub fn new(path: &str, cache_size: Option<usize>) -> EarlyMergeDB { pub fn new(path: &str, config: DatabaseConfig) -> EarlyMergeDB {
let opts = DatabaseConfig { let opts = config.prefix(DB_PREFIX_LEN);
// this must match account_db prefix
prefix_size: Some(DB_PREFIX_LEN),
max_open_files: 256,
cache_size: cache_size,
};
let backing = Database::open(&opts, path).unwrap_or_else(|e| { let backing = Database::open(&opts, path).unwrap_or_else(|e| {
panic!("Error opening state db: {}", e); panic!("Error opening state db: {}", e);
}); });

View File

@ -17,6 +17,7 @@
//! `JournalDB` interface and implementation. //! `JournalDB` interface and implementation.
use common::*; use common::*;
use kvdb::DatabaseConfig;
/// Export the journaldb module. /// Export the journaldb module.
pub mod traits; pub mod traits;
@ -71,12 +72,12 @@ impl fmt::Display for Algorithm {
} }
/// Create a new `JournalDB` trait object. /// Create a new `JournalDB` trait object.
pub fn new(path: &str, algorithm: Algorithm, cache_size: Option<usize>) -> Box<JournalDB> { pub fn new(path: &str, algorithm: Algorithm, config: DatabaseConfig) -> Box<JournalDB> {
match algorithm { match algorithm {
Algorithm::Archive => Box::new(archivedb::ArchiveDB::new(path, cache_size)), Algorithm::Archive => Box::new(archivedb::ArchiveDB::new(path, config)),
Algorithm::EarlyMerge => Box::new(earlymergedb::EarlyMergeDB::new(path, cache_size)), Algorithm::EarlyMerge => Box::new(earlymergedb::EarlyMergeDB::new(path, config)),
Algorithm::OverlayRecent => Box::new(overlayrecentdb::OverlayRecentDB::new(path, cache_size)), Algorithm::OverlayRecent => Box::new(overlayrecentdb::OverlayRecentDB::new(path, config)),
Algorithm::RefCounted => Box::new(refcounteddb::RefCountedDB::new(path, cache_size)), Algorithm::RefCounted => Box::new(refcounteddb::RefCountedDB::new(path, config)),
} }
} }

View File

@ -98,18 +98,13 @@ const PADDING : [u8; 10] = [ 0u8; 10 ];
impl OverlayRecentDB { impl OverlayRecentDB {
/// Create a new instance from file /// Create a new instance from file
pub fn new(path: &str, cache_size: Option<usize>) -> OverlayRecentDB { pub fn new(path: &str, config: DatabaseConfig) -> OverlayRecentDB {
Self::from_prefs(path, cache_size) Self::from_prefs(path, config)
} }
/// Create a new instance from file /// Create a new instance from file
pub fn from_prefs(path: &str, cache_size: Option<usize>) -> OverlayRecentDB { pub fn from_prefs(path: &str, config: DatabaseConfig) -> OverlayRecentDB {
let opts = DatabaseConfig { let opts = config.prefix(DB_PREFIX_LEN);
// this must match account_db prefix
prefix_size: Some(DB_PREFIX_LEN),
max_open_files: 256,
cache_size: cache_size,
};
let backing = Database::open(&opts, path).unwrap_or_else(|e| { let backing = Database::open(&opts, path).unwrap_or_else(|e| {
panic!("Error opening state db: {}", e); panic!("Error opening state db: {}", e);
}); });

View File

@ -46,13 +46,8 @@ const PADDING : [u8; 10] = [ 0u8; 10 ];
impl RefCountedDB { impl RefCountedDB {
/// Create a new instance given a `backing` database. /// Create a new instance given a `backing` database.
pub fn new(path: &str, cache_size: Option<usize>) -> RefCountedDB { pub fn new(path: &str, config: DatabaseConfig) -> RefCountedDB {
let opts = DatabaseConfig { let opts = config.prefix(DB_PREFIX_LEN);
// this must match account_db prefix
prefix_size: Some(DB_PREFIX_LEN),
max_open_files: 256,
cache_size: cache_size,
};
let backing = Database::open(&opts, path).unwrap_or_else(|e| { let backing = Database::open(&opts, path).unwrap_or_else(|e| {
panic!("Error opening state db: {}", e); panic!("Error opening state db: {}", e);
}); });

View File

@ -104,11 +104,13 @@ impl DatabaseConfig {
} }
} }
/// Modify the compaction profile
pub fn compaction(mut self, profile: CompactionProfile) -> Self { pub fn compaction(mut self, profile: CompactionProfile) -> Self {
self.compaction = profile; self.compaction = profile;
self self
} }
/// Modify the prefix of the db
pub fn prefix(mut self, prefix_size: usize) -> Self { pub fn prefix(mut self, prefix_size: usize) -> Self {
self.prefix_size = Some(prefix_size); self.prefix_size = Some(prefix_size);
self self