Commit a28ba922 authored by Neil Shen's avatar Neil Shen Committed by GitHub

add rocksdb log dir option (#61)

parent ba914b8b
...@@ -189,6 +189,7 @@ extern "C" { ...@@ -189,6 +189,7 @@ extern "C" {
pub fn rocksdb_options_statistics_get_string(options: *mut DBOptions) -> *const c_char; pub fn rocksdb_options_statistics_get_string(options: *mut DBOptions) -> *const c_char;
pub fn rocksdb_options_set_stats_dump_period_sec(options: *mut DBOptions, v: usize); pub fn rocksdb_options_set_stats_dump_period_sec(options: *mut DBOptions, v: usize);
pub fn rocksdb_options_set_num_levels(options: *mut DBOptions, v: c_int); pub fn rocksdb_options_set_num_levels(options: *mut DBOptions, v: c_int);
pub fn rocksdb_options_set_db_log_dir(options: *mut DBOptions, path: *const c_char);
pub fn rocksdb_filterpolicy_create_bloom_full(bits_per_key: c_int) -> *mut DBFilterPolicy; pub fn rocksdb_filterpolicy_create_bloom_full(bits_per_key: c_int) -> *mut DBFilterPolicy;
pub fn rocksdb_filterpolicy_create_bloom(bits_per_key: c_int) -> *mut DBFilterPolicy; pub fn rocksdb_filterpolicy_create_bloom(bits_per_key: c_int) -> *mut DBFilterPolicy;
pub fn rocksdb_open(options: *mut DBOptions, pub fn rocksdb_open(options: *mut DBOptions,
......
...@@ -1043,6 +1043,8 @@ impl Drop for BackupEngine { ...@@ -1043,6 +1043,8 @@ impl Drop for BackupEngine {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use rocksdb_options::*; use rocksdb_options::*;
use std::fs;
use std::path::Path;
use std::str; use std::str;
use super::*; use super::*;
use tempdir::TempDir; use tempdir::TempDir;
...@@ -1218,6 +1220,32 @@ mod test { ...@@ -1218,6 +1220,32 @@ mod test {
assert!(r.unwrap().unwrap().to_utf8().unwrap() == str::from_utf8(value).unwrap()); assert!(r.unwrap().unwrap().to_utf8().unwrap() == str::from_utf8(value).unwrap());
} }
} }
#[test]
fn log_dir_test() {
let db_dir = TempDir::new("_rust_rocksdb_logdirtest").unwrap();
let db_path = db_dir.path().to_str().unwrap();
let log_path = format!("{}", Path::new(&db_path).join("log_path").display());
fs::create_dir_all(&log_path).unwrap();
let mut opts = Options::new();
opts.create_if_missing(true);
opts.set_db_log_dir(&log_path);
DB::open(opts, db_path).unwrap();
// Check LOG file.
let mut read_dir = fs::read_dir(&log_path).unwrap();
let entry = read_dir.next().unwrap().unwrap();
let name = entry.file_name();
name.to_str().unwrap().find("LOG").unwrap();
for entry in fs::read_dir(&db_path).unwrap() {
let entry = entry.unwrap();
let name = entry.file_name();
assert!(name.to_str().unwrap().find("LOG").is_none());
}
}
} }
#[test] #[test]
......
...@@ -549,6 +549,13 @@ impl Options { ...@@ -549,6 +549,13 @@ impl Options {
rocksdb_ffi::rocksdb_options_set_num_levels(self.inner, n); rocksdb_ffi::rocksdb_options_set_num_levels(self.inner, n);
} }
} }
pub fn set_db_log_dir(&mut self, path: &str) {
let path = CString::new(path.as_bytes()).unwrap();
unsafe {
rocksdb_ffi::rocksdb_options_set_db_log_dir(self.inner, path.as_ptr());
}
}
} }
pub struct FlushOptions { pub struct FlushOptions {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment