Skip to content

Commit

Permalink
feat: Expose set_periodic_compaction_seconds (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaidoon1 committed Dec 13, 2023
1 parent 7c66ff5 commit f4f9722
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/db_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,55 @@ impl Options {
}
}

/// This option has different meanings for different compaction styles:
///
/// Leveled: files older than `periodic_compaction_seconds` will be picked up
/// for compaction and will be re-written to the same level as they were
/// before.
///
/// FIFO: not supported. Setting this option has no effect for FIFO compaction.
///
/// Universal: when there are files older than `periodic_compaction_seconds`,
/// rocksdb will try to do as large a compaction as possible including the
/// last level. Such compaction is only skipped if only last level is to
/// be compacted and no file in last level is older than
/// `periodic_compaction_seconds`. See more in
/// UniversalCompactionBuilder::PickPeriodicCompaction().
/// For backward compatibility, the effective value of this option takes
/// into account the value of option `ttl`. The logic is as follows:
/// - both options are set to 30 days if they have the default value.
/// - if both options are zero, zero is picked. Otherwise, we take the min
/// value among non-zero options values (i.e. takes the stricter limit).
///
/// One main use of the feature is to make sure a file goes through compaction
/// filters periodically. Users can also use the feature to clear up SST
/// files using old format.
///
/// A file's age is computed by looking at file_creation_time or creation_time
/// table properties in order, if they have valid non-zero values; if not, the
/// age is based on the file's last modified time (given by the underlying
/// Env).
///
/// This option only supports block based table format for any compaction
/// style.
///
/// unit: seconds. Ex: 7 days = 7 * 24 * 60 * 60
///
/// Values:
/// 0: Turn off Periodic compactions.
/// UINT64_MAX - 1 (0xfffffffffffffffe) is special flag to allow RocksDB to
/// pick default.
///
/// Default: 30 days if using block based table format + compaction filter +
/// leveled compaction or block based table format + universal compaction.
/// 0 (disabled) otherwise.
///
pub fn set_periodic_compaction_seconds(&mut self, secs: u64) {
unsafe {
ffi::rocksdb_options_set_periodic_compaction_seconds(self.inner, secs);
}
}

pub fn set_merge_operator_associative<F: MergeFn + Clone>(
&mut self,
name: impl CStrLike,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_rocksdb_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,14 @@ fn test_add_compact_on_deletion_collector_factory() {
.expect("can read the LOG file");
assert!(settings.contains("CompactOnDeletionCollector (Sliding window size = 5 Deletion trigger = 10 Deletion ratio = 0.5)"));
}

#[test]
fn test_set_periodic_compaction_seconds() {
let path = DBPath::new("_set_periodic_compaction_seconds");
{
let mut opts = Options::default();
opts.create_if_missing(true);
opts.set_periodic_compaction_seconds(5);
let _db = DB::open(&opts, &path).unwrap();
}
}

0 comments on commit f4f9722

Please sign in to comment.