From ccf6ae3aff54e52a7d404a19a3a56b9ef3aedf24 Mon Sep 17 00:00:00 2001 From: codingsh Date: Tue, 19 Jan 2021 07:44:24 +0000 Subject: [PATCH] Export persist_period_sec option and background_threads (#448) --- librocksdb-sys/rocksdb | 2 +- librocksdb-sys/rocksdb_lib_sources.txt | 8 ++++- src/compaction_filter.rs | 2 +- src/db_options.rs | 45 ++++++++++++++++++++++++++ tests/test_db.rs | 23 +++++++++++++ 5 files changed, 77 insertions(+), 3 deletions(-) diff --git a/librocksdb-sys/rocksdb b/librocksdb-sys/rocksdb index 48bfca3..50f206a 160000 --- a/librocksdb-sys/rocksdb +++ b/librocksdb-sys/rocksdb @@ -1 +1 @@ -Subproject commit 48bfca38f6f175435052a59791922a1a453d9609 +Subproject commit 50f206ad84fa6cd516bad1bea93c03ae0655b314 diff --git a/librocksdb-sys/rocksdb_lib_sources.txt b/librocksdb-sys/rocksdb_lib_sources.txt index bf06ae2..716b03d 100644 --- a/librocksdb-sys/rocksdb_lib_sources.txt +++ b/librocksdb-sys/rocksdb_lib_sources.txt @@ -20,6 +20,7 @@ db/compaction/compaction_picker.cc db/compaction/compaction_picker_fifo.cc db/compaction/compaction_picker_level.cc db/compaction/compaction_picker_universal.cc +db/compaction/sst_partitioner.cc db/convenience.cc db/db_filesnapshot.cc db/db_impl/db_impl.cc @@ -76,6 +77,7 @@ env/env_hdfs.cc env/env_posix.cc env/file_system.cc env/fs_posix.cc +env/file_system_tracer.cc env/io_posix.cc env/mock_env.cc file/delete_scheduler.cc @@ -164,6 +166,7 @@ table/plain/plain_table_factory.cc table/plain/plain_table_index.cc table/plain/plain_table_key_coding.cc table/plain/plain_table_reader.cc +table/sst_file_dumper.cc table/sst_file_reader.cc table/sst_file_writer.cc table/table_properties.cc @@ -174,6 +177,7 @@ test_util/transaction_test_util.cc tools/dump/db_dump_tool.cc trace_replay/trace_replay.cc trace_replay/block_cache_tracer.cc +trace_replay/io_tracer.cc util/build_version.cc util/coding.cc util/compaction_job_stats_impl.cc @@ -208,6 +212,8 @@ utilities/convenience/info_log_finder.cc utilities/debug.cc utilities/env_mirror.cc utilities/env_timed.cc +utilities/fault_injection_env.cc +utilities/fault_injection_fs.cc utilities/leveldb_options/leveldb_options.cc utilities/memory/memory_util.cc utilities/merge_operators/max.cc @@ -244,4 +250,4 @@ utilities/transactions/write_unprepared_txn.cc utilities/transactions/write_unprepared_txn_db.cc utilities/ttl/db_ttl_impl.cc utilities/write_batch_with_index/write_batch_with_index.cc -utilities/write_batch_with_index/write_batch_with_index_internal.cc \ No newline at end of file +utilities/write_batch_with_index/write_batch_with_index_internal.cc diff --git a/src/compaction_filter.rs b/src/compaction_filter.rs index 53bcba0..7e39a56 100644 --- a/src/compaction_filter.rs +++ b/src/compaction_filter.rs @@ -137,7 +137,7 @@ where Change(newval) => { *new_value = newval.as_ptr() as *mut c_char; *new_value_length = newval.len() as size_t; - *value_changed = 1 as c_uchar; + *value_changed = 1_u8; 0 } } diff --git a/src/db_options.rs b/src/db_options.rs index 6777d08..7317f18 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -137,6 +137,22 @@ impl Env { } } + /// Sets the size of the low priority thread pool that can be used to + /// prevent compactions from stalling memtable flushes. + pub fn set_low_priority_background_threads(&mut self, n: c_int) { + unsafe { + ffi::rocksdb_env_set_low_priority_background_threads(self.inner, n); + } + } + + /// Sets the size of the bottom priority thread pool that can be used to + /// prevent compactions from stalling memtable flushes. + pub fn set_bottom_priority_background_threads(&mut self, n: c_int) { + unsafe { + ffi::rocksdb_env_set_bottom_priority_background_threads(self.inner, n); + } + } + /// Wait for all threads started by StartThread to terminate. pub fn join_all_threads(&mut self) { unsafe { @@ -2223,6 +2239,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. @@ -3420,4 +3454,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 eed57dc..d9ec85b 100644 --- a/tests/test_db.rs +++ b/tests/test_db.rs @@ -779,6 +779,29 @@ 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.set_max_background_jobs(0); + opts.set_stats_dump_period_sec(0); + opts.set_stats_persist_period_sec(0); + + // test Env::Default()->SetBackgroundThreads(0, Env::Priority::BOTTOM); + let mut env = Env::default().unwrap(); + env.set_bottom_priority_background_threads(0); + opts.set_env(&env); + + // 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]