Revert the changes related to Options, as requested to seperate them into

a different patch.
main
unknown 10 years ago committed by Dmitri Smirnov
parent d8586ab22b
commit 5c79132335
  1. 14
      include/rocksdb/utilities/convenience.h
  2. 31
      table/plain_table_builder.cc
  3. 12
      table/plain_table_builder.h
  4. 38
      table/plain_table_factory.cc
  5. 46
      table/plain_table_factory.h
  6. 22
      table/plain_table_reader.cc
  7. 12
      table/plain_table_reader.h
  8. 101
      util/options_helper.cc
  9. 79
      util/options_test.cc

@ -30,11 +30,6 @@ Status GetBlockBasedTableOptionsFromMap(
const std::unordered_map<std::string, std::string>& opts_map, const std::unordered_map<std::string, std::string>& opts_map,
BlockBasedTableOptions* new_table_options); BlockBasedTableOptions* new_table_options);
Status GetPlainTableOptionsFromMap(
const PlainTableOptions& table_options,
const std::unordered_map<std::string, std::string>& opts_map,
PlainTableOptions* new_table_options);
// Take a string representation of option names and values, apply them into the // Take a string representation of option names and values, apply them into the
// base_options, and return the new options as a result. The string has the // base_options, and return the new options as a result. The string has the
// following format: // following format:
@ -53,20 +48,11 @@ Status GetDBOptionsFromString(
const std::string& opts_str, const std::string& opts_str,
DBOptions* new_options); DBOptions* new_options);
Status GetPlainTableOptionsFromString(
const PlainTableOptions& table_options,
const std::string& opts_str,
PlainTableOptions* new_table_options);
Status GetBlockBasedTableOptionsFromString( Status GetBlockBasedTableOptionsFromString(
const BlockBasedTableOptions& table_options, const BlockBasedTableOptions& table_options,
const std::string& opts_str, const std::string& opts_str,
BlockBasedTableOptions* new_table_options); BlockBasedTableOptions* new_table_options);
Status GetMemTableRepFactoryFromString(
const std::string& opts_str,
MemTableRepFactory** new_mem_factory);
Status GetOptionsFromString(const Options& base_options, Status GetOptionsFromString(const Options& base_options,
const std::string& opts_str, Options* new_options); const std::string& opts_str, Options* new_options);

