Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export persist_period_sec option and background_threads #448

Merged
merged 6 commits into from Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion librocksdb-sys/rocksdb
Submodule rocksdb updated 338 files
8 changes: 7 additions & 1 deletion librocksdb-sys/rocksdb_lib_sources.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
utilities/write_batch_with_index/write_batch_with_index_internal.cc
2 changes: 1 addition & 1 deletion src/compaction_filter.rs
Expand Up @@ -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
}
}
Expand Down
45 changes: 45 additions & 0 deletions src/db_options.rs
Expand Up @@ -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) {
developerfred marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand Down Expand Up @@ -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);
developerfred marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// 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 @@ -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());
}
}
23 changes: 23 additions & 0 deletions tests/test_db.rs
Expand Up @@ -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]
Expand Down