Skip to content

Commit

Permalink
Merge branch 'master' into widecolumns
Browse files Browse the repository at this point in the history
  • Loading branch information
Congyuwang committed Jun 25, 2024
2 parents 2486ff5 + 64a90a8 commit d14ad3c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.70.0"
42 changes: 40 additions & 2 deletions src/db_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3117,9 +3117,30 @@ impl Options {
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);
ffi::rocksdb_ratelimiter_destroy(ratelimiter);
}
}

/// 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
pub fn set_auto_tuned_ratelimiter(
&mut self,
rate_bytes_per_sec: i64,
refill_period_us: i64,
fairness: i32,
) {
unsafe {
let ratelimiter = ffi::rocksdb_ratelimiter_create_auto_tuned(
rate_bytes_per_sec,
refill_period_us,
fairness,
);
ffi::rocksdb_options_set_ratelimiter(self.inner, ratelimiter);
ffi::rocksdb_ratelimiter_destroy(ratelimiter);
}
}

Expand Down Expand Up @@ -3380,6 +3401,19 @@ impl Options {
}
self.outlive.write_buffer_manager = Some(write_buffer_manager.clone());
}

/// If true, working thread may avoid doing unnecessary and long-latency
/// operation (such as deleting obsolete files directly or deleting memtable)
/// and will instead schedule a background job to do it.
///
/// Use it if you're latency-sensitive.
///
/// Default: false (disabled)
pub fn set_avoid_unnecessary_blocking_io(&mut self, val: bool) {
unsafe {
ffi::rocksdb_options_set_avoid_unnecessary_blocking_io(self.inner, u8::from(val));
}
}
}

impl Default for Options {
Expand Down Expand Up @@ -3533,6 +3567,10 @@ pub enum ReadTier {
All = 0,
/// Reads data in memtable or block cache.
BlockCache,
/// Reads persisted data. When WAL is disabled, this option will skip data in memtable.
Persisted,
/// Reads data in memtable. Used for memtable only iterators.
Memtable,
}

impl ReadOptions {
Expand Down
37 changes: 37 additions & 0 deletions tests/test_rocksdb_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ fn test_add_compact_on_deletion_collector_factory() {
assert!(settings.contains("CompactOnDeletionCollector (Sliding window size = 5 Deletion trigger = 10 Deletion ratio = 0.5)"));
}

#[test]
fn test_set_avoid_unnecessary_blocking_io() {
let path = DBPath::new("_set_avoid_unnecessary_blocking_io");
{
let mut opts = Options::default();
opts.create_if_missing(true);
opts.set_avoid_unnecessary_blocking_io(true);
let db = DB::open(&opts, &path).unwrap();
let _ = db.put(b"k1", b"a");
assert_eq!(&*db.get(b"k1").unwrap().unwrap(), b"a");
}
}

#[test]
fn test_set_periodic_compaction_seconds() {
let path = DBPath::new("_set_periodic_compaction_seconds");
Expand All @@ -276,3 +289,27 @@ fn test_set_periodic_compaction_seconds() {
let _db = DB::open(&opts, &path).unwrap();
}
}

#[test]
fn test_set_ratelimiter() {
let path = DBPath::new("_set_ratelimiter");
{
let mut opts = Options::default();
opts.create_if_missing(true);
opts.set_ratelimiter(1024000, 1000, 1);
let db = DB::open(&opts, &path).unwrap();

let _ = db.put(b"k1", b"a");
assert_eq!(&*db.get(b"k1").unwrap().unwrap(), b"a");
}

{
let mut opts = Options::default();
opts.create_if_missing(true);
opts.set_auto_tuned_ratelimiter(1024000, 1000, 1);
let db = DB::open(&opts, &path).unwrap();

let _ = db.put(b"k2", b"a");
assert_eq!(&*db.get(b"k2").unwrap().unwrap(), b"a");
}
}

0 comments on commit d14ad3c

Please sign in to comment.