Skip to content

Commit 02ac6b1

Browse files
committed
Expose set_ttl
1 parent 10e28ec commit 02ac6b1

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/db_options.rs

+41-1
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,9 @@ impl Options {
13951395
///
13961396
/// Leveled: files older than `periodic_compaction_seconds` will be picked up
13971397
/// for compaction and will be re-written to the same level as they were
1398-
/// before.
1398+
/// before if level_compaction_dynamic_level_bytes is disabled. Otherwise,
1399+
/// it will rewrite files to the next level except for the last level files
1400+
/// to the same level.
13991401
///
14001402
/// FIFO: not supported. Setting this option has no effect for FIFO compaction.
14011403
///
@@ -1440,6 +1442,44 @@ impl Options {
14401442
}
14411443
}
14421444

1445+
/// This option has different meanings for different compaction styles:
1446+
///
1447+
/// Leveled: Non-bottom-level files with all keys older than TTL will go
1448+
/// through the compaction process. This usually happens in a cascading
1449+
/// way so that those entries will be compacted to bottommost level/file.
1450+
/// The feature is used to remove stale entries that have been deleted or
1451+
/// updated from the file system.
1452+
///
1453+
/// FIFO: Files with all keys older than TTL will be deleted. TTL is only
1454+
/// supported if option max_open_files is set to -1.
1455+
///
1456+
/// Universal: users should only set the option `periodic_compaction_seconds`
1457+
/// instead. For backward compatibility, this option has the same
1458+
/// meaning as `periodic_compaction_seconds`. See more in comments for
1459+
/// `periodic_compaction_seconds` on the interaction between these two
1460+
/// options.
1461+
///
1462+
/// This option only supports block based table format for any compaction
1463+
/// style.
1464+
///
1465+
/// unit: seconds. Ex: 1 day = 1 * 24 * 60 * 60
1466+
/// 0 means disabling.
1467+
/// UINT64_MAX - 1 (0xfffffffffffffffe) is special flag to allow RocksDB to
1468+
/// pick default.
1469+
///
1470+
/// Default: 30 days if using block based table. 0 (disable) otherwise.
1471+
///
1472+
/// Dynamically changeable
1473+
/// Note that dynamically changing this option only works for leveled and FIFO
1474+
/// compaction. For universal compaction, dynamically changing this option has
1475+
/// no effect, users should dynamically change `periodic_compaction_seconds`
1476+
/// instead.
1477+
pub fn set_ttl(&mut self, secs: u64) {
1478+
unsafe {
1479+
ffi::rocksdb_options_set_ttl(self.inner, secs);
1480+
}
1481+
}
1482+
14431483
pub fn set_merge_operator_associative<F: MergeFn + Clone>(
14441484
&mut self,
14451485
name: impl CStrLike,

tests/test_rocksdb_options.rs

+11
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,14 @@ fn test_set_periodic_compaction_seconds() {
276276
let _db = DB::open(&opts, &path).unwrap();
277277
}
278278
}
279+
280+
#[test]
281+
fn test_set_ttl() {
282+
let path = DBPath::new("_set_ttl");
283+
{
284+
let mut opts = Options::default();
285+
opts.create_if_missing(true);
286+
opts.set_ttl(5);
287+
let _db = DB::open(&opts, &path).unwrap();
288+
}
289+
}

0 commit comments

Comments
 (0)