Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add to kvdb-rocksdb create_if_missing config option #576

Merged
merged 4 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kvdb-rocksdb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kvdb-rocksdb"
version = "0.12.1"
version = "0.13.0"
authors = ["Parity Technologies <admin@parity.io>"]
repository = "https://github.com/paritytech/parity-common"
description = "kvdb implementation backed by RocksDB"
Expand Down
9 changes: 7 additions & 2 deletions kvdb-rocksdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ pub struct DatabaseConfig {
/// Limit the size (in bytes) of write ahead logs
/// More info: https://github.com/facebook/rocksdb/wiki/Write-Ahead-Log
pub max_total_wal_size: Option<u64>,
/// Creates a new database if no database exists.
/// Set to `true` by default for backwards compatibility.
pub create_if_missing: bool,
}

impl DatabaseConfig {
Expand Down Expand Up @@ -233,6 +236,7 @@ impl Default for DatabaseConfig {
enable_statistics: false,
secondary: None,
max_total_wal_size: None,
create_if_missing: true,
}
}
}
Expand Down Expand Up @@ -325,7 +329,7 @@ fn generate_options(config: &DatabaseConfig) -> Options {
opts.enable_statistics();
}
opts.set_use_fsync(false);
opts.create_if_missing(true);
opts.create_if_missing(config.create_if_missing);
if config.secondary.is_some() {
opts.set_max_open_files(-1)
} else {
Expand Down Expand Up @@ -376,7 +380,7 @@ fn generate_block_based_options(config: &DatabaseConfig) -> io::Result<BlockBase
impl Database {
const CORRUPTION_FILE_NAME: &'static str = "CORRUPTED";

/// Open database file. Creates if it does not exist.
/// Open database file.
///
/// # Safety
///
Expand Down Expand Up @@ -921,6 +925,7 @@ mod tests {
enable_statistics: false,
secondary: None,
max_total_wal_size: None,
create_if_missing: true,
};

let db = Database::open(&config, tempdir.path().to_str().unwrap()).unwrap();
Expand Down