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 {
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 =

@ -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,

@ -106,10 +106,9 @@ std::string trim(const std::string& str) {
return std::string();
}
template<typename T>
bool ParseEnum(const std::unordered_map<std::string,T>& type_map,
template <typename T>
bool ParseEnum(const std::unordered_map<std::string, T>& 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<std::string,T>& type_map,
return false;
}
template<typename T>
bool SerializeEnum(const std::unordered_map<std::string,T>& type_map,
template <typename T>
bool SerializeEnum(const std::unordered_map<std::string, T>& 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<CompressionType>& types,
}
std::string string_type;
result = SerializeEnum<CompressionType>(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<CompressionType>(compression_type_string_map,
value.substr(start), &type);
is_ok = ParseEnum<CompressionType>(compression_type_string_map,
value.substr(start), &type);
if (!is_ok) {
return false;
}
compression_per_level->emplace_back(type);
break;
} else {
is_ok = ParseEnum<CompressionType>(compression_type_string_map,
value.substr(start, end - start), &type);
is_ok = ParseEnum<CompressionType>(
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<double*>(opt_address) = ParseDouble(value);
break;
case OptionType::kCompactionStyle:
return ParseEnum<CompactionStyle>(compaction_style_string_map,
value, reinterpret_cast<CompactionStyle*>(opt_address));
return ParseEnum<CompactionStyle>(
compaction_style_string_map, value,
reinterpret_cast<CompactionStyle*>(opt_address));
case OptionType::kCompressionType:
return ParseEnum<CompressionType>(compression_type_string_map,
value, reinterpret_cast<CompressionType*>(opt_address));
return ParseEnum<CompressionType>(
compression_type_string_map, value,
reinterpret_cast<CompressionType*>(opt_address));
case OptionType::kVectorCompressionType:
return ParseVectorCompressionType(
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>*>(
opt_address));
case OptionType::kChecksumType:
return ParseEnum<ChecksumType>(checksum_type_string_map, value,
reinterpret_cast<ChecksumType*>(opt_address));
return ParseEnum<ChecksumType>(
checksum_type_string_map, value,
reinterpret_cast<ChecksumType*>(opt_address));
case OptionType::kBlockBasedTableIndexType:
return ParseEnum<BlockBasedTableOptions::IndexType>(
block_base_table_index_type_string_map, value,
reinterpret_cast<BlockBasedTableOptions::IndexType*>(opt_address));
block_base_table_index_type_string_map, value,
reinterpret_cast<BlockBasedTableOptions::IndexType*>(opt_address));
case OptionType::kEncodingType:
return ParseEnum<EncodingType>(encoding_type_string_map, value,
reinterpret_cast<EncodingType*>(opt_address));
return ParseEnum<EncodingType>(
encoding_type_string_map, value,
reinterpret_cast<EncodingType*>(opt_address));
default:
return false;
}
@ -398,10 +401,12 @@ bool SerializeSingleOptionHelper(const char* opt_address,
*(reinterpret_cast<const std::string*>(opt_address)));
break;
case OptionType::kCompactionStyle:
return SerializeEnum<CompactionStyle>(compaction_style_string_map,
return SerializeEnum<CompactionStyle>(
compaction_style_string_map,
*(reinterpret_cast<const CompactionStyle*>(opt_address)), value);
case OptionType::kCompressionType:
return SerializeEnum<CompressionType>(compression_type_string_map,
return SerializeEnum<CompressionType>(
compression_type_string_map,
*(reinterpret_cast<const CompressionType*>(opt_address)), value);
case OptionType::kVectorCompressionType:
return SerializeVectorCompressionType(
@ -473,7 +478,8 @@ bool SerializeSingleOptionHelper(const char* opt_address,
break;
}
case OptionType::kChecksumType:
return SerializeEnum<ChecksumType>(checksum_type_string_map,
return SerializeEnum<ChecksumType>(
checksum_type_string_map,
*reinterpret_cast<const ChecksumType*>(opt_address), value);
case OptionType::kBlockBasedTableIndexType:
return SerializeEnum<BlockBasedTableOptions::IndexType>(
@ -489,7 +495,8 @@ bool SerializeSingleOptionHelper(const char* opt_address,
break;
}
case OptionType::kEncodingType:
return SerializeEnum<EncodingType>(encoding_type_string_map,
return SerializeEnum<EncodingType>(
encoding_type_string_map,
*reinterpret_cast<const EncodingType*>(opt_address), value);
default:
return false;
@ -936,8 +943,8 @@ Status GetStringFromTableFactory(std::string* opts_str, const TableFactory* tf,
const auto* bbtf = dynamic_cast<const BlockBasedTableFactory*>(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();

@ -493,55 +493,52 @@ static std::unordered_map<std::string,
{offsetof(struct BlockBasedTableOptions, format_version),
OptionType::kUInt32T, OptionVerificationType::kNormal}}};
static std::unordered_map<std::string,
OptionTypeInfo> 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<std::string, OptionTypeInfo> 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<std::string, CompressionType>
static std::unordered_map<std::string, CompressionType>
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<std::string, BlockBasedTableOptions::IndexType>
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<std::string, EncodingType>
encoding_type_string_map = {{"kPlain", kPlain}, {"kPrefix", kPrefix}};
static std::unordered_map<std::string, EncodingType> encoding_type_string_map =
{{"kPlain", kPlain}, {"kPrefix", kPrefix}};
static std::unordered_map<std::string, ChecksumType>
checksum_type_string_map = {
{"kNoChecksum", kNoChecksum}, {"kCRC32c", kCRC32c}, {"kxxHash", kxxHash}};
static std::unordered_map<std::string, ChecksumType> checksum_type_string_map =
{{"kNoChecksum", kNoChecksum}, {"kCRC32c", kCRC32c}, {"kxxHash", kxxHash}};
static std::unordered_map<std::string, CompactionStyle>
compaction_style_string_map = {

@ -46,7 +46,7 @@ class MemoryTest : public testing::Test {
const BlockBasedTableFactory* bbtf =
dynamic_cast<const BlockBasedTableFactory*>(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());
}

Loading…
Cancel
Save