From 182922f0e6468dee319ad3e81a65ab6603c4df85 Mon Sep 17 00:00:00 2001 From: codingsh Date: Thu, 23 Jul 2020 16:58:54 -0300 Subject: [PATCH] feat: export persist_period_sec option and background_threads #447 - [x] add test disable all threads on get_with_cache_and_bulkload_test - [x] add test for stats_persist_period_sec --- src/db_options.rs | 29 +++++++++++++++++++++++++++++ tests/test_db.rs | 20 ++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/db_options.rs b/src/db_options.rs index c6239960b..155d4a883 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -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. @@ -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()); + } } diff --git a/tests/test_db.rs b/tests/test_db.rs index c97c2e5ee..6496837dd 100644 --- a/tests/test_db.rs +++ b/tests/test_db.rs @@ -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]