Turn on periodic compaction in universal by default if compaction filter is used. (#5994)

Summary:
Recently, periodic compaction got turned on by default for leveled compaction is compaction filter is used. Since periodic compaction is now supported in universal compaction too, we do the same default for universal now.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5994

Test Plan: Add a new unit test.

Differential Revision: D18363744

fbshipit-source-id: 5093288ce990ee3cab0e44ffd92d8489fbcd6a48
main
sdong 5 years ago committed by Facebook Github Bot
parent 7b3222e10a
commit f0b469e563
  1. 14
      db/column_family.cc
  2. 23
      db/db_universal_compaction_test.cc

@ -349,12 +349,14 @@ ColumnFamilyOptions SanitizeOptions(const ImmutableDBOptions& db_options,
// Turn on periodic compactions and set them to occur once every 30 days if // 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 // compaction filters are used and periodic_compaction_seconds is set to the
// default value. // default value.
if (result.compaction_style == kCompactionStyleLevel && if (result.compaction_style != kCompactionStyleFIFO) {
(result.compaction_filter != nullptr || if ((result.compaction_filter != nullptr ||
result.compaction_filter_factory != nullptr) && result.compaction_filter_factory != nullptr) &&
result.periodic_compaction_seconds == kDefaultPeriodicCompSecs) { result.periodic_compaction_seconds == kDefaultPeriodicCompSecs) {
result.periodic_compaction_seconds = kDefaultTtlSecs; result.periodic_compaction_seconds = kDefaultTtlSecs;
} else if (result.compaction_style == kCompactionStyleFIFO) { }
} else {
// result.compaction_style == kCompactionStyleFIFO
if (result.ttl == 0) { if (result.ttl == 0) {
if (result.periodic_compaction_seconds == kDefaultPeriodicCompSecs) { if (result.periodic_compaction_seconds == kDefaultPeriodicCompSecs) {
result.periodic_compaction_seconds = kDefaultTtlSecs; result.periodic_compaction_seconds = kDefaultTtlSecs;

@ -2149,6 +2149,29 @@ TEST_F(DBTestUniversalCompaction2, IngestBehind) {
ASSERT_GT(NumTableFilesAtLevel(5), 0); ASSERT_GT(NumTableFilesAtLevel(5), 0);
} }
TEST_F(DBTestUniversalCompaction2, PeriodicCompactionDefault) {
Options options;
options.compaction_style = kCompactionStyleUniversal;
KeepFilterFactory* filter = new KeepFilterFactory(true);
options.compaction_filter_factory.reset(filter);
Reopen(options);
ASSERT_EQ(30 * 24 * 60 * 60,
dbfull()->GetOptions().periodic_compaction_seconds);
KeepFilter df;
options.compaction_filter_factory.reset();
options.compaction_filter = &df;
Reopen(options);
ASSERT_EQ(30 * 24 * 60 * 60,
dbfull()->GetOptions().periodic_compaction_seconds);
options.compaction_filter = nullptr;
Reopen(options);
ASSERT_EQ(options.periodic_compaction_seconds,
dbfull()->GetOptions().periodic_compaction_seconds);
}
TEST_F(DBTestUniversalCompaction2, PeriodicCompaction) { TEST_F(DBTestUniversalCompaction2, PeriodicCompaction) {
Options opts = CurrentOptions(); Options opts = CurrentOptions();
opts.env = env_; opts.env = env_;

Loading…
Cancel
Save