Skip to content

Commit

Permalink
feat: Expose compact_on_deletion_collector_factory
Browse files Browse the repository at this point in the history
  • Loading branch information
zaidoon committed Nov 26, 2023
1 parent 4b8a2ce commit 0a25f41
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/db_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3131,6 +3131,31 @@ impl Options {
ffi::rocksdb_options_set_allow_ingest_behind(self.inner, c_uchar::from(val));
}
}

// A factory of a table property collector that marks an SST
// file as need-compaction when it observe at least "D" deletion
// entries in any "N" consecutive entries, or the ratio of tombstone
// entries >= deletion_ratio.
//
// `window_size`: is the sliding window size "N"
// `num_dels_trigger`: is the deletion trigger "D"
// `deletion_ratio`: if <= 0 or > 1, disable triggering compaction based on
// deletion ratio.
pub fn add_compact_on_deletion_collector_factory(
&mut self,
window_size: size_t,
num_dels_trigger: size_t,
deletion_ratio: f64,
) {
unsafe {
ffi::rocksdb_options_add_compact_on_deletion_collector_factory_del_ratio(
self.inner,
window_size,
num_dels_trigger,
deletion_ratio,
);
}
}
}

impl Default for Options {
Expand Down
18 changes: 18 additions & 0 deletions tests/test_rocksdb_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,21 @@ fn test_lz4_compression() {
fn test_zstd_compression() {
test_compression_type(DBCompressionType::Zstd);
}

#[test]
fn test_add_compact_on_deletion_collector_factory() {
let n = DBPath::new("_rust_rocksdb_test_add_compact_on_deletion_collector_factory");

let mut opts = Options::default();
opts.create_if_missing(true);
opts.add_compact_on_deletion_collector_factory(5, 10, 0.5);
let _db = DB::open(&opts, &n).unwrap();

let mut rocksdb_log = fs::File::open(format!("{}/LOG", (&n).as_ref().to_str().unwrap()))
.expect("rocksdb creates a LOG file");
let mut settings = String::new();
rocksdb_log
.read_to_string(&mut settings)
.expect("can read the LOG file");
assert!(settings.contains("CompactOnDeletionCollector (Sliding window size = 5 Deletion trigger = 10 Deletion ratio = 0.5)"));
}

0 comments on commit 0a25f41

Please sign in to comment.