From d94aa2f7dbfa37f39de58d40dfc10c7ba0fb4693 Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Wed, 23 Jan 2019 16:44:02 -0800 Subject: [PATCH] Make compaction_pri = kMinOverlappingRatio to be default (#4911) Summary: compaction_pri = kMinOverlappingRatio usually provides much better write amplification than the default. https://github.com/facebook/rocksdb/pull/4907 fixes one shortcome of this option. Make it default. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4911 Differential Revision: D13789262 Pulled By: siying fbshipit-source-id: d90acf8c4dede44f00d183ca4c7a210259378269 --- HISTORY.md | 3 +++ db/compaction_picker_test.cc | 3 +++ include/rocksdb/advanced_options.h | 4 ++-- options/options.cc | 5 ++++- options/options_test.cc | 9 +++++++++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 7d9386468..0a70a00a3 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -23,6 +23,9 @@ * Fix incorrect `NotFound` point lookup result when querying the endpoint of a file that has been extended by a range tombstone. * Fix with pipelined write, write leaders's callback failure lead to the whole write group fail. +### Change Default Options +* Change options.compaction_pri's default to kMinOverlappingRatio + ## 5.18.0 (11/30/2018) ### New Features * Introduced `JemallocNodumpAllocator` memory allocator. When being use, block cache will be excluded from core dump. diff --git a/db/compaction_picker_test.cc b/db/compaction_picker_test.cc index dea5d4a06..74909f783 100644 --- a/db/compaction_picker_test.cc +++ b/db/compaction_picker_test.cc @@ -59,6 +59,9 @@ class CompactionPickerTest : public testing::Test { log_buffer_(InfoLogLevel::INFO_LEVEL, &logger_), file_num_(1), vstorage_(nullptr) { + // ioptions_.compaction_pri = kMinOverlappingRatio has its own set of + // tests to cover. + ioptions_.compaction_pri = kByCompensatedSize; fifo_options_.max_table_files_size = 1; mutable_cf_options_.RefreshDerivedOptions(ioptions_); ioptions_.cf_paths.emplace_back("dummy", diff --git a/include/rocksdb/advanced_options.h b/include/rocksdb/advanced_options.h index fe331482e..8b91000c9 100644 --- a/include/rocksdb/advanced_options.h +++ b/include/rocksdb/advanced_options.h @@ -528,8 +528,8 @@ struct AdvancedColumnFamilyOptions { // If level compaction_style = kCompactionStyleLevel, for each level, // which files are prioritized to be picked to compact. - // Default: kByCompensatedSize - CompactionPri compaction_pri = kByCompensatedSize; + // Default: kMinOverlappingRatio + CompactionPri compaction_pri = kMinOverlappingRatio; // The options needed to support Universal Style compactions // diff --git a/options/options.cc b/options/options.cc index 17798accb..4f3195fe6 100644 --- a/options/options.cc +++ b/options/options.cc @@ -439,6 +439,10 @@ DBOptions* DBOptions::OldDefaults(int rocksdb_major_version, ColumnFamilyOptions* ColumnFamilyOptions::OldDefaults( int rocksdb_major_version, int rocksdb_minor_version) { + if (rocksdb_major_version < 5 || + (rocksdb_major_version == 5 && rocksdb_minor_version <= 18)) { + compaction_pri = CompactionPri::kByCompensatedSize; + } if (rocksdb_major_version < 4 || (rocksdb_major_version == 4 && rocksdb_minor_version < 7)) { write_buffer_size = 4 << 20; @@ -452,7 +456,6 @@ ColumnFamilyOptions* ColumnFamilyOptions::OldDefaults( } else if (rocksdb_major_version == 5 && rocksdb_minor_version < 2) { level0_stop_writes_trigger = 30; } - compaction_pri = CompactionPri::kByCompensatedSize; return this; } diff --git a/options/options_test.cc b/options/options_test.cc index 6dc94af5b..1ad28dae1 100644 --- a/options/options_test.cc +++ b/options/options_test.cc @@ -1528,6 +1528,7 @@ TEST_F(OptionsParserTest, DifferentDefault) { const std::string kOptionsFileName = "test-persisted-options.ini"; ColumnFamilyOptions cf_level_opts; + ASSERT_EQ(CompactionPri::kMinOverlappingRatio, cf_level_opts.compaction_pri); cf_level_opts.OptimizeLevelStyleCompaction(); ColumnFamilyOptions cf_univ_opts; @@ -1597,6 +1598,14 @@ TEST_F(OptionsParserTest, DifferentDefault) { Options old_default_opts; old_default_opts.OldDefaults(5, 2); ASSERT_EQ(16 * 1024U * 1024U, old_default_opts.delayed_write_rate); + ASSERT_TRUE(old_default_opts.compaction_pri == + CompactionPri::kByCompensatedSize); + } + { + Options old_default_opts; + old_default_opts.OldDefaults(5, 18); + ASSERT_TRUE(old_default_opts.compaction_pri == + CompactionPri::kByCompensatedSize); } Options small_opts;