@ -60,32 +60,33 @@ extern const uint64_t kLegacyPlainTableMagicNumber = 0x4f3418eb7a8f13b8ull;
PlainTableBuilder::PlainTableBuilder( PlainTableBuilder::PlainTableBuilder(
const ImmutableCFOptions& ioptions, const ImmutableCFOptions& ioptions,
const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>* int_tbl_prop_collector_factories, const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
const PlainTableOptions& table_options, int_tbl_prop_collector_factories,
WritableFile* file, uint32_t num_probes) WritableFile* file, uint32_t user_key_len, EncodingType encoding_type,
size_t index_sparseness, uint32_t bloom_bits_per_key, uint32_t num_probes,
size_t huge_page_tlb_size, double hash_table_ratio,
bool store_index_in_file)
: ioptions_(ioptions), : ioptions_(ioptions),
bloom_block_(num_probes), bloom_block_(num_probes),
file_(file), file_(file),
bloom_bits_per_key_(table_options.bloom_bits_per_key), bloom_bits_per_key_(bloom_bits_per_key),
huge_page_tlb_size_(table_options.huge_page_tlb_size), huge_page_tlb_size_(huge_page_tlb_size),
encoder_(table_options.encoding_type, table_options.user_key_len, encoder_(encoding_type, user_key_len, ioptions.prefix_extractor,
ioptions.prefix_extractor, table_options.index_sparseness), index_sparseness),
store_index_in_file_(table_options.store_index_in_file), store_index_in_file_(store_index_in_file),
prefix_extractor_(ioptions.prefix_extractor) { prefix_extractor_(ioptions.prefix_extractor) {
// Build index block and save it in the file if hash_table_ratio > 0 // Build index block and save it in the file if hash_table_ratio > 0
if (store_index_in_file_) { if (store_index_in_file_) {
assert(table_options.hash_table_ratio > 0 || IsTotalOrderMode()); assert(hash_table_ratio > 0 || IsTotalOrderMode());
index_builder_.reset( index_builder_.reset(
new PlainTableIndexBuilder(&arena_, ioptions, new PlainTableIndexBuilder(&arena_, ioptions, index_sparseness,
table_options.index_sparseness, hash_table_ratio, huge_page_tlb_size_));
table_options.hash_table_ratio,
huge_page_tlb_size_));
assert(bloom_bits_per_key_ > 0); assert(bloom_bits_per_key_ > 0);
properties_.user_collected_properties properties_.user_collected_properties
[PlainTablePropertyNames::kBloomVersion] = "1"; // For future use [PlainTablePropertyNames::kBloomVersion] = "1"; // For future use
} }
properties_.fixed_key_len = table_options.user_key_len; properties_.fixed_key_len = user_key_len;
// for plain table, we put all the data in a big chuck. // for plain table, we put all the data in a big chuck.
properties_.num_data_blocks = 1; properties_.num_data_blocks = 1;
@ -94,7 +95,7 @@ PlainTableBuilder::PlainTableBuilder(
properties_.filter_size = 0; properties_.filter_size = 0;
// To support roll-back to previous version, now still use version 0 for // To support roll-back to previous version, now still use version 0 for
// plain encoding. // plain encoding.
properties_.format_version = (table_options.encoding_type == kPlain) ? 0 : 1; properties_.format_version = (encoding_type == kPlain) ? 0 : 1;
if (ioptions_.prefix_extractor) { if (ioptions_.prefix_extractor) {
properties_.user_collected_properties properties_.user_collected_properties

@ -30,10 +30,14 @@ class PlainTableBuilder: public TableBuilder {
// caller to close the file after calling Finish(). The output file // caller to close the file after calling Finish(). The output file
// will be part of level specified by 'level'. A value of -1 means // will be part of level specified by 'level'. A value of -1 means
// that the caller does not know which level the output file will reside. // that the caller does not know which level the output file will reside.
PlainTableBuilder(const ImmutableCFOptions& ioptions, PlainTableBuilder(
const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>* int_tbl_prop_collector_factories, const ImmutableCFOptions& ioptions,
const PlainTableOptions& table_options, const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
WritableFile* file, uint32_t num_probes = 6); int_tbl_prop_collector_factories,
WritableFile* file, uint32_t user_key_size, EncodingType encoding_type,
size_t index_sparseness, uint32_t bloom_bits_per_key,
uint32_t num_probes = 6, size_t huge_page_tlb_size = 0,
double hash_table_ratio = 0, bool store_index_in_file = false);
// REQUIRES: Either Finish() or Abandon() has been called. // REQUIRES: Either Finish() or Abandon() has been called.
~PlainTableBuilder(); ~PlainTableBuilder();

@ -17,11 +17,13 @@ namespace rocksdb {
Status PlainTableFactory::NewTableReader(const ImmutableCFOptions& ioptions, Status PlainTableFactory::NewTableReader(const ImmutableCFOptions& ioptions,
const EnvOptions& env_options, const EnvOptions& env_options,
const InternalKeyComparator& icomp, const InternalKeyComparator& icomp,
std::unique_ptr<RandomAccessFile>&& file, unique_ptr<RandomAccessFile>&& file,
uint64_t file_size, uint64_t file_size,
std::unique_ptr<TableReader>* table) const { unique_ptr<TableReader>* table) const {
return PlainTableReader::Open(ioptions, env_options, table_options_, return PlainTableReader::Open(ioptions, env_options, icomp, std::move(file),
icomp, std::move(file), file_size, table); file_size, table, bloom_bits_per_key_,
hash_table_ratio_, index_sparseness_,
huge_page_tlb_size_, full_scan_mode_);
} }
TableBuilder* PlainTableFactory::NewTableBuilder( TableBuilder* PlainTableFactory::NewTableBuilder(
@ -31,9 +33,11 @@ TableBuilder* PlainTableFactory::NewTableBuilder(
// in-memory dbs. The skip_filters optimization is not useful for plain // in-memory dbs. The skip_filters optimization is not useful for plain
// tables // tables
// //
return new PlainTableBuilder(table_builder_options.ioptions, return new PlainTableBuilder(
table_builder_options.int_tbl_prop_collector_factories, table_builder_options.ioptions,
table_options_, file, 6); table_builder_options.int_tbl_prop_collector_factories, file,
user_key_len_, encoding_type_, index_sparseness_, bloom_bits_per_key_, 6,
huge_page_tlb_size_, hash_table_ratio_, store_index_in_file_);
} }
std::string PlainTableFactory::GetPrintableTableOptions() const { std::string PlainTableFactory::GetPrintableTableOptions() const {
@ -43,36 +47,32 @@ std::string PlainTableFactory::GetPrintableTableOptions() const {
char buffer[kBufferSize]; char buffer[kBufferSize];
snprintf(buffer, kBufferSize, " user_key_len: %u\n", snprintf(buffer, kBufferSize, " user_key_len: %u\n",
table_options_.user_key_len); user_key_len_);
ret.append(buffer); ret.append(buffer);
snprintf(buffer, kBufferSize, " bloom_bits_per_key: %d\n", snprintf(buffer, kBufferSize, " bloom_bits_per_key: %d\n",
table_options_.bloom_bits_per_key); bloom_bits_per_key_);
ret.append(buffer); ret.append(buffer);
snprintf(buffer, kBufferSize, " hash_table_ratio: %lf\n", snprintf(buffer, kBufferSize, " hash_table_ratio: %lf\n",
table_options_.hash_table_ratio); hash_table_ratio_);
ret.append(buffer); ret.append(buffer);
snprintf(buffer, kBufferSize, " index_sparseness: %" ROCKSDB_PRIszt "\n", snprintf(buffer, kBufferSize, " index_sparseness: %" ROCKSDB_PRIszt "\n",
table_options_.index_sparseness); index_sparseness_);
ret.append(buffer); ret.append(buffer);
snprintf(buffer, kBufferSize, " huge_page_tlb_size: %" ROCKSDB_PRIszt "\n", snprintf(buffer, kBufferSize, " huge_page_tlb_size: %" ROCKSDB_PRIszt "\n",
table_options_.huge_page_tlb_size); huge_page_tlb_size_);
ret.append(buffer); ret.append(buffer);
snprintf(buffer, kBufferSize, " encoding_type: %d\n", snprintf(buffer, kBufferSize, " encoding_type: %d\n",
table_options_.encoding_type); encoding_type_);
ret.append(buffer); ret.append(buffer);
snprintf(buffer, kBufferSize, " full_scan_mode: %d\n", snprintf(buffer, kBufferSize, " full_scan_mode: %d\n",
table_options_.full_scan_mode); full_scan_mode_);
ret.append(buffer); ret.append(buffer);
snprintf(buffer, kBufferSize, " store_index_in_file: %d\n", snprintf(buffer, kBufferSize, " store_index_in_file: %d\n",
table_options_.store_index_in_file); store_index_in_file_);
ret.append(buffer); ret.append(buffer);
return ret; return ret;
} }
const PlainTableOptions& PlainTableFactory::GetTableOptions() const {
return table_options_;
}
extern TableFactory* NewPlainTableFactory(const PlainTableOptions& options) { extern TableFactory* NewPlainTableFactory(const PlainTableOptions& options) {
return new PlainTableFactory(options); return new PlainTableFactory(options);
} }

@ -127,18 +127,37 @@ class TableBuilder;
class PlainTableFactory : public TableFactory { class PlainTableFactory : public TableFactory {
public: public:
~PlainTableFactory() {} ~PlainTableFactory() {}
// user_key_len is the length of the user key. If it is set to be
explicit PlainTableFactory( // kPlainTableVariableLength, then it means variable length. Otherwise, all
const PlainTableOptions& table_options = PlainTableOptions()) // the keys need to have the fix length of this value. bloom_bits_per_key is
: table_options_(table_options) {} // number of bits used for bloom filer per key. hash_table_ratio is
// the desired utilization of the hash table used for prefix hashing.
// hash_table_ratio = number of prefixes / #buckets in the hash table
// hash_table_ratio = 0 means skip hash table but only replying on binary
// search.
// index_sparseness determines index interval for keys
// inside the same prefix. It will be the maximum number of linear search
// required after hash and binary search.
// index_sparseness = 0 means index for every key.
// 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& options =
PlainTableOptions())
: user_key_len_(options.user_key_len),
bloom_bits_per_key_(options.bloom_bits_per_key),
hash_table_ratio_(options.hash_table_ratio),
index_sparseness_(options.index_sparseness),
huge_page_tlb_size_(options.huge_page_tlb_size),
encoding_type_(options.encoding_type),
full_scan_mode_(options.full_scan_mode),
store_index_in_file_(options.store_index_in_file) {}
const char* Name() const override { return "PlainTable"; } const char* Name() const override { return "PlainTable"; }
Status NewTableReader( Status NewTableReader(
const ImmutableCFOptions& options, const EnvOptions& soptions, const ImmutableCFOptions& options, const EnvOptions& soptions,
const InternalKeyComparator& internal_comparator, const InternalKeyComparator& internal_comparator,
std::unique_ptr<RandomAccessFile>&& file, uint64_t file_size, unique_ptr<RandomAccessFile>&& file, uint64_t file_size,
std::unique_ptr<TableReader>* table) const override; unique_ptr<TableReader>* table) const override;
TableBuilder* NewTableBuilder( TableBuilder* NewTableBuilder(
const TableBuilderOptions& table_builder_options, const TableBuilderOptions& table_builder_options,
WritableFile* file) const override; WritableFile* file) const override;
@ -157,10 +176,15 @@ class PlainTableFactory : public TableFactory {
return Status::OK(); return Status::OK();
} }
const PlainTableOptions& GetTableOptions() const;
private: private:
PlainTableOptions table_options_; uint32_t user_key_len_;
int bloom_bits_per_key_;
double hash_table_ratio_;
size_t index_sparseness_;
size_t huge_page_tlb_size_;
EncodingType encoding_type_;
bool full_scan_mode_;
bool store_index_in_file_;
}; };
} // namespace rocksdb } // namespace rocksdb

@ -90,7 +90,7 @@ class PlainTableIterator : public Iterator {
extern const uint64_t kPlainTableMagicNumber; extern const uint64_t kPlainTableMagicNumber;
PlainTableReader::PlainTableReader(const ImmutableCFOptions& ioptions, PlainTableReader::PlainTableReader(const ImmutableCFOptions& ioptions,
std::unique_ptr<RandomAccessFile>&& file, unique_ptr<RandomAccessFile>&& file,
const EnvOptions& storage_options, const EnvOptions& storage_options,
const InternalKeyComparator& icomparator, const InternalKeyComparator& icomparator,
EncodingType encoding_type, EncodingType encoding_type,
@ -114,11 +114,13 @@ PlainTableReader::~PlainTableReader() {
Status PlainTableReader::Open(const ImmutableCFOptions& ioptions, Status PlainTableReader::Open(const ImmutableCFOptions& ioptions,
const EnvOptions& env_options, const EnvOptions& env_options,
const PlainTableOptions& table_options,
const InternalKeyComparator& internal_comparator, const InternalKeyComparator& internal_comparator,
std::unique_ptr<RandomAccessFile>&& file, unique_ptr<RandomAccessFile>&& file,
uint64_t file_size, uint64_t file_size,
std::unique_ptr<TableReader>* table_reader) { unique_ptr<TableReader>* table_reader,
const int bloom_bits_per_key,
double hash_table_ratio, size_t index_sparseness,
size_t huge_page_tlb_size, bool full_scan_mode) {
assert(ioptions.allow_mmap_reads); assert(ioptions.allow_mmap_reads);
if (file_size > PlainTableIndex::kMaxFileSize) { if (file_size > PlainTableIndex::kMaxFileSize) {
return Status::NotSupported("File is too large for PlainTableReader!"); return Status::NotSupported("File is too large for PlainTableReader!");
@ -131,12 +133,12 @@ Status PlainTableReader::Open(const ImmutableCFOptions& ioptions,
return s; return s;
} }
assert(table_options.hash_table_ratio >= 0.0); assert(hash_table_ratio >= 0.0);
auto& user_props = props->user_collected_properties; auto& user_props = props->user_collected_properties;
auto prefix_extractor_in_file = auto prefix_extractor_in_file =
user_props.find(PlainTablePropertyNames::kPrefixExtractorName); user_props.find(PlainTablePropertyNames::kPrefixExtractorName);
if (!table_options.full_scan_mode && prefix_extractor_in_file != user_props.end()) { if (!full_scan_mode && prefix_extractor_in_file != user_props.end()) {
if (!ioptions.prefix_extractor) { if (!ioptions.prefix_extractor) {
return Status::InvalidArgument( return Status::InvalidArgument(
"Prefix extractor is missing when opening a PlainTable built " "Prefix extractor is missing when opening a PlainTable built "
@ -166,11 +168,9 @@ Status PlainTableReader::Open(const ImmutableCFOptions& ioptions,
return s; return s;
} }
if (!table_options.full_scan_mode) { if (!full_scan_mode) {
s = new_reader->PopulateIndex(props, table_options.bloom_bits_per_key, s = new_reader->PopulateIndex(props, bloom_bits_per_key, hash_table_ratio,
table_options.hash_table_ratio, index_sparseness, huge_page_tlb_size);
table_options.index_sparseness,
table_options.huge_page_tlb_size);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }

@ -55,10 +55,12 @@ class PlainTableReader: public TableReader {
public: public:
static Status Open(const ImmutableCFOptions& ioptions, static Status Open(const ImmutableCFOptions& ioptions,
const EnvOptions& env_options, const EnvOptions& env_options,
const PlainTableOptions& table_options,
const InternalKeyComparator& internal_comparator, const InternalKeyComparator& internal_comparator,
std::unique_ptr<RandomAccessFile>&& file, uint64_t file_size, unique_ptr<RandomAccessFile>&& file, uint64_t file_size,
std::unique_ptr<TableReader>* table); unique_ptr<TableReader>* table,
const int bloom_bits_per_key, double hash_table_ratio,
size_t index_sparseness, size_t huge_page_tlb_size,
bool full_scan_mode);
Iterator* NewIterator(const ReadOptions&, Arena* arena = nullptr) override; Iterator* NewIterator(const ReadOptions&, Arena* arena = nullptr) override;
@ -81,7 +83,7 @@ class PlainTableReader: public TableReader {
} }
PlainTableReader(const ImmutableCFOptions& ioptions, PlainTableReader(const ImmutableCFOptions& ioptions,
std::unique_ptr<RandomAccessFile>&& file, unique_ptr<RandomAccessFile>&& file,
const EnvOptions& env_options, const EnvOptions& env_options,
const InternalKeyComparator& internal_comparator, const InternalKeyComparator& internal_comparator,
EncodingType encoding_type, uint64_t file_size, EncodingType encoding_type, uint64_t file_size,
@ -132,7 +134,7 @@ class PlainTableReader: public TableReader {
Arena arena_; Arena arena_;
const ImmutableCFOptions& ioptions_; const ImmutableCFOptions& ioptions_;
std::unique_ptr<RandomAccessFile> file_; unique_ptr<RandomAccessFile> file_;
uint64_t file_size_; uint64_t file_size_;
std::shared_ptr<const TableProperties> table_properties_; std::shared_ptr<const TableProperties> table_properties_;

@ -10,16 +10,13 @@
#include "rocksdb/cache.h" #include "rocksdb/cache.h"
#include "rocksdb/filter_policy.h" #include "rocksdb/filter_policy.h"
#include "rocksdb/options.h" #include "rocksdb/options.h"
#include "rocksdb/memtablerep.h"
#include "rocksdb/rate_limiter.h" #include "rocksdb/rate_limiter.h"
#include "rocksdb/slice_transform.h" #include "rocksdb/slice_transform.h"
#include "rocksdb/table.h" #include "rocksdb/table.h"
#include "rocksdb/utilities/convenience.h" #include "rocksdb/utilities/convenience.h"
#include "table/block_based_table_factory.h" #include "table/block_based_table_factory.h"
#include "table/plain_table_factory.h"
#include "util/logging.h" #include "util/logging.h"
#include "util/options_helper.h" #include "util/options_helper.h"
#include "util/string_util.h"
namespace rocksdb { namespace rocksdb {
@ -269,7 +266,7 @@ Status GetMutableOptionsFromStrings(
return Status::InvalidArgument( return Status::InvalidArgument(
"unsupported dynamic option: " + o.first); "unsupported dynamic option: " + o.first);
} }
} catch (const std::exception& e) { } catch (std::exception& e) {
return Status::InvalidArgument("error parsing " + o.first + ":" + return Status::InvalidArgument("error parsing " + o.first + ":" +
std::string(e.what())); std::string(e.what()));
} }
@ -394,27 +391,6 @@ bool ParseColumnFamilyOption(const std::string& name, const std::string& value,
return false; return false;
} }
new_options->table_factory.reset(NewBlockBasedTableFactory(table_opt)); new_options->table_factory.reset(NewBlockBasedTableFactory(table_opt));
} else if (name == "plain_table_factory") {
PlainTableOptions table_opt, base_table_options;
auto plain_table_factory = dynamic_cast<PlainTableFactory*>(
new_options->table_factory.get());
if (plain_table_factory != nullptr) {
base_table_options = plain_table_factory->GetTableOptions();
}
Status table_opt_s = GetPlainTableOptionsFromString(
base_table_options, value, &table_opt);
if (!table_opt_s.ok()) {
return false;
}
new_options->table_factory.reset(NewPlainTableFactory(table_opt));
} else if (name == "memtablerep") {
MemTableRepFactory* new_mem_factory;
Status mem_factory_s =
GetMemTableRepFactoryFromString(value, &new_mem_factory);
if (!mem_factory_s.ok()) {
return false;
}
new_options->memtable_factory.reset(new_mem_factory);
} else if (name == "min_write_buffer_number_to_merge") { } else if (name == "min_write_buffer_number_to_merge") {
new_options->min_write_buffer_number_to_merge = ParseInt(value); new_options->min_write_buffer_number_to_merge = ParseInt(value);
} else if (name == "max_write_buffer_number_to_maintain") { } else if (name == "max_write_buffer_number_to_maintain") {
@ -505,7 +481,7 @@ bool ParseColumnFamilyOption(const std::string& name, const std::string& value,
return false; return false;
} }
} }
catch (const std::exception& e) { catch (std::exception& e) {
return false; return false;
} }
return true; return true;
@ -653,7 +629,7 @@ Status GetBlockBasedTableOptionsFromMap(
} else { } else {
return Status::InvalidArgument("Unrecognized option: " + o.first); return Status::InvalidArgument("Unrecognized option: " + o.first);
} }
} catch (const std::exception& e) { } catch (std::exception& e) {
return Status::InvalidArgument("error parsing " + o.first + ":" + return Status::InvalidArgument("error parsing " + o.first + ":" +
std::string(e.what())); std::string(e.what()));
} }
@ -708,7 +684,7 @@ Status GetPlainTableOptionsFromMap(
} else { } else {
return Status::InvalidArgument("Unrecognized option: " + o.first); return Status::InvalidArgument("Unrecognized option: " + o.first);
} }
} catch (const std::exception& e) { } catch (std::exception& e) {
return Status::InvalidArgument("error parsing " + o.first + ":" + return Status::InvalidArgument("error parsing " + o.first + ":" +
std::string(e.what())); std::string(e.what()));
} }
@ -716,75 +692,6 @@ Status GetPlainTableOptionsFromMap(
return Status::OK(); return Status::OK();
} }
Status GetPlainTableOptionsFromString(
const PlainTableOptions& table_options,
const std::string& opts_str,
PlainTableOptions* new_table_options) {
std::unordered_map<std::string, std::string> opts_map;
Status s = StringToMap(opts_str, &opts_map);
if (!s.ok()) {
return s;
}
return GetPlainTableOptionsFromMap(table_options, opts_map,
new_table_options);
}
Status GetMemTableRepFactoryFromString(
const std::string& opts_str,
MemTableRepFactory** new_mem_factory) {
std::vector<std::string> opts_list = StringSplit(opts_str, ':');
size_t len = opts_list.size();
if (opts_list[0] == "skip_list") {
// Expecting format
// skip_list:lookahead
if (2 == len) {
size_t lookahead = ParseSizeT(opts_list[1]);
*new_mem_factory = new SkipListFactory(lookahead);
} else if (1 == len) {
*new_mem_factory = new SkipListFactory();
} else {
return Status::InvalidArgument("Can't parse option ", opts_str);
}
} else if (opts_list[0] == "prefix_hash") {
// Expecting format
// prfix_hash:hash_bucket_count
if (2 == len) {
size_t hash_bucket_count = ParseSizeT(opts_list[1]);
*new_mem_factory = NewHashSkipListRepFactory(hash_bucket_count);
} else if (1 == len) {
*new_mem_factory = NewHashSkipListRepFactory();
} else {
return Status::InvalidArgument("Can't parse option ", opts_str);
}
} else if (opts_list[0] == "hash_linkedlist") {
// Expecting format
// hash_linkedlist:hash_bucket_count
if (2 == len) {
size_t hash_bucket_count = ParseSizeT(opts_list[1]);
*new_mem_factory = NewHashLinkListRepFactory(hash_bucket_count);
} else if (1 == len) {
*new_mem_factory = NewHashLinkListRepFactory();
} else {
return Status::InvalidArgument("Can't parse option ", opts_str);
}
} else if (opts_list[0] == "vector") {
if (1 == len) {
*new_mem_factory = new VectorRepFactory;
} else {
return Status::InvalidArgument("Can't parse option ", opts_str);
}
} else if (opts_list[0] == "cuckoo") {
return Status::InvalidArgument("cuckoo is not supported for now");
// TODO(bahuang): cuckoo is not supported for now
// *new_mem_factory = NewHashCuckooRepFactory(
// options.write_buffer_size, FLAGS_key_size + FLAGS_value_size));
} else {
return Status::InvalidArgument("Can't parse option " + opts_str);
}
return Status::OK();
}
Status GetColumnFamilyOptionsFromMap( Status GetColumnFamilyOptionsFromMap(
const ColumnFamilyOptions& base_options, const ColumnFamilyOptions& base_options,
const std::unordered_map<std::string, std::string>& opts_map, const std::unordered_map<std::string, std::string>& opts_map,

@ -16,12 +16,10 @@
#include "rocksdb/cache.h" #include "rocksdb/cache.h"
#include "rocksdb/options.h" #include "rocksdb/options.h"
#include "rocksdb/memtablerep.h"
#include "rocksdb/table.h" #include "rocksdb/table.h"
#include "rocksdb/utilities/convenience.h" #include "rocksdb/utilities/convenience.h"
#include "rocksdb/utilities/leveldb_options.h" #include "rocksdb/utilities/leveldb_options.h"
#include "table/block_based_table_factory.h" #include "table/block_based_table_factory.h"
#include "table/plain_table_factory.h"
#include "util/random.h" #include "util/random.h"
#include "util/testharness.h" #include "util/testharness.h"
@ -421,18 +419,6 @@ TEST_F(OptionsTest, GetColumnFamilyOptionsFromStringTest) {
ASSERT_NOK(GetColumnFamilyOptionsFromString(base_cf_opt, ASSERT_NOK(GetColumnFamilyOptionsFromString(base_cf_opt,
"optimize_filters_for_hits=junk", "optimize_filters_for_hits=junk",
&new_cf_opt)); &new_cf_opt));
// Parsing PlainTableOption
ASSERT_OK(GetColumnFamilyOptionsFromString(
base_cf_opt,
"plain_table_factory={user_key_len=16;bloom_bits_per_key=10;};",
&new_cf_opt));
// Paring Memtable Factory Options
ASSERT_OK(GetColumnFamilyOptionsFromString(
base_cf_opt,
"memtablerep=prefix_hash;",
&new_cf_opt));
} }
#endif // !ROCKSDB_LITE #endif // !ROCKSDB_LITE
@ -491,71 +477,6 @@ TEST_F(OptionsTest, GetBlockBasedTableOptionsFromString) {
} }
#endif // !ROCKSDB_LITE #endif // !ROCKSDB_LITE
#ifndef ROCKSDB_LITE // GetPlainTableOptionsFromString is not supported
TEST_F(OptionsTest, GetPlainTableOptionsFromString){
PlainTableOptions table_opt;
PlainTableOptions new_opt;
// make sure default values are overwritten by something else
ASSERT_OK(GetPlainTableOptionsFromString(table_opt,
"user_key_len=16;bloom_bits_per_key=8;hash_table_ratio=0.5;"
"index_sparseness=8;huge_page_tlb_size=20;encoding_type=kPrefix;"
"full_scan_mode=1;store_index_in_file=1",
&new_opt));
ASSERT_EQ(new_opt.user_key_len, 16);
ASSERT_EQ(new_opt.bloom_bits_per_key, 8);
ASSERT_EQ(new_opt.hash_table_ratio, 0.5);
ASSERT_EQ(new_opt.index_sparseness, 8);
ASSERT_EQ(new_opt.huge_page_tlb_size, 20);
ASSERT_EQ(new_opt.encoding_type, kPrefix);
ASSERT_TRUE(new_opt.full_scan_mode);
ASSERT_TRUE(new_opt.store_index_in_file);
// unknown options
ASSERT_NOK(GetPlainTableOptionsFromString(table_opt,
"user_key_len=16;bloom_bits_per_key=8;bad_option=1",
&new_opt));
// unknown encoding type
ASSERT_NOK(GetPlainTableOptionsFromString(table_opt,
"user_key_len=16;bloom_bits_per_key=8;encoding_type=kPrefixXX",
&new_opt));
}
#endif // !ROCKSDB_LITE
#ifndef ROCKSDB_LITE // GetMemTableRepFactoryFromString is not supported
TEST_F(OptionsTest, GetMemTableRepFactoryFromString) {
MemTableRepFactory* new_mem_factory = nullptr;
ASSERT_OK(GetMemTableRepFactoryFromString(
"skip_list", &new_mem_factory));
ASSERT_OK(GetMemTableRepFactoryFromString(
"skip_list:16", &new_mem_factory));
ASSERT_EQ(std::string(new_mem_factory->Name()), "SkipListFactory");
ASSERT_OK(GetMemTableRepFactoryFromString(
"prefix_hash", &new_mem_factory));
ASSERT_OK(GetMemTableRepFactoryFromString(
"prefix_hash:1000", &new_mem_factory));
ASSERT_EQ(std::string(new_mem_factory->Name()), "HashSkipListRepFactory");
ASSERT_OK(GetMemTableRepFactoryFromString(
"hash_linkedlist", &new_mem_factory));
ASSERT_OK(GetMemTableRepFactoryFromString(
"hash_linkedlist:1000", &new_mem_factory));
ASSERT_EQ(std::string(new_mem_factory->Name()), "HashLinkListRepFactory");
ASSERT_OK(GetMemTableRepFactoryFromString(
"vector", &new_mem_factory));
ASSERT_EQ(std::string(new_mem_factory->Name()), "VectorRepFactory");
ASSERT_NOK(GetMemTableRepFactoryFromString(
"invalid_factory", &new_mem_factory));
ASSERT_NOK(GetMemTableRepFactoryFromString(
"skip_list:16:invalid_opt", &new_mem_factory));
}
#endif // !ROCKSDB_LITE
#ifndef ROCKSDB_LITE // GetOptionsFromString is not supported in RocksDB Lite #ifndef ROCKSDB_LITE // GetOptionsFromString is not supported in RocksDB Lite
TEST_F(OptionsTest, GetOptionsFromStringTest) { TEST_F(OptionsTest, GetOptionsFromStringTest) {
Options base_options, new_options; Options base_options, new_options;

Loading…
Cancel
Save