From 8432bcf555649ada68bc1bbfaab98967598070dd Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Thu, 2 Mar 2017 10:08:49 -0800 Subject: [PATCH] Make compaction_pri settable through option string Summary: Closes https://github.com/facebook/rocksdb/pull/1941 Differential Revision: D4637253 Pulled By: siying fbshipit-source-id: a59dcdb --- util/options_helper.cc | 8 ++++++++ util/options_helper.h | 14 ++++++++++++-- util/options_parser.cc | 3 +++ util/options_settable_test.cc | 2 +- util/options_test.cc | 2 ++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/util/options_helper.cc b/util/options_helper.cc index a4637fa90..18fae4234 100644 --- a/util/options_helper.cc +++ b/util/options_helper.cc @@ -530,6 +530,10 @@ bool ParseOptionHelper(char* opt_address, const OptionType& opt_type, return ParseEnum( compaction_style_string_map, value, reinterpret_cast(opt_address)); + case OptionType::kCompactionPri: + return ParseEnum( + compaction_pri_string_map, value, + reinterpret_cast(opt_address)); case OptionType::kCompressionType: return ParseEnum( compression_type_string_map, value, @@ -611,6 +615,10 @@ bool SerializeSingleOptionHelper(const char* opt_address, return SerializeEnum( compaction_style_string_map, *(reinterpret_cast(opt_address)), value); + case OptionType::kCompactionPri: + return SerializeEnum( + compaction_pri_string_map, + *(reinterpret_cast(opt_address)), value); case OptionType::kCompressionType: return SerializeEnum( compression_type_string_map, diff --git a/util/options_helper.h b/util/options_helper.h index 85e727877..1de6b1869 100644 --- a/util/options_helper.h +++ b/util/options_helper.h @@ -106,6 +106,7 @@ enum class OptionType { kString, kDouble, kCompactionStyle, + kCompactionPri, kSliceTransform, kCompressionType, kVectorCompressionType, @@ -581,8 +582,10 @@ static std::unordered_map cf_options_type_info = { OptionType::kMergeOperator, OptionVerificationType::kByName, false, 0}}, {"compaction_style", {offset_of(&ColumnFamilyOptions::compaction_style), - OptionType::kCompactionStyle, OptionVerificationType::kNormal, false, - 0}}}; + OptionType::kCompactionStyle, OptionVerificationType::kNormal, false, 0}}, + {"compaction_pri", + {offset_of(&ColumnFamilyOptions::compaction_pri), + OptionType::kCompactionPri, OptionVerificationType::kNormal, false, 0}}}; static std::unordered_map block_based_table_type_info = { @@ -714,6 +717,13 @@ static std::unordered_map {"kCompactionStyleFIFO", kCompactionStyleFIFO}, {"kCompactionStyleNone", kCompactionStyleNone}}; +static std::unordered_map + compaction_pri_string_map = { + {"kByCompensatedSize", kByCompensatedSize}, + {"kOldestLargestSeqFirst", kOldestLargestSeqFirst}, + {"kOldestSmallestSeqFirst", kOldestSmallestSeqFirst}, + {"kMinOverlappingRatio", kMinOverlappingRatio}}; + static std::unordered_map wal_recovery_mode_string_map = { {"kTolerateCorruptedTailRecords", diff --git a/util/options_parser.cc b/util/options_parser.cc index a69a00cb5..58cc19ba5 100644 --- a/util/options_parser.cc +++ b/util/options_parser.cc @@ -542,6 +542,9 @@ bool AreEqualOptions( case OptionType::kCompactionStyle: return (*reinterpret_cast(offset1) == *reinterpret_cast(offset2)); + case OptionType::kCompactionPri: + return (*reinterpret_cast(offset1) == + *reinterpret_cast(offset2)); case OptionType::kCompressionType: return (*reinterpret_cast(offset1) == *reinterpret_cast(offset2)); diff --git a/util/options_settable_test.cc b/util/options_settable_test.cc index 45fa94ef5..1618894e2 100644 --- a/util/options_settable_test.cc +++ b/util/options_settable_test.cc @@ -370,7 +370,6 @@ TEST_F(OptionsSettableTest, ColumnFamilyOptionsAllFieldsSettable) { // Following options are not settable through // GetColumnFamilyOptionsFromString(): options->rate_limit_delay_max_milliseconds = 33; - options->compaction_pri = CompactionPri::kOldestSmallestSeqFirst; options->compaction_options_universal = CompactionOptionsUniversal(); options->compression_opts = CompressionOptions(); options->hard_rate_limit = 0; @@ -428,6 +427,7 @@ TEST_F(OptionsSettableTest, ColumnFamilyOptionsAllFieldsSettable) { "level_compaction_dynamic_level_bytes=false;" "inplace_update_support=false;" "compaction_style=kCompactionStyleFIFO;" + "compaction_pri=kMinOverlappingRatio;" "purge_redundant_kvs_while_flush=true;" "hard_pending_compaction_bytes_limit=0;" "disable_auto_compactions=false;" diff --git a/util/options_test.cc b/util/options_test.cc index ccd3a3322..76bd010fb 100644 --- a/util/options_test.cc +++ b/util/options_test.cc @@ -77,6 +77,7 @@ TEST_F(OptionsTest, GetOptionsFromMapTest) { {"arena_block_size", "22"}, {"disable_auto_compactions", "true"}, {"compaction_style", "kCompactionStyleLevel"}, + {"compaction_pri", "kOldestSmallestSeqFirst"}, {"verify_checksums_in_compaction", "false"}, {"compaction_options_fifo", "23"}, {"max_sequential_skip_in_iterations", "24"}, @@ -174,6 +175,7 @@ TEST_F(OptionsTest, GetOptionsFromMapTest) { ASSERT_EQ(new_cf_opt.arena_block_size, 22U); ASSERT_EQ(new_cf_opt.disable_auto_compactions, true); ASSERT_EQ(new_cf_opt.compaction_style, kCompactionStyleLevel); + ASSERT_EQ(new_cf_opt.compaction_pri, kOldestSmallestSeqFirst); ASSERT_EQ(new_cf_opt.compaction_options_fifo.max_table_files_size, static_cast(23)); ASSERT_EQ(new_cf_opt.max_sequential_skip_in_iterations,