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
main
sdong 9 years ago
parent 3a6643c2fd
commit 6170fec251
  1. 8
      table/block_based_table_factory.cc
  2. 6
      table/plain_table_factory.h
  3. 59
      util/options_helper.cc
  4. 79
      util/options_helper.h
  5. 2
      utilities/memory/memory_test.cc

@ -24,8 +24,8 @@
namespace rocksdb { namespace rocksdb {
BlockBasedTableFactory::BlockBasedTableFactory( BlockBasedTableFactory::BlockBasedTableFactory(
const BlockBasedTableOptions& table_options) const BlockBasedTableOptions& _table_options)
: table_options_(table_options) { : table_options_(_table_options) {
if (table_options_.flush_block_policy_factory == nullptr) { if (table_options_.flush_block_policy_factory == nullptr) {
table_options_.flush_block_policy_factory.reset( table_options_.flush_block_policy_factory.reset(
new FlushBlockBySizePolicyFactory()); new FlushBlockBySizePolicyFactory());
@ -167,8 +167,8 @@ const BlockBasedTableOptions& BlockBasedTableFactory::table_options() const {
} }
TableFactory* NewBlockBasedTableFactory( TableFactory* NewBlockBasedTableFactory(
const BlockBasedTableOptions& table_options) { const BlockBasedTableOptions& _table_options) {
return new BlockBasedTableFactory(table_options); return new BlockBasedTableFactory(_table_options);
} }
const std::string BlockBasedTablePropertyNames::kIndexType = const std::string BlockBasedTablePropertyNames::kIndexType =

@ -142,9 +142,9 @@ class PlainTableFactory : public TableFactory {
// huge_page_tlb_size determines whether to allocate hash indexes from huge // 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 // page TLB and the page size if allocating from there. See comments of
// Arena::AllocateAligned() for details. // Arena::AllocateAligned() for details.
explicit PlainTableFactory(const PlainTableOptions& table_options = explicit PlainTableFactory(
PlainTableOptions()) const PlainTableOptions& _table_options = PlainTableOptions())
: table_options_(table_options) {}; : table_options_(_table_options) {}
const char* Name() const override { return "PlainTable"; } const char* Name() const override { return "PlainTable"; }
Status NewTableReader(const TableReaderOptions& table_reader_options, Status NewTableReader(const TableReaderOptions& table_reader_options,

@ -106,10 +106,9 @@ std::string trim(const std::string& str) {
return std::string(); return std::string();
} }
template<typename T> template <typename T>
bool ParseEnum(const std::unordered_map<std::string,T>& type_map, bool ParseEnum(const std::unordered_map<std::string, T>& type_map,
const std::string& type, T* value) { const std::string& type, T* value) {
auto iter = type_map.find(type); auto iter = type_map.find(type);
if (iter != type_map.end()) { if (iter != type_map.end()) {
*value = iter->second; *value = iter->second;
@ -118,8 +117,8 @@ bool ParseEnum(const std::unordered_map<std::string,T>& type_map,
return false; return false;
} }
template<typename T> template <typename T>
bool SerializeEnum(const std::unordered_map<std::string,T>& type_map, bool SerializeEnum(const std::unordered_map<std::string, T>& type_map,
const T& type, std::string* value) { const T& type, std::string* value) {
for (const auto& pair : type_map) { for (const auto& pair : type_map) {
if (pair.second == type) { if (pair.second == type) {
@ -140,7 +139,7 @@ bool SerializeVectorCompressionType(const std::vector<CompressionType>& types,
} }
std::string string_type; std::string string_type;
result = SerializeEnum<CompressionType>(compression_type_string_map, result = SerializeEnum<CompressionType>(compression_type_string_map,
types[i], &string_type); types[i], &string_type);
if (result == false) { if (result == false) {
return result; return result;
} }
@ -238,16 +237,16 @@ bool ParseVectorCompressionType(
bool is_ok; bool is_ok;
CompressionType type; CompressionType type;
if (end == std::string::npos) { if (end == std::string::npos) {
is_ok = ParseEnum<CompressionType>(compression_type_string_map, is_ok = ParseEnum<CompressionType>(compression_type_string_map,
value.substr(start), &type); value.substr(start), &type);
if (!is_ok) { if (!is_ok) {
return false; return false;
} }
compression_per_level->emplace_back(type); compression_per_level->emplace_back(type);
break; break;
} else { } else {
is_ok = ParseEnum<CompressionType>(compression_type_string_map, is_ok = ParseEnum<CompressionType>(
value.substr(start, end - start), &type); compression_type_string_map, value.substr(start, end - start), &type);
if (!is_ok) { if (!is_ok) {
return false; return false;
} }
@ -336,11 +335,13 @@ bool ParseOptionHelper(char* opt_address, const OptionType& opt_type,
*reinterpret_cast<double*>(opt_address) = ParseDouble(value); *reinterpret_cast<double*>(opt_address) = ParseDouble(value);
break; break;
case OptionType::kCompactionStyle: case OptionType::kCompactionStyle:
return ParseEnum<CompactionStyle>(compaction_style_string_map, return ParseEnum<CompactionStyle>(
value, reinterpret_cast<CompactionStyle*>(opt_address)); compaction_style_string_map, value,
reinterpret_cast<CompactionStyle*>(opt_address));
case OptionType::kCompressionType: case OptionType::kCompressionType:
return ParseEnum<CompressionType>(compression_type_string_map, return ParseEnum<CompressionType>(
value, reinterpret_cast<CompressionType*>(opt_address)); compression_type_string_map, value,
reinterpret_cast<CompressionType*>(opt_address));
case OptionType::kVectorCompressionType: case OptionType::kVectorCompressionType:
return ParseVectorCompressionType( return ParseVectorCompressionType(
value, reinterpret_cast<std::vector<CompressionType>*>(opt_address)); value, reinterpret_cast<std::vector<CompressionType>*>(opt_address));
@ -349,15 +350,17 @@ bool ParseOptionHelper(char* opt_address, const OptionType& opt_type,
value, reinterpret_cast<std::shared_ptr<const SliceTransform>*>( value, reinterpret_cast<std::shared_ptr<const SliceTransform>*>(
opt_address)); opt_address));
case OptionType::kChecksumType: case OptionType::kChecksumType:
return ParseEnum<ChecksumType>(checksum_type_string_map, value, return ParseEnum<ChecksumType>(
reinterpret_cast<ChecksumType*>(opt_address)); checksum_type_string_map, value,
reinterpret_cast<ChecksumType*>(opt_address));
case OptionType::kBlockBasedTableIndexType: case OptionType::kBlockBasedTableIndexType:
return ParseEnum<BlockBasedTableOptions::IndexType>( return ParseEnum<BlockBasedTableOptions::IndexType>(
block_base_table_index_type_string_map, value, block_base_table_index_type_string_map, value,
reinterpret_cast<BlockBasedTableOptions::IndexType*>(opt_address)); reinterpret_cast<BlockBasedTableOptions::IndexType*>(opt_address));
case OptionType::kEncodingType: case OptionType::kEncodingType:
return ParseEnum<EncodingType>(encoding_type_string_map, value, return ParseEnum<EncodingType>(
reinterpret_cast<EncodingType*>(opt_address)); encoding_type_string_map, value,
reinterpret_cast<EncodingType*>(opt_address));
default: default:
return false; return false;
} }
@ -398,10 +401,12 @@ bool SerializeSingleOptionHelper(const char* opt_address,
*(reinterpret_cast<const std::string*>(opt_address))); *(reinterpret_cast<const std::string*>(opt_address)));
break; break;
case OptionType::kCompactionStyle: case OptionType::kCompactionStyle:
return SerializeEnum<CompactionStyle>(compaction_style_string_map, return SerializeEnum<CompactionStyle>(
compaction_style_string_map,
*(reinterpret_cast<const CompactionStyle*>(opt_address)), value); *(reinterpret_cast<const CompactionStyle*>(opt_address)), value);
case OptionType::kCompressionType: case OptionType::kCompressionType:
return SerializeEnum<CompressionType>(compression_type_string_map, return SerializeEnum<CompressionType>(
compression_type_string_map,
*(reinterpret_cast<const CompressionType*>(opt_address)), value); *(reinterpret_cast<const CompressionType*>(opt_address)), value);
case OptionType::kVectorCompressionType: case OptionType::kVectorCompressionType:
return SerializeVectorCompressionType( return SerializeVectorCompressionType(
@ -473,7 +478,8 @@ bool SerializeSingleOptionHelper(const char* opt_address,
break; break;
} }
case OptionType::kChecksumType: case OptionType::kChecksumType:
return SerializeEnum<ChecksumType>(checksum_type_string_map, return SerializeEnum<ChecksumType>(
checksum_type_string_map,
*reinterpret_cast<const ChecksumType*>(opt_address), value); *reinterpret_cast<const ChecksumType*>(opt_address), value);
case OptionType::kBlockBasedTableIndexType: case OptionType::kBlockBasedTableIndexType:
return SerializeEnum<BlockBasedTableOptions::IndexType>( return SerializeEnum<BlockBasedTableOptions::IndexType>(
@ -489,7 +495,8 @@ bool SerializeSingleOptionHelper(const char* opt_address,
break; break;
} }
case OptionType::kEncodingType: case OptionType::kEncodingType:
return SerializeEnum<EncodingType>(encoding_type_string_map, return SerializeEnum<EncodingType>(
encoding_type_string_map,
*reinterpret_cast<const EncodingType*>(opt_address), value); *reinterpret_cast<const EncodingType*>(opt_address), value);
default: default:
return false; return false;
@ -936,8 +943,8 @@ Status GetStringFromTableFactory(std::string* opts_str, const TableFactory* tf,
const auto* bbtf = dynamic_cast<const BlockBasedTableFactory*>(tf); const auto* bbtf = dynamic_cast<const BlockBasedTableFactory*>(tf);
opts_str->clear(); opts_str->clear();
if (bbtf != nullptr) { if (bbtf != nullptr) {
return GetStringFromBlockBasedTableOptions( return GetStringFromBlockBasedTableOptions(opts_str, bbtf->table_options(),
opts_str, bbtf->table_options(), delimiter); delimiter);
} }
return Status::OK(); return Status::OK();

@ -493,55 +493,52 @@ static std::unordered_map<std::string,
{offsetof(struct BlockBasedTableOptions, format_version), {offsetof(struct BlockBasedTableOptions, format_version),
OptionType::kUInt32T, OptionVerificationType::kNormal}}}; OptionType::kUInt32T, OptionVerificationType::kNormal}}};
static std::unordered_map<std::string, static std::unordered_map<std::string, OptionTypeInfo> plain_table_type_info = {
OptionTypeInfo> plain_table_type_info = { {"user_key_len",
{"user_key_len", {offsetof(struct PlainTableOptions, user_key_len), OptionType::kUInt32T,
{offsetof(struct PlainTableOptions, user_key_len), OptionVerificationType::kNormal}},
OptionType::kUInt32T, OptionVerificationType::kNormal}}, {"bloom_bits_per_key",
{"bloom_bits_per_key", {offsetof(struct PlainTableOptions, bloom_bits_per_key), OptionType::kInt,
{offsetof(struct PlainTableOptions, bloom_bits_per_key), OptionVerificationType::kNormal}},
OptionType::kInt, OptionVerificationType::kNormal}}, {"hash_table_ratio",
{"hash_table_ratio", {offsetof(struct PlainTableOptions, hash_table_ratio), OptionType::kDouble,
{offsetof(struct PlainTableOptions, hash_table_ratio), OptionVerificationType::kNormal}},
OptionType::kDouble, OptionVerificationType::kNormal}}, {"index_sparseness",
{"index_sparseness", {offsetof(struct PlainTableOptions, index_sparseness), OptionType::kSizeT,
{offsetof(struct PlainTableOptions, index_sparseness), OptionVerificationType::kNormal}},
OptionType::kSizeT, OptionVerificationType::kNormal}}, {"huge_page_tlb_size",
{"huge_page_tlb_size", {offsetof(struct PlainTableOptions, huge_page_tlb_size),
{offsetof(struct PlainTableOptions, huge_page_tlb_size), OptionType::kSizeT, OptionVerificationType::kNormal}},
OptionType::kSizeT, OptionVerificationType::kNormal}}, {"encoding_type",
{"encoding_type", {offsetof(struct PlainTableOptions, encoding_type),
{offsetof(struct PlainTableOptions, encoding_type), OptionType::kEncodingType, OptionVerificationType::kByName}},
OptionType::kEncodingType, OptionVerificationType::kByName}}, {"full_scan_mode",
{"full_scan_mode", {offsetof(struct PlainTableOptions, full_scan_mode), OptionType::kBoolean,
{offsetof(struct PlainTableOptions, full_scan_mode), OptionVerificationType::kNormal}},
OptionType::kBoolean, OptionVerificationType::kNormal}}, {"store_index_in_file",
{"store_index_in_file", {offsetof(struct PlainTableOptions, store_index_in_file),
{offsetof(struct PlainTableOptions, store_index_in_file), OptionType::kBoolean, OptionVerificationType::kNormal}}};
OptionType::kBoolean, OptionVerificationType::kNormal}}};
static std::unordered_map<std::string, CompressionType> static std::unordered_map<std::string, CompressionType>
compression_type_string_map = { compression_type_string_map = {
{"kNoCompression", kNoCompression}, {"kNoCompression", kNoCompression},
{"kSnappyCompression", kSnappyCompression}, {"kSnappyCompression", kSnappyCompression},
{"kZlibCompression", kZlibCompression}, {"kZlibCompression", kZlibCompression},
{"kBZip2Compression", kBZip2Compression}, {"kBZip2Compression", kBZip2Compression},
{"kLZ4Compression", kLZ4Compression}, {"kLZ4Compression", kLZ4Compression},
{"kLZ4HCCompression", kLZ4HCCompression}, {"kLZ4HCCompression", kLZ4HCCompression},
{"kZSTDNotFinalCompression", kZSTDNotFinalCompression} {"kZSTDNotFinalCompression", kZSTDNotFinalCompression}};
};
static std::unordered_map<std::string, BlockBasedTableOptions::IndexType> static std::unordered_map<std::string, BlockBasedTableOptions::IndexType>
block_base_table_index_type_string_map = { block_base_table_index_type_string_map = {
{"kBinarySearch", BlockBasedTableOptions::IndexType::kBinarySearch}, {"kBinarySearch", BlockBasedTableOptions::IndexType::kBinarySearch},
{"kHashSearch", BlockBasedTableOptions::IndexType::kHashSearch}}; {"kHashSearch", BlockBasedTableOptions::IndexType::kHashSearch}};
static std::unordered_map<std::string, EncodingType> static std::unordered_map<std::string, EncodingType> encoding_type_string_map =
encoding_type_string_map = {{"kPlain", kPlain}, {"kPrefix", kPrefix}}; {{"kPlain", kPlain}, {"kPrefix", kPrefix}};
static std::unordered_map<std::string, ChecksumType> static std::unordered_map<std::string, ChecksumType> checksum_type_string_map =
checksum_type_string_map = { {{"kNoChecksum", kNoChecksum}, {"kCRC32c", kCRC32c}, {"kxxHash", kxxHash}};
{"kNoChecksum", kNoChecksum}, {"kCRC32c", kCRC32c}, {"kxxHash", kxxHash}};
static std::unordered_map<std::string, CompactionStyle> static std::unordered_map<std::string, CompactionStyle>
compaction_style_string_map = { compaction_style_string_map = {

@ -46,7 +46,7 @@ class MemoryTest : public testing::Test {
const BlockBasedTableFactory* bbtf = const BlockBasedTableFactory* bbtf =
dynamic_cast<const BlockBasedTableFactory*>(factory); dynamic_cast<const BlockBasedTableFactory*>(factory);
if (bbtf != nullptr) { 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.get());
cache_set->insert(bbt_opts.block_cache_compressed.get()); cache_set->insert(bbt_opts.block_cache_compressed.get());
} }

Loading…
Cancel
Save