Skip to content

Commit

Permalink
[kvdb-rocksdb] add DatabaseConfig max_total_wal_size (#528)
Browse files Browse the repository at this point in the history
* Add DatabaseConfig max_total_wal_size

* formatting

* formatting

* fixed test

* Update kvdb-rocksdb/src/lib.rs

Co-authored-by: Andronik Ordian <[email protected]>

* carog fmt

Co-authored-by: mdben1247 <[email protected]>
Co-authored-by: Andronik Ordian <[email protected]>
  • Loading branch information
3 people authored Mar 2, 2021
1 parent 0a7fe81 commit 7ff438a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions kvdb-rocksdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ pub struct DatabaseConfig {
/// if the secondary instance reads and applies state changes before the primary instance compacts them.
/// More info: https://github.com/facebook/rocksdb/wiki/Secondary-instance
pub secondary: Option<String>,
/// 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>,
}

impl DatabaseConfig {
Expand Down Expand Up @@ -227,6 +230,7 @@ impl Default for DatabaseConfig {
keep_log_file_num: 1,
enable_statistics: false,
secondary: None,
max_total_wal_size: None,
}
}
}
Expand Down Expand Up @@ -325,6 +329,9 @@ fn generate_options(config: &DatabaseConfig) -> Options {
opts.set_bytes_per_sync(1 * MB as u64);
opts.set_keep_log_file_num(1);
opts.increase_parallelism(cmp::max(1, num_cpus::get() as i32 / 2));
if let Some(m) = config.max_total_wal_size {
opts.set_max_total_wal_size(m);
}

opts
}
Expand Down Expand Up @@ -898,6 +905,7 @@ mod tests {
keep_log_file_num: 1,
enable_statistics: false,
secondary: None,
max_total_wal_size: None,
};

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

0 comments on commit 7ff438a

Please sign in to comment.