Deprecate option `periodic_compaction_seconds` for FIFO compaction (#11550)

Summary:
both options `ttl` and `periodic_compaction_seconds` have the same meaning for FIFO compaction, which is redundant and can be confusing to use. For example, setting TTL to 0 does not disable TTL: user needs to also set periodic_compaction_seconds to 0. Another example is that dynamically setting `periodic_compaction_seconds` (surprisingly) has no effect on TTL compaction. This is because FIFO compaction picker internally only looks at value of `ttl`. The value of `ttl` is in `SanitizeOptions()` which take into account the value of `periodic_compaction_seconds`, but dynamically setting an option does not invoke this method.

This PR clarifies the usage of both options for FIFO compaction: only `ttl` should be used, `periodic_compaction_seconds` will not have any effect on FIFO compaction.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/11550

Test Plan:
- updated existing unit test `DBOptionsTest.SanitizeFIFOPeriodicCompaction`
- checked existing values of both options in feature matrix: https://fburl.com/daiquery/xxd0gs9w. All current uses cases either have `periodic_compaction_seconds = 0` or have `periodic_compaction_seconds > ttl`, so should not cause change of behavior.

Reviewed By: ajkr

Differential Revision: D46902959

Pulled By: cbi42

fbshipit-source-id: a9ede235b276783b4906aaec443551fa62ceff4c
oxigraph-main
Changyu Bi 1 year ago committed by Facebook GitHub Bot
parent c53d604f41
commit df082c8d1d
  1. 20
      db/column_family.cc
  2. 15
      db/db_options_test.cc
  3. 29
      include/rocksdb/advanced_options.h
  4. 1
      unreleased_history/behavior_changes/fifo_ttl_periodic_compaction.md

@ -382,8 +382,8 @@ ColumnFamilyOptions SanitizeOptions(const ImmutableDBOptions& db_options,
const uint64_t kAdjustedTtl = 30 * 24 * 60 * 60; const uint64_t kAdjustedTtl = 30 * 24 * 60 * 60;
if (result.ttl == kDefaultTtl) { if (result.ttl == kDefaultTtl) {
if (is_block_based_table && if (is_block_based_table) {
result.compaction_style != kCompactionStyleFIFO) { // For FIFO, max_open_files is checked in ValidateOptions().
result.ttl = kAdjustedTtl; result.ttl = kAdjustedTtl;
} else { } else {
result.ttl = 0; result.ttl = 0;
@ -403,16 +403,12 @@ ColumnFamilyOptions SanitizeOptions(const ImmutableDBOptions& db_options,
result.periodic_compaction_seconds = kAdjustedPeriodicCompSecs; result.periodic_compaction_seconds = kAdjustedPeriodicCompSecs;
} }
} else { } else {
// result.compaction_style == kCompactionStyleFIFO if (result.periodic_compaction_seconds != kDefaultPeriodicCompSecs &&
if (result.ttl == 0) { result.periodic_compaction_seconds > 0) {
if (is_block_based_table) { ROCKS_LOG_WARN(
if (result.periodic_compaction_seconds == kDefaultPeriodicCompSecs) { db_options.info_log.get(),
result.periodic_compaction_seconds = kAdjustedPeriodicCompSecs; "periodic_compaction_seconds does not support FIFO compaction. You"
} "may want to set option TTL instead.");
result.ttl = result.periodic_compaction_seconds;
}
} else if (result.periodic_compaction_seconds != 0) {
result.ttl = std::min(result.ttl, result.periodic_compaction_seconds);
} }
} }

@ -880,9 +880,13 @@ TEST_F(DBOptionsTest, SanitizeFIFOPeriodicCompaction) {
Options options; Options options;
options.compaction_style = kCompactionStyleFIFO; options.compaction_style = kCompactionStyleFIFO;
options.env = CurrentOptions().env; options.env = CurrentOptions().env;
// Default value allows RocksDB to set ttl to 30 days.
ASSERT_EQ(30 * 24 * 60 * 60, dbfull()->GetOptions().ttl);
// Disable
options.ttl = 0; options.ttl = 0;
Reopen(options); Reopen(options);
ASSERT_EQ(30 * 24 * 60 * 60, dbfull()->GetOptions().ttl); ASSERT_EQ(0, dbfull()->GetOptions().ttl);
options.ttl = 100; options.ttl = 100;
Reopen(options); Reopen(options);
@ -892,15 +896,12 @@ TEST_F(DBOptionsTest, SanitizeFIFOPeriodicCompaction) {
Reopen(options); Reopen(options);
ASSERT_EQ(100 * 24 * 60 * 60, dbfull()->GetOptions().ttl); ASSERT_EQ(100 * 24 * 60 * 60, dbfull()->GetOptions().ttl);
options.ttl = 200; // periodic_compaction_seconds should have no effect
options.periodic_compaction_seconds = 300; // on FIFO compaction.
Reopen(options);
ASSERT_EQ(200, dbfull()->GetOptions().ttl);
options.ttl = 500; options.ttl = 500;
options.periodic_compaction_seconds = 300; options.periodic_compaction_seconds = 300;
Reopen(options); Reopen(options);
ASSERT_EQ(300, dbfull()->GetOptions().ttl); ASSERT_EQ(500, dbfull()->GetOptions().ttl);
} }
TEST_F(DBOptionsTest, SetFIFOCompactionOptions) { TEST_F(DBOptionsTest, SetFIFOCompactionOptions) {

@ -858,24 +858,23 @@ struct AdvancedColumnFamilyOptions {
// Dynamically changeable through SetOptions() API // Dynamically changeable through SetOptions() API
bool report_bg_io_stats = false; bool report_bg_io_stats = false;
// Files containing updates older than TTL will go through the compaction // This option has different meanings for different compaction styles:
// process. This usually happens in a cascading way so that those entries //
// will be compacted to bottommost level/file. // Leveled: Non-bottom-level files with all keys older than TTL will go
// through the compaction process. This usually happens in a cascading
// way so that those entries will be compacted to bottommost level/file.
// The feature is used to remove stale entries that have been deleted or // The feature is used to remove stale entries that have been deleted or
// updated from the file system. // updated from the file system.
// Pre-req: This needs max_open_files to be set to -1. //
// In Level: Non-bottom-level files older than TTL will go through the // FIFO: Files with all keys older than TTL will be deleted. TTL is only
// compaction process. // supported if option max_open_files is set to -1.
// In FIFO: Files older than TTL will be deleted. //
// unit: seconds. Ex: 1 day = 1 * 24 * 60 * 60 // unit: seconds. Ex: 1 day = 1 * 24 * 60 * 60
// In FIFO, this option will have the same meaning as
// periodic_compaction_seconds. Whichever stricter will be used.
// 0 means disabling. // 0 means disabling.
// UINT64_MAX - 1 (0xfffffffffffffffe) is special flag to allow RocksDB to // UINT64_MAX - 1 (0xfffffffffffffffe) is special flag to allow RocksDB to
// pick default. // pick default.
// //
// Default: 30 days for leveled compaction + block based table. disable // Default: 30 days if using block based table. 0 (disable) otherwise.
// otherwise.
// //
// Dynamically changeable through SetOptions() API // Dynamically changeable through SetOptions() API
uint64_t ttl = 0xfffffffffffffffe; uint64_t ttl = 0xfffffffffffffffe;
@ -891,12 +890,9 @@ struct AdvancedColumnFamilyOptions {
// age is based on the file's last modified time (given by the underlying // age is based on the file's last modified time (given by the underlying
// Env). // Env).
// //
// Supported in all compaction styles. // Supported in leveled and universal compaction.
// In Universal compaction, rocksdb will try to do a full compaction when // In Universal compaction, rocksdb will try to do a full compaction when
// possible, see more in UniversalCompactionBuilder::PickPeriodicCompaction(). // possible, see more in UniversalCompactionBuilder::PickPeriodicCompaction().
// In FIFO compaction, this option has the same meaning as TTL and whichever
// stricter will be used.
// Pre-req: max_open_file == -1.
// unit: seconds. Ex: 7 days = 7 * 24 * 60 * 60 // unit: seconds. Ex: 7 days = 7 * 24 * 60 * 60
// //
// Values: // Values:
@ -905,9 +901,6 @@ struct AdvancedColumnFamilyOptions {
// as needed. For now, RocksDB will change this value to 30 days // as needed. For now, RocksDB will change this value to 30 days
// (i.e 30 * 24 * 60 * 60) so that every file goes through the compaction // (i.e 30 * 24 * 60 * 60) so that every file goes through the compaction
// process at least once every 30 days if not compacted sooner. // process at least once every 30 days if not compacted sooner.
// In FIFO compaction, since the option has the same meaning as ttl,
// when this value is left default, and ttl is left to 0, 30 days will be
// used. Otherwise, min(ttl, periodic_compaction_seconds) will be used.
// //
// Default: UINT64_MAX - 1 (allow RocksDB to auto-tune) // Default: UINT64_MAX - 1 (allow RocksDB to auto-tune)
// //

@ -0,0 +1 @@
Option `periodic_compaction_seconds` no longer supports FIFO compaction: setting it has no effect on FIFO compactions. FIFO compaction users should only set option `ttl` instead.
Loading…
Cancel
Save