From c09e2b0d27d48588f9a418e849a00a8a120628f7 Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 8 Jan 2020 22:44:15 +0800 Subject: [PATCH] Options: add set_ratelimiter (#369) --- src/db_options.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/db_options.rs b/src/db_options.rs index 7e90e4a..94ca34c 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -1346,6 +1346,35 @@ impl Options { ffi::rocksdb_options_set_allow_mmap_reads(self.inner, is_enabled as c_uchar); } } + + /// Use to control write rate of flush and compaction. Flush has higher + /// priority than compaction. + /// If rate limiter is enabled, bytes_per_sync is set to 1MB by default. + /// + /// Default: disable + /// + /// # Example + /// + /// ``` + /// use rocksdb::Options; + /// + /// let mut options = Options::default(); + /// options.set_ratelimiter(1024 * 1024, 100 * 1000, 10); + /// ``` + pub fn set_ratelimiter( + &mut self, + rate_bytes_per_sec: i64, + refill_period_us: i64, + fairness: i32, + ) { + unsafe { + let ratelimiter = + ffi::rocksdb_ratelimiter_create(rate_bytes_per_sec, refill_period_us, fairness); + // Since limiter is wrapped in shared_ptr, we don't need to + // call rocksdb_ratelimiter_destroy explicitly. + ffi::rocksdb_options_set_ratelimiter(self.inner, ratelimiter); + } + } } impl Default for Options {