diff --git a/HISTORY.md b/HISTORY.md index 63254df95..6aacb132e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ ## Unreleased ### Public API Change * Changed the default value of periodic_compaction_seconds to `UINT64_MAX` which allows RocksDB to auto-tune periodic compaction scheduling. When using the default value, periodic compactions are now auto-enabled if a compaction filter is used. A value of `0` will turn off the feature completely. +* With FIFO compaction style, options.periodic_compaction_seconds will have the same meaning as options.ttl. Whichever stricter will be used. With the default options.periodic_compaction_seconds value with options.ttl's default of 0, RocksDB will give a default of 30 days. * Added an API GetCreationTimeOfOldestFile(uint64_t* creation_time) to get the file_creation_time of the oldest SST file in the DB. diff --git a/db/column_family.cc b/db/column_family.cc index f0360eefe..7c3b0276d 100644 --- a/db/column_family.cc +++ b/db/column_family.cc @@ -343,14 +343,26 @@ ColumnFamilyOptions SanitizeOptions(const ImmutableDBOptions& db_options, result.max_compaction_bytes = result.target_file_size_base * 25; } + const uint64_t kDefaultPeriodicCompSecs = 0xffffffffffffffff; + const uint64_t kDefaultTtlSecs = 30 * 24 * 60 * 60; + // Turn on periodic compactions and set them to occur once every 30 days if // compaction filters are used and periodic_compaction_seconds is set to the // default value. if (result.compaction_style == kCompactionStyleLevel && (result.compaction_filter != nullptr || result.compaction_filter_factory != nullptr) && - result.periodic_compaction_seconds == port::kMaxUint64) { - result.periodic_compaction_seconds = 30 * 24 * 60 * 60; + result.periodic_compaction_seconds == kDefaultPeriodicCompSecs) { + result.periodic_compaction_seconds = kDefaultTtlSecs; + } else if (result.compaction_style == kCompactionStyleFIFO) { + if (result.ttl == 0) { + if (result.periodic_compaction_seconds == kDefaultPeriodicCompSecs) { + result.periodic_compaction_seconds = kDefaultTtlSecs; + } + result.ttl = result.periodic_compaction_seconds; + } else if (result.periodic_compaction_seconds != 0) { + result.ttl = std::min(result.ttl, result.periodic_compaction_seconds); + } } return result; diff --git a/db/db_options_test.cc b/db/db_options_test.cc index 787f77ebd..004c9acfb 100644 --- a/db/db_options_test.cc +++ b/db/db_options_test.cc @@ -606,6 +606,32 @@ TEST_F(DBOptionsTest, SanitizeDelayedWriteRate) { ASSERT_EQ(31 * 1024 * 1024, dbfull()->GetDBOptions().delayed_write_rate); } +TEST_F(DBOptionsTest, SanitizeFIFOPeriodicCompaction) { + Options options; + options.compaction_style = kCompactionStyleFIFO; + options.ttl = 0; + Reopen(options); + ASSERT_EQ(30 * 24 * 60 * 60, dbfull()->GetOptions().ttl); + + options.ttl = 100; + Reopen(options); + ASSERT_EQ(100, dbfull()->GetOptions().ttl); + + options.ttl = 100 * 24 * 60 * 60; + Reopen(options); + ASSERT_EQ(100 * 24 * 60 * 60, dbfull()->GetOptions().ttl); + + options.ttl = 200; + options.periodic_compaction_seconds = 300; + Reopen(options); + ASSERT_EQ(200, dbfull()->GetOptions().ttl); + + options.ttl = 500; + options.periodic_compaction_seconds = 300; + Reopen(options); + ASSERT_EQ(300, dbfull()->GetOptions().ttl); +} + TEST_F(DBOptionsTest, SetFIFOCompactionOptions) { Options options; options.compaction_style = kCompactionStyleFIFO; diff --git a/include/rocksdb/advanced_options.h b/include/rocksdb/advanced_options.h index 77c55d977..63d1f1ec9 100644 --- a/include/rocksdb/advanced_options.h +++ b/include/rocksdb/advanced_options.h @@ -653,6 +653,8 @@ struct AdvancedColumnFamilyOptions { // compation process. // In FIFO: Files older than TTL will be deleted. // 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. // // Default: 0 (disabled) // @@ -667,7 +669,9 @@ struct AdvancedColumnFamilyOptions { // age is based on the file's last modified time (given by the underlying // Env). // - // Only supported in Level compaction. + // Supported in Level and FIFO compaction. + // 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 // @@ -677,6 +681,9 @@ struct AdvancedColumnFamilyOptions { // 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 // 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 (allow RocksDB to auto-tune) //