migration fixes (#1155)
* dont use system temp for migration, do backup * fixed issue with number of open files on osx * fixed compilation of util tests
This commit is contained in:
@@ -47,7 +47,9 @@ impl ArchiveDB {
|
||||
/// Create a new instance from file
|
||||
pub fn new(path: &str) -> ArchiveDB {
|
||||
let opts = DatabaseConfig {
|
||||
prefix_size: Some(12) //use 12 bytes as prefix, this must match account_db prefix
|
||||
//use 12 bytes as prefix, this must match account_db prefix
|
||||
prefix_size: Some(12),
|
||||
max_open_files: 256,
|
||||
};
|
||||
let backing = Database::open(&opts, path).unwrap_or_else(|e| {
|
||||
panic!("Error opening state db: {}", e);
|
||||
|
||||
@@ -77,7 +77,9 @@ impl EarlyMergeDB {
|
||||
/// Create a new instance from file
|
||||
pub fn new(path: &str) -> EarlyMergeDB {
|
||||
let opts = DatabaseConfig {
|
||||
prefix_size: Some(12) //use 12 bytes as prefix, this must match account_db prefix
|
||||
//use 12 bytes as prefix, this must match account_db prefix
|
||||
prefix_size: Some(12),
|
||||
max_open_files: 256,
|
||||
};
|
||||
let backing = Database::open(&opts, path).unwrap_or_else(|e| {
|
||||
panic!("Error opening state db: {}", e);
|
||||
|
||||
@@ -107,7 +107,9 @@ impl OverlayRecentDB {
|
||||
/// Create a new instance from file
|
||||
pub fn from_prefs(path: &str) -> OverlayRecentDB {
|
||||
let opts = DatabaseConfig {
|
||||
prefix_size: Some(12) //use 12 bytes as prefix, this must match account_db prefix
|
||||
//use 12 bytes as prefix, this must match account_db prefix
|
||||
prefix_size: Some(12),
|
||||
max_open_files: 256,
|
||||
};
|
||||
let backing = Database::open(&opts, path).unwrap_or_else(|e| {
|
||||
panic!("Error opening state db: {}", e);
|
||||
|
||||
@@ -49,7 +49,9 @@ impl RefCountedDB {
|
||||
/// Create a new instance given a `backing` database.
|
||||
pub fn new(path: &str) -> RefCountedDB {
|
||||
let opts = DatabaseConfig {
|
||||
prefix_size: Some(12) //use 12 bytes as prefix, this must match account_db prefix
|
||||
//use 12 bytes as prefix, this must match account_db prefix
|
||||
prefix_size: Some(12),
|
||||
max_open_files: 256,
|
||||
};
|
||||
let backing = Database::open(&opts, path).unwrap_or_else(|e| {
|
||||
panic!("Error opening state db: {}", e);
|
||||
|
||||
@@ -51,7 +51,9 @@ impl DBTransaction {
|
||||
/// Database configuration
|
||||
pub struct DatabaseConfig {
|
||||
/// Optional prefix size in bytes. Allows lookup by partial key.
|
||||
pub prefix_size: Option<usize>
|
||||
pub prefix_size: Option<usize>,
|
||||
/// Max number of open files.
|
||||
pub max_open_files: i32,
|
||||
}
|
||||
|
||||
/// Database iterator
|
||||
@@ -75,13 +77,13 @@ pub struct Database {
|
||||
impl Database {
|
||||
/// Open database with default settings.
|
||||
pub fn open_default(path: &str) -> Result<Database, String> {
|
||||
Database::open(&DatabaseConfig { prefix_size: None }, path)
|
||||
Database::open(&DatabaseConfig { prefix_size: None, max_open_files: 256 }, path)
|
||||
}
|
||||
|
||||
/// Open database file. Creates if it does not exist.
|
||||
pub fn open(config: &DatabaseConfig, path: &str) -> Result<Database, String> {
|
||||
let mut opts = Options::new();
|
||||
opts.set_max_open_files(256);
|
||||
opts.set_max_open_files(config.max_open_files);
|
||||
opts.create_if_missing(true);
|
||||
opts.set_use_fsync(false);
|
||||
opts.set_compaction_style(DBCompactionStyle::DBUniversalCompaction);
|
||||
@@ -203,10 +205,10 @@ mod tests {
|
||||
let path = RandomTempPath::create_dir();
|
||||
let smoke = Database::open_default(path.as_path().to_str().unwrap()).unwrap();
|
||||
assert!(smoke.is_empty());
|
||||
test_db(&DatabaseConfig { prefix_size: None });
|
||||
test_db(&DatabaseConfig { prefix_size: Some(1) });
|
||||
test_db(&DatabaseConfig { prefix_size: Some(8) });
|
||||
test_db(&DatabaseConfig { prefix_size: Some(32) });
|
||||
test_db(&DatabaseConfig { prefix_size: None, max_open_files: 256 });
|
||||
test_db(&DatabaseConfig { prefix_size: Some(1), max_open_files: 256 });
|
||||
test_db(&DatabaseConfig { prefix_size: Some(8), max_open_files: 256 });
|
||||
test_db(&DatabaseConfig { prefix_size: Some(32), max_open_files: 256 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user