From 6170fec2515948fdce4b8ca3b0aaaec1378f79a9 Mon Sep 17 00:00:00 2001 From: sdong Date: Tue, 17 Nov 2015 16:41:54 -0800 Subject: [PATCH] Fix build broken by previous commit of "option helper refactor" Summary: The commit of option helper refactor broken the build: (1) a git merge problem (2) some uncaught compiler warning Fix it. Test Plan: Make sure "make all" passes Reviewers: anthony, IslamAbdelRahman, rven, kradhakrishnan, yhchiang Reviewed By: yhchiang Subscribers: leveldb, dhruba Differential Revision: https://reviews.facebook.net/D50943 --- table/block_based_table_factory.cc | 8 +-- table/plain_table_factory.h | 6 +-- util/options_helper.cc | 59 ++++++++++++---------- util/options_helper.h | 79 ++++++++++++++---------------- utilities/memory/memory_test.cc | 2 +- 5 files changed, 79 insertions(+), 75 deletions(-) diff --git a/table/block_based_table_factory.cc b/table/block_based_table_factory.cc index e5f2e4ada..3ddb46bf9 100644 --- a/table/block_based_table_factory.cc +++ b/table/block_based_table_factory.cc @@ -24,8 +24,8 @@ namespace rocksdb { BlockBasedTableFactory::BlockBasedTableFactory( - const BlockBasedTableOptions& table_options) - : table_options_(table_options) { + const BlockBasedTableOptions& _table_options) + : table_options_(_table_options) { if (table_options_.flush_block_policy_factory == nullptr) { table_options_.flush_block_policy_factory.reset( new FlushBlockBySizePolicyFactory()); @@ -167,8 +167,8 @@ const BlockBasedTableOptions& BlockBasedTableFactory::table_options() const { } TableFactory* NewBlockBasedTableFactory( - const BlockBasedTableOptions& table_options) { - return new BlockBasedTableFactory(table_options); + const BlockBasedTableOptions& _table_options) { + return new BlockBasedTableFactory(_table_options); } const std::string BlockBasedTablePropertyNames::kIndexType = diff --git a/table/plain_table_factory.h b/table/plain_table_factory.h index 2dd921d32..154cbff06 100644 --- a/table/plain_table_factory.h +++ b/table/plain_table_factory.h @@ -142,9 +142,9 @@ class PlainTableFactory : public TableFactory { // huge_page_tlb_size determines whether to allocate hash indexes from huge // page TLB and the page size if allocating from there. See comments of // Arena::AllocateAligned() for details. - explicit PlainTableFactory(const PlainTableOptions& table_options = - PlainTableOptions()) - : table_options_(table_options) {}; + explicit PlainTableFactory( + const PlainTableOptions& _table_options = PlainTableOptions()) + : table_options_(_table_options) {} const char* Name() const override { return "PlainTable"; } Status NewTableReader(const TableReaderOptions& table_reader_options, diff --git a/util/options_helper.cc b/util/options_helper.cc index 48d137f75..26b4c08ef 100644 --- a/util/options_helper.cc +++ b/util/options_helper.cc @@ -106,10 +106,9 @@ std::string trim(const std::string& str) { return std::string(); } -template -bool ParseEnum(const std::unordered_map& type_map, +template +bool ParseEnum(const std::unordered_map& type_map, const std::string& type, T* value) { - auto iter = type_map.find(type); if (iter != type_map.end()) { *value = iter->second; @@ -118,8 +117,8 @@ bool ParseEnum(const std::unordered_map& type_map, return false; } -template -bool SerializeEnum(const std::unordered_map& type_map, +template +bool SerializeEnum(const std::unordered_map& type_map, const T& type, std::string* value) { for (const auto& pair : type_map) { if (pair.second == type) { @@ -140,7 +139,7 @@ bool SerializeVectorCompressionType(const std::vector& types, } std::string string_type; result = SerializeEnum(compression_type_string_map, - types[i], &string_type); + types[i], &string_type); if (result == false) { return result; } @@ -238,16 +237,16 @@ bool ParseVectorCompressionType( bool is_ok; CompressionType type; if (end == std::string::npos) { - is_ok = ParseEnum(compression_type_string_map, - value.substr(start), &type); + is_ok = ParseEnum(compression_type_string_map, + value.substr(start), &type); if (!is_ok) { return false; } compression_per_level->emplace_back(type); break; } else { - is_ok = ParseEnum(compression_type_string_map, - value.substr(start, end - start), &type); + is_ok = ParseEnum( + compression_type_string_map, value.substr(start, end - start), &type); if (!is_ok) { return false; } @@ -336,11 +335,13 @@ bool ParseOptionHelper(char* opt_address, const OptionType& opt_type, *reinterpret_cast(opt_address) = ParseDouble(value); break; case OptionType::kCompactionStyle: - return ParseEnum(compaction_style_string_map, - value, reinterpret_cast(opt_address)); + return ParseEnum( + compaction_style_string_map, value, + reinterpret_cast(opt_address)); case OptionType::kCompressionType: - return ParseEnum(compression_type_string_map, - value, reinterpret_cast(opt_address)); + return ParseEnum( + compression_type_string_map, value, + reinterpret_cast(opt_address)); case OptionType::kVectorCompressionType: return ParseVectorCompressionType( value, reinterpret_cast*>(opt_address)); @@ -349,15 +350,17 @@ bool ParseOptionHelper(char* opt_address, const OptionType& opt_type, value, reinterpret_cast*>( opt_address)); case OptionType::kChecksumType: - return ParseEnum(checksum_type_string_map, value, - reinterpret_cast(opt_address)); + return ParseEnum( + checksum_type_string_map, value, + reinterpret_cast(opt_address)); case OptionType::kBlockBasedTableIndexType: return ParseEnum( - block_base_table_index_type_string_map, value, - reinterpret_cast(opt_address)); + block_base_table_index_type_string_map, value, + reinterpret_cast(opt_address)); case OptionType::kEncodingType: - return ParseEnum(encoding_type_string_map, value, - reinterpret_cast(opt_address)); + return ParseEnum( + encoding_type_string_map, value, + reinterpret_cast(opt_address)); default: return false; } @@ -398,10 +401,12 @@ bool SerializeSingleOptionHelper(const char* opt_address, *(reinterpret_cast(opt_address))); break; case OptionType::kCompactionStyle: - return SerializeEnum(compaction_style_string_map, + return SerializeEnum( + compaction_style_string_map, *(reinterpret_cast(opt_address)), value); case OptionType::kCompressionType: - return SerializeEnum(compression_type_string_map, + return SerializeEnum( + compression_type_string_map, *(reinterpret_cast(opt_address)), value); case OptionType::kVectorCompressionType: return SerializeVectorCompressionType( @@ -473,7 +478,8 @@ bool SerializeSingleOptionHelper(const char* opt_address, break; } case OptionType::kChecksumType: - return SerializeEnum(checksum_type_string_map, + return SerializeEnum( + checksum_type_string_map, *reinterpret_cast(opt_address), value); case OptionType::kBlockBasedTableIndexType: return SerializeEnum( @@ -489,7 +495,8 @@ bool SerializeSingleOptionHelper(const char* opt_address, break; } case OptionType::kEncodingType: - return SerializeEnum(encoding_type_string_map, + return SerializeEnum( + encoding_type_string_map, *reinterpret_cast(opt_address), value); default: return false; @@ -936,8 +943,8 @@ Status GetStringFromTableFactory(std::string* opts_str, const TableFactory* tf, const auto* bbtf = dynamic_cast(tf); opts_str->clear(); if (bbtf != nullptr) { - return GetStringFromBlockBasedTableOptions( - opts_str, bbtf->table_options(), delimiter); + return GetStringFromBlockBasedTableOptions(opts_str, bbtf->table_options(), + delimiter); } return Status::OK(); diff --git a/util/options_helper.h b/util/options_helper.h index c9b154680..373ffc6be 100644 --- a/util/options_helper.h +++ b/util/options_helper.h @@ -493,55 +493,52 @@ static std::unordered_map plain_table_type_info = { - {"user_key_len", - {offsetof(struct PlainTableOptions, user_key_len), - OptionType::kUInt32T, OptionVerificationType::kNormal}}, - {"bloom_bits_per_key", - {offsetof(struct PlainTableOptions, bloom_bits_per_key), - OptionType::kInt, OptionVerificationType::kNormal}}, - {"hash_table_ratio", - {offsetof(struct PlainTableOptions, hash_table_ratio), - OptionType::kDouble, OptionVerificationType::kNormal}}, - {"index_sparseness", - {offsetof(struct PlainTableOptions, index_sparseness), - OptionType::kSizeT, OptionVerificationType::kNormal}}, - {"huge_page_tlb_size", - {offsetof(struct PlainTableOptions, huge_page_tlb_size), - OptionType::kSizeT, OptionVerificationType::kNormal}}, - {"encoding_type", - {offsetof(struct PlainTableOptions, encoding_type), - OptionType::kEncodingType, OptionVerificationType::kByName}}, - {"full_scan_mode", - {offsetof(struct PlainTableOptions, full_scan_mode), - OptionType::kBoolean, OptionVerificationType::kNormal}}, - {"store_index_in_file", - {offsetof(struct PlainTableOptions, store_index_in_file), - OptionType::kBoolean, OptionVerificationType::kNormal}}}; +static std::unordered_map plain_table_type_info = { + {"user_key_len", + {offsetof(struct PlainTableOptions, user_key_len), OptionType::kUInt32T, + OptionVerificationType::kNormal}}, + {"bloom_bits_per_key", + {offsetof(struct PlainTableOptions, bloom_bits_per_key), OptionType::kInt, + OptionVerificationType::kNormal}}, + {"hash_table_ratio", + {offsetof(struct PlainTableOptions, hash_table_ratio), OptionType::kDouble, + OptionVerificationType::kNormal}}, + {"index_sparseness", + {offsetof(struct PlainTableOptions, index_sparseness), OptionType::kSizeT, + OptionVerificationType::kNormal}}, + {"huge_page_tlb_size", + {offsetof(struct PlainTableOptions, huge_page_tlb_size), + OptionType::kSizeT, OptionVerificationType::kNormal}}, + {"encoding_type", + {offsetof(struct PlainTableOptions, encoding_type), + OptionType::kEncodingType, OptionVerificationType::kByName}}, + {"full_scan_mode", + {offsetof(struct PlainTableOptions, full_scan_mode), OptionType::kBoolean, + OptionVerificationType::kNormal}}, + {"store_index_in_file", + {offsetof(struct PlainTableOptions, store_index_in_file), + OptionType::kBoolean, OptionVerificationType::kNormal}}}; -static std::unordered_map +static std::unordered_map compression_type_string_map = { - {"kNoCompression", kNoCompression}, - {"kSnappyCompression", kSnappyCompression}, - {"kZlibCompression", kZlibCompression}, - {"kBZip2Compression", kBZip2Compression}, - {"kLZ4Compression", kLZ4Compression}, - {"kLZ4HCCompression", kLZ4HCCompression}, - {"kZSTDNotFinalCompression", kZSTDNotFinalCompression} -}; + {"kNoCompression", kNoCompression}, + {"kSnappyCompression", kSnappyCompression}, + {"kZlibCompression", kZlibCompression}, + {"kBZip2Compression", kBZip2Compression}, + {"kLZ4Compression", kLZ4Compression}, + {"kLZ4HCCompression", kLZ4HCCompression}, + {"kZSTDNotFinalCompression", kZSTDNotFinalCompression}}; static std::unordered_map - block_base_table_index_type_string_map = { + block_base_table_index_type_string_map = { {"kBinarySearch", BlockBasedTableOptions::IndexType::kBinarySearch}, {"kHashSearch", BlockBasedTableOptions::IndexType::kHashSearch}}; -static std::unordered_map - encoding_type_string_map = {{"kPlain", kPlain}, {"kPrefix", kPrefix}}; +static std::unordered_map encoding_type_string_map = + {{"kPlain", kPlain}, {"kPrefix", kPrefix}}; -static std::unordered_map - checksum_type_string_map = { - {"kNoChecksum", kNoChecksum}, {"kCRC32c", kCRC32c}, {"kxxHash", kxxHash}}; +static std::unordered_map checksum_type_string_map = + {{"kNoChecksum", kNoChecksum}, {"kCRC32c", kCRC32c}, {"kxxHash", kxxHash}}; static std::unordered_map compaction_style_string_map = { diff --git a/utilities/memory/memory_test.cc b/utilities/memory/memory_test.cc index e18723d5c..079514736 100644 --- a/utilities/memory/memory_test.cc +++ b/utilities/memory/memory_test.cc @@ -46,7 +46,7 @@ class MemoryTest : public testing::Test { const BlockBasedTableFactory* bbtf = dynamic_cast(factory); if (bbtf != nullptr) { - const auto bbt_opts = bbtf->GetTableOptions(); + const auto bbt_opts = bbtf->table_options(); cache_set->insert(bbt_opts.block_cache.get()); cache_set->insert(bbt_opts.block_cache_compressed.get()); }