From deb08b8226a6e54038c48d62394c585a94a7f181 Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Wed, 2 Mar 2016 10:34:14 -0800 Subject: [PATCH] Add parsing of missing DB options Summary: There are a few options in struct DBOptions that aren't handled by options_helper.cc. Add those missing options so they can be used by GetDBOptionsFromString() and friends. Test Plan: Updated options_test.cc, reran all tests. Reviewers: sdong, yhchiang Reviewed By: yhchiang Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D54603 --- util/options_helper.cc | 24 +++++++++++++++++++ util/options_helper.h | 52 +++++++++++++++++++++++++++++++++++++++--- util/options_parser.cc | 9 ++++++++ util/options_test.cc | 20 ++++++++-------- 4 files changed, 91 insertions(+), 14 deletions(-) diff --git a/util/options_helper.cc b/util/options_helper.cc index 44b57f48b..679d0a1b4 100644 --- a/util/options_helper.cc +++ b/util/options_helper.cc @@ -361,6 +361,18 @@ bool ParseOptionHelper(char* opt_address, const OptionType& opt_type, return ParseEnum( encoding_type_string_map, value, reinterpret_cast(opt_address)); + case OptionType::kWALRecoveryMode: + return ParseEnum( + wal_recovery_mode_string_map, value, + reinterpret_cast(opt_address)); + case OptionType::kAccessHint: + return ParseEnum( + access_hint_string_map, value, + reinterpret_cast(opt_address)); + case OptionType::kInfoLogLevel: + return ParseEnum( + info_log_level_string_map, value, + reinterpret_cast(opt_address)); default: return false; } @@ -498,6 +510,18 @@ bool SerializeSingleOptionHelper(const char* opt_address, return SerializeEnum( encoding_type_string_map, *reinterpret_cast(opt_address), value); + case OptionType::kWALRecoveryMode: + return SerializeEnum( + wal_recovery_mode_string_map, + *reinterpret_cast(opt_address), value); + case OptionType::kAccessHint: + return SerializeEnum( + access_hint_string_map, + *reinterpret_cast(opt_address), value); + case OptionType::kInfoLogLevel: + return SerializeEnum( + info_log_level_string_map, + *reinterpret_cast(opt_address), value); default: return false; } diff --git a/util/options_helper.h b/util/options_helper.h index fc7e2c2e2..b0864442c 100644 --- a/util/options_helper.h +++ b/util/options_helper.h @@ -93,6 +93,9 @@ enum class OptionType { kFlushBlockPolicyFactory, kChecksumType, kEncodingType, + kWALRecoveryMode, + kAccessHint, + kInfoLogLevel, kUnknown }; @@ -143,10 +146,7 @@ Status GetColumnFamilyOptionsFromMapInternal( static std::unordered_map db_options_type_info = { /* // not yet supported - AccessHint access_hint_on_compaction_start; Env* env; - InfoLogLevel info_log_level; - WALRecoveryMode wal_recovery_mode; std::shared_ptr row_cache; std::shared_ptr delete_scheduler; std::shared_ptr info_log; @@ -289,6 +289,30 @@ static std::unordered_map db_options_type_info = { OptionVerificationType::kNormal}}, {"stats_dump_period_sec", {offsetof(struct DBOptions, stats_dump_period_sec), OptionType::kUInt, + OptionVerificationType::kNormal}}, + {"fail_if_options_file_error", + {offsetof(struct DBOptions, fail_if_options_file_error), + OptionType::kBoolean, OptionVerificationType::kNormal}}, + {"allow_concurrent_memtable_write", + {offsetof(struct DBOptions, allow_concurrent_memtable_write), + OptionType::kBoolean, OptionVerificationType::kNormal}}, + {"wal_recovery_mode", + {offsetof(struct DBOptions, wal_recovery_mode), + OptionType::kWALRecoveryMode, OptionVerificationType::kNormal}}, + {"enable_write_thread_adaptive_yield", + {offsetof(struct DBOptions, enable_write_thread_adaptive_yield), + OptionType::kBoolean, OptionVerificationType::kNormal}}, + {"write_thread_slow_yield_usec", + {offsetof(struct DBOptions, write_thread_slow_yield_usec), + OptionType::kUInt64T, OptionVerificationType::kNormal}}, + {"write_thread_max_yield_usec", + {offsetof(struct DBOptions, write_thread_max_yield_usec), + OptionType::kUInt64T, OptionVerificationType::kNormal}}, + {"access_hint_on_compaction_start", + {offsetof(struct DBOptions, access_hint_on_compaction_start), + OptionType::kAccessHint, OptionVerificationType::kNormal}}, + {"info_log_level", + {offsetof(struct DBOptions, info_log_level), OptionType::kInfoLogLevel, OptionVerificationType::kNormal}}}; static std::unordered_map cf_options_type_info = { @@ -558,6 +582,28 @@ static std::unordered_map {"kCompactionStyleFIFO", kCompactionStyleFIFO}, {"kCompactionStyleNone", kCompactionStyleNone}}; +static std::unordered_map wal_recovery_mode_string_map = { + {"kTolerateCorruptedTailRecords", + WALRecoveryMode::kTolerateCorruptedTailRecords}, + {"kAbsoluteConsistency", WALRecoveryMode::kAbsoluteConsistency}, + {"kPointInTimeRecovery", WALRecoveryMode::kPointInTimeRecovery}, + {"kSkipAnyCorruptedRecords", WALRecoveryMode::kSkipAnyCorruptedRecords}}; + +static std::unordered_map + access_hint_string_map = {{"NONE", DBOptions::AccessHint::NONE}, + {"NORMAL", DBOptions::AccessHint::NORMAL}, + {"SEQUENTIAL", DBOptions::AccessHint::SEQUENTIAL}, + {"WILLNEED", DBOptions::AccessHint::WILLNEED}}; + +static std::unordered_map info_log_level_string_map = + {{"DEBUG_LEVEL", InfoLogLevel::DEBUG_LEVEL}, + {"INFO_LEVEL", InfoLogLevel::INFO_LEVEL}, + {"WARN_LEVEL", InfoLogLevel::WARN_LEVEL}, + {"ERROR_LEVEL", InfoLogLevel::ERROR_LEVEL}, + {"FATAL_LEVEL", InfoLogLevel::FATAL_LEVEL}, + {"HEADER_LEVEL", InfoLogLevel::HEADER_LEVEL}}; + } // namespace rocksdb #endif // !ROCKSDB_LITE diff --git a/util/options_parser.cc b/util/options_parser.cc index e01529bff..0c368c646 100644 --- a/util/options_parser.cc +++ b/util/options_parser.cc @@ -557,6 +557,15 @@ bool AreEqualOptions( *reinterpret_cast( offset1) == *reinterpret_cast(offset2)); + case OptionType::kWALRecoveryMode: + return (*reinterpret_cast(offset1) == + *reinterpret_cast(offset2)); + case OptionType::kAccessHint: + return (*reinterpret_cast(offset1) == + *reinterpret_cast(offset2)); + case OptionType::kInfoLogLevel: + return (*reinterpret_cast(offset1) == + *reinterpret_cast(offset2)); default: if (type_info.verification == OptionVerificationType::kByName || type_info.verification == OptionVerificationType::kByNameAllowNull) { diff --git a/util/options_test.cc b/util/options_test.cc index 02f128d69..f36da9282 100644 --- a/util/options_test.cc +++ b/util/options_test.cc @@ -1653,16 +1653,6 @@ TEST_F(OptionsParserTest, DBOptionsAllFieldsSettable) { options = new (options_ptr) DBOptions(); FillWithSpecialChar(options_ptr, sizeof(DBOptions), kDBOptionsBlacklist); - // Following options are not settable through GetDBOptionsFromString(): - options->fail_if_options_file_error = false; - options->allow_concurrent_memtable_write = false; - options->wal_recovery_mode = WALRecoveryMode::kPointInTimeRecovery; - options->enable_write_thread_adaptive_yield = true; - options->write_thread_slow_yield_usec = true; - options->write_thread_max_yield_usec = 1000u; - options->access_hint_on_compaction_start = DBOptions::AccessHint::NONE; - options->info_log_level = InfoLogLevel::DEBUG_LEVEL; - char* new_options_ptr = new char[sizeof(DBOptions)]; DBOptions* new_options = new (new_options_ptr) DBOptions(); FillWithSpecialChar(new_options_ptr, sizeof(DBOptions), kDBOptionsBlacklist); @@ -1714,7 +1704,15 @@ TEST_F(OptionsParserTest, DBOptionsAllFieldsSettable) { "allow_mmap_reads=false;" "max_log_file_size=4607;" "random_access_max_buffer_size=1048576;" - "advise_random_on_open=true;", + "advise_random_on_open=true;" + "fail_if_options_file_error=false;" + "allow_concurrent_memtable_write=true;" + "wal_recovery_mode=kPointInTimeRecovery;" + "enable_write_thread_adaptive_yield=true;" + "write_thread_slow_yield_usec=5;" + "write_thread_max_yield_usec=1000;" + "access_hint_on_compaction_start=NONE;" + "info_log_level=DEBUG_LEVEL;", new_options)); ASSERT_EQ(unset_bytes_base, NumUnsetBytes(new_options_ptr, sizeof(DBOptions),