Skip to content

Commit

Permalink
feat: export persist_period_sec option and background_threads #447
Browse files Browse the repository at this point in the history
- [x] add test disable all threads on get_with_cache_and_bulkload_test
- [x] add test for stats_persist_period_sec
  • Loading branch information
developerfred committed Jul 23, 2020
1 parent 22c4780 commit 182922f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/db_options.rs
Expand Up @@ -2188,6 +2188,24 @@ impl Options {
}
}

/// If not zero, dump rocksdb.stats to RocksDB to LOG every `stats_persist_period_sec`.
///
/// Default: `600` (10 mins)
///
/// # Examples
///
/// ```
/// use rocksdb::Options;
///
/// let mut opts = Options::default();
/// opts.set_stats_persist_period_sec(5);
/// ```
pub fn set_stats_persist_period_sec(&mut self, period: c_uint) {
unsafe {
ffi::rocksdb_options_set_stats_persist_period_sec(self.inner, period);
}
}

/// When set to true, reading SST files will opt out of the filesystem's
/// readahead. Setting this to false may improve sequential iteration
/// performance.
Expand Down Expand Up @@ -3360,4 +3378,15 @@ mod tests {
branching_factor: 4,
});
}

#[test]
fn test_set_stats_persist_period_sec(){
let mut opts = Options::default();
opts.enable_statistics();
opts.set_stats_persist_period_sec(5);
assert!(opts.get_statistics().is_some());

let opts = Options::default();
assert!(opts.get_statistics().is_none());
}
}
20 changes: 20 additions & 0 deletions tests/test_db.rs
Expand Up @@ -691,6 +691,26 @@ fn get_with_cache_and_bulkload_test() {
opts.set_error_if_exists(true);
assert!(DB::open(&opts, &path).is_err());
}

// disable all threads
{
// create new options
let mut opts = Options::default();
opts.max_background_jobs(0);
opts.max_background_compactions(0);
opts.max_background_flushes(0);
opts.stats_dump_period_sec(0);
opts.stats_persist_period_sec(0);

// open db
let db = DB::open(&opts, &path).unwrap();

// try to get key
let iter = db.iterator(IteratorMode::Start);
for (expected, (k, _)) in iter.enumerate() {
assert_eq!(k.as_ref(), format!("{:0>4}", expected).as_bytes());
}
}
}

#[test]
Expand Down

0 comments on commit 182922f

Please sign in to comment.