Skip to content

Commit

Permalink
Revert the changes related to Options, as requested to seperate them …
Browse files Browse the repository at this point in the history
…into

a different patch.
  • Loading branch information
unknown authored and yuslepukhin committed Jul 9, 2015
1 parent d8586ab commit 5c79132
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 255 deletions.
14 changes: 0 additions & 14 deletions include/rocksdb/utilities/convenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ Status GetBlockBasedTableOptionsFromMap(
const std::unordered_map<std::string, std::string>& opts_map,
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
// base_options, and return the new options as a result. The string has the
// following format:
Expand All @@ -53,20 +48,11 @@ Status GetDBOptionsFromString(
const std::string& opts_str,
DBOptions* new_options);

Status GetPlainTableOptionsFromString(
const PlainTableOptions& table_options,
const std::string& opts_str,
PlainTableOptions* new_table_options);

Status GetBlockBasedTableOptionsFromString(
const BlockBasedTableOptions& table_options,
const std::string& opts_str,
BlockBasedTableOptions* new_table_options);

Status GetMemTableRepFactoryFromString(
const std::string& opts_str,
MemTableRepFactory** new_mem_factory);

Status GetOptionsFromString(const Options& base_options,
const std::string& opts_str, Options* new_options);

Expand Down
31 changes: 16 additions & 15 deletions table/plain_table_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,33 @@ extern const uint64_t kLegacyPlainTableMagicNumber = 0x4f3418eb7a8f13b8ull;

PlainTableBuilder::PlainTableBuilder(
const ImmutableCFOptions& ioptions,
const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>* int_tbl_prop_collector_factories,
const PlainTableOptions& table_options,
WritableFile* file, uint32_t num_probes)
const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
int_tbl_prop_collector_factories,
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),
bloom_block_(num_probes),
file_(file),
bloom_bits_per_key_(table_options.bloom_bits_per_key),
huge_page_tlb_size_(table_options.huge_page_tlb_size),
encoder_(table_options.encoding_type, table_options.user_key_len,
ioptions.prefix_extractor, table_options.index_sparseness),
store_index_in_file_(table_options.store_index_in_file),
bloom_bits_per_key_(bloom_bits_per_key),
huge_page_tlb_size_(huge_page_tlb_size),
encoder_(encoding_type, user_key_len, ioptions.prefix_extractor,
index_sparseness),
store_index_in_file_(store_index_in_file),
prefix_extractor_(ioptions.prefix_extractor) {
// Build index block and save it in the file if hash_table_ratio > 0
if (store_index_in_file_) {
assert(table_options.hash_table_ratio > 0 || IsTotalOrderMode());
assert(hash_table_ratio > 0 || IsTotalOrderMode());
index_builder_.reset(
new PlainTableIndexBuilder(&arena_, ioptions,
table_options.index_sparseness,
table_options.hash_table_ratio,
huge_page_tlb_size_));
new PlainTableIndexBuilder(&arena_, ioptions, index_sparseness,
hash_table_ratio, huge_page_tlb_size_));
assert(bloom_bits_per_key_ > 0);
properties_.user_collected_properties
[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.
properties_.num_data_blocks = 1;
Expand All @@ -94,7 +95,7 @@ PlainTableBuilder::PlainTableBuilder(
properties_.filter_size = 0;
// To support roll-back to previous version, now still use version 0 for
// plain encoding.
properties_.format_version = (table_options.encoding_type == kPlain) ? 0 : 1;
properties_.format_version = (encoding_type == kPlain) ? 0 : 1;

if (ioptions_.prefix_extractor) {
properties_.user_collected_properties
Expand Down
12 changes: 8 additions & 4 deletions table/plain_table_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ class PlainTableBuilder: public TableBuilder {
// caller to close the file after calling Finish(). The output file
// 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.
PlainTableBuilder(const ImmutableCFOptions& ioptions,
const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>* int_tbl_prop_collector_factories,
const PlainTableOptions& table_options,
WritableFile* file, uint32_t num_probes = 6);
PlainTableBuilder(
const ImmutableCFOptions& ioptions,
const std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
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.
~PlainTableBuilder();
Expand Down
38 changes: 19 additions & 19 deletions table/plain_table_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ namespace rocksdb {
Status PlainTableFactory::NewTableReader(const ImmutableCFOptions& ioptions,
const EnvOptions& env_options,
const InternalKeyComparator& icomp,
std::unique_ptr<RandomAccessFile>&& file,
unique_ptr<RandomAccessFile>&& file,
uint64_t file_size,
std::unique_ptr<TableReader>* table) const {
return PlainTableReader::Open(ioptions, env_options, table_options_,
icomp, std::move(file), file_size, table);
unique_ptr<TableReader>* table) const {
return PlainTableReader::Open(ioptions, env_options, icomp, std::move(file),
file_size, table, bloom_bits_per_key_,
hash_table_ratio_, index_sparseness_,
huge_page_tlb_size_, full_scan_mode_);
}

TableBuilder* PlainTableFactory::NewTableBuilder(
Expand All @@ -31,9 +33,11 @@ TableBuilder* PlainTableFactory::NewTableBuilder(
// in-memory dbs. The skip_filters optimization is not useful for plain
// tables
//
return new PlainTableBuilder(table_builder_options.ioptions,
table_builder_options.int_tbl_prop_collector_factories,
table_options_, file, 6);
return new PlainTableBuilder(
table_builder_options.ioptions,
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 {
Expand All @@ -43,36 +47,32 @@ std::string PlainTableFactory::GetPrintableTableOptions() const {
char buffer[kBufferSize];

snprintf(buffer, kBufferSize, " user_key_len: %u\n",
table_options_.user_key_len);
user_key_len_);
ret.append(buffer);
snprintf(buffer, kBufferSize, " bloom_bits_per_key: %d\n",
table_options_.bloom_bits_per_key);
bloom_bits_per_key_);
ret.append(buffer);
snprintf(buffer, kBufferSize, " hash_table_ratio: %lf\n",
table_options_.hash_table_ratio);
hash_table_ratio_);
ret.append(buffer);
snprintf(buffer, kBufferSize, " index_sparseness: %" ROCKSDB_PRIszt "\n",
table_options_.index_sparseness);
index_sparseness_);
ret.append(buffer);
snprintf(buffer, kBufferSize, " huge_page_tlb_size: %" ROCKSDB_PRIszt "\n",
table_options_.huge_page_tlb_size);
huge_page_tlb_size_);
ret.append(buffer);
snprintf(buffer, kBufferSize, " encoding_type: %d\n",
table_options_.encoding_type);
encoding_type_);
ret.append(buffer);
snprintf(buffer, kBufferSize, " full_scan_mode: %d\n",
table_options_.full_scan_mode);
full_scan_mode_);
ret.append(buffer);
snprintf(buffer, kBufferSize, " store_index_in_file: %d\n",
table_options_.store_index_in_file);
store_index_in_file_);
ret.append(buffer);
return ret;
}

const PlainTableOptions& PlainTableFactory::GetTableOptions() const {
return table_options_;
}

extern TableFactory* NewPlainTableFactory(const PlainTableOptions& options) {
return new PlainTableFactory(options);
}
Expand Down
46 changes: 35 additions & 11 deletions table/plain_table_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,37 @@ class TableBuilder;
class PlainTableFactory : public TableFactory {
public:
~PlainTableFactory() {}

explicit PlainTableFactory(
const PlainTableOptions& table_options = PlainTableOptions())
: table_options_(table_options) {}

// user_key_len is the length of the user key. If it is set to be
// kPlainTableVariableLength, then it means variable length. Otherwise, all
// the keys need to have the fix length of this value. bloom_bits_per_key is
// 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"; }
Status NewTableReader(
const ImmutableCFOptions& options, const EnvOptions& soptions,
const InternalKeyComparator& internal_comparator,
std::unique_ptr<RandomAccessFile>&& file, uint64_t file_size,
std::unique_ptr<TableReader>* table) const override;

unique_ptr<RandomAccessFile>&& file, uint64_t file_size,
unique_ptr<TableReader>* table) const override;
TableBuilder* NewTableBuilder(
const TableBuilderOptions& table_builder_options,
WritableFile* file) const override;
Expand All @@ -157,10 +176,15 @@ class PlainTableFactory : public TableFactory {
return Status::OK();
}

const PlainTableOptions& GetTableOptions() const;

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
Expand Down
22 changes: 11 additions & 11 deletions table/plain_table_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class PlainTableIterator : public Iterator {

extern const uint64_t kPlainTableMagicNumber;
PlainTableReader::PlainTableReader(const ImmutableCFOptions& ioptions,
std::unique_ptr<RandomAccessFile>&& file,
unique_ptr<RandomAccessFile>&& file,
const EnvOptions& storage_options,
const InternalKeyComparator& icomparator,
EncodingType encoding_type,
Expand All @@ -114,11 +114,13 @@ PlainTableReader::~PlainTableReader() {

Status PlainTableReader::Open(const ImmutableCFOptions& ioptions,
const EnvOptions& env_options,
const PlainTableOptions& table_options,
const InternalKeyComparator& internal_comparator,
std::unique_ptr<RandomAccessFile>&& file,
unique_ptr<RandomAccessFile>&& file,
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);
if (file_size > PlainTableIndex::kMaxFileSize) {
return Status::NotSupported("File is too large for PlainTableReader!");
Expand All @@ -131,12 +133,12 @@ Status PlainTableReader::Open(const ImmutableCFOptions& ioptions,
return s;
}

assert(table_options.hash_table_ratio >= 0.0);
assert(hash_table_ratio >= 0.0);
auto& user_props = props->user_collected_properties;
auto prefix_extractor_in_file =
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) {
return Status::InvalidArgument(
"Prefix extractor is missing when opening a PlainTable built "
Expand Down Expand Up @@ -166,11 +168,9 @@ Status PlainTableReader::Open(const ImmutableCFOptions& ioptions,
return s;
}

if (!table_options.full_scan_mode) {
s = new_reader->PopulateIndex(props, table_options.bloom_bits_per_key,
table_options.hash_table_ratio,
table_options.index_sparseness,
table_options.huge_page_tlb_size);
if (!full_scan_mode) {
s = new_reader->PopulateIndex(props, bloom_bits_per_key, hash_table_ratio,
index_sparseness, huge_page_tlb_size);
if (!s.ok()) {
return s;
}
Expand Down
12 changes: 7 additions & 5 deletions table/plain_table_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ class PlainTableReader: public TableReader {
public:
static Status Open(const ImmutableCFOptions& ioptions,
const EnvOptions& env_options,
const PlainTableOptions& table_options,
const InternalKeyComparator& internal_comparator,
std::unique_ptr<RandomAccessFile>&& file, uint64_t file_size,
std::unique_ptr<TableReader>* table);
unique_ptr<RandomAccessFile>&& file, uint64_t file_size,
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;

Expand All @@ -81,7 +83,7 @@ class PlainTableReader: public TableReader {
}

PlainTableReader(const ImmutableCFOptions& ioptions,
std::unique_ptr<RandomAccessFile>&& file,
unique_ptr<RandomAccessFile>&& file,
const EnvOptions& env_options,
const InternalKeyComparator& internal_comparator,
EncodingType encoding_type, uint64_t file_size,
Expand Down Expand Up @@ -132,7 +134,7 @@ class PlainTableReader: public TableReader {
Arena arena_;

const ImmutableCFOptions& ioptions_;
std::unique_ptr<RandomAccessFile> file_;
unique_ptr<RandomAccessFile> file_;
uint64_t file_size_;
std::shared_ptr<const TableProperties> table_properties_;

Expand Down
Loading

0 comments on commit 5c79132

Please sign in to comment.