2019-04-18 19:51:19 +02:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
2013-10-29 04:34:02 +01:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
2014-04-15 22:39:26 +02:00
|
|
|
#ifndef ROCKSDB_LITE
|
2019-05-30 23:47:29 +02:00
|
|
|
#include "table/plain/plain_table_factory.h"
|
2013-10-29 04:34:02 +01:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2020-04-22 02:35:28 +02:00
|
|
|
|
2017-07-29 01:23:50 +02:00
|
|
|
#include <memory>
|
2020-04-22 02:35:28 +02:00
|
|
|
|
2014-01-27 22:53:22 +01:00
|
|
|
#include "db/dbformat.h"
|
2017-07-29 01:23:50 +02:00
|
|
|
#include "options/options_helper.h"
|
|
|
|
#include "port/port.h"
|
|
|
|
#include "rocksdb/convenience.h"
|
2019-05-30 23:47:29 +02:00
|
|
|
#include "table/plain/plain_table_builder.h"
|
|
|
|
#include "table/plain/plain_table_reader.h"
|
2017-07-29 01:23:50 +02:00
|
|
|
#include "util/string_util.h"
|
2013-10-29 04:34:02 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2020-04-03 19:48:46 +02:00
|
|
|
static std::unordered_map<std::string, OptionTypeInfo> plain_table_type_info = {
|
|
|
|
{"user_key_len",
|
|
|
|
{offsetof(struct PlainTableOptions, user_key_len), OptionType::kUInt32T,
|
|
|
|
OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
|
|
|
|
{"bloom_bits_per_key",
|
|
|
|
{offsetof(struct PlainTableOptions, bloom_bits_per_key), OptionType::kInt,
|
|
|
|
OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
|
|
|
|
{"hash_table_ratio",
|
|
|
|
{offsetof(struct PlainTableOptions, hash_table_ratio), OptionType::kDouble,
|
|
|
|
OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
|
|
|
|
{"index_sparseness",
|
|
|
|
{offsetof(struct PlainTableOptions, index_sparseness), OptionType::kSizeT,
|
|
|
|
OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
|
|
|
|
{"huge_page_tlb_size",
|
|
|
|
{offsetof(struct PlainTableOptions, huge_page_tlb_size),
|
|
|
|
OptionType::kSizeT, OptionVerificationType::kNormal,
|
|
|
|
OptionTypeFlags::kNone, 0}},
|
|
|
|
{"encoding_type",
|
|
|
|
{offsetof(struct PlainTableOptions, encoding_type),
|
|
|
|
OptionType::kEncodingType, OptionVerificationType::kByName,
|
|
|
|
OptionTypeFlags::kNone, 0}},
|
|
|
|
{"full_scan_mode",
|
|
|
|
{offsetof(struct PlainTableOptions, full_scan_mode), OptionType::kBoolean,
|
|
|
|
OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}},
|
|
|
|
{"store_index_in_file",
|
|
|
|
{offsetof(struct PlainTableOptions, store_index_in_file),
|
|
|
|
OptionType::kBoolean, OptionVerificationType::kNormal,
|
|
|
|
OptionTypeFlags::kNone, 0}}};
|
2013-10-29 04:34:02 +01:00
|
|
|
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-18 01:16:11 +02:00
|
|
|
Status PlainTableFactory::NewTableReader(
|
2015-09-11 20:36:33 +02:00
|
|
|
const TableReaderOptions& table_reader_options,
|
2018-11-09 20:17:34 +01:00
|
|
|
std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
|
|
|
|
std::unique_ptr<TableReader>* table,
|
2018-03-05 22:08:17 +01:00
|
|
|
bool /*prefetch_index_and_filter_in_cache*/) const {
|
2015-09-11 20:36:33 +02:00
|
|
|
return PlainTableReader::Open(
|
|
|
|
table_reader_options.ioptions, table_reader_options.env_options,
|
|
|
|
table_reader_options.internal_comparator, std::move(file), file_size,
|
2015-11-16 21:56:21 +01:00
|
|
|
table, table_options_.bloom_bits_per_key, table_options_.hash_table_ratio,
|
|
|
|
table_options_.index_sparseness, table_options_.huge_page_tlb_size,
|
2019-01-26 02:07:00 +01:00
|
|
|
table_options_.full_scan_mode, table_reader_options.immortal,
|
|
|
|
table_reader_options.prefix_extractor);
|
2013-10-29 04:34:02 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 06:58:46 +01:00
|
|
|
TableBuilder* PlainTableFactory::NewTableBuilder(
|
2015-10-09 01:57:35 +02:00
|
|
|
const TableBuilderOptions& table_builder_options, uint32_t column_family_id,
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-18 01:16:11 +02:00
|
|
|
WritableFileWriter* file) const {
|
2015-02-17 17:03:45 +01:00
|
|
|
// Ignore the skip_filters flag. PlainTable format is optimized for small
|
|
|
|
// in-memory dbs. The skip_filters optimization is not useful for plain
|
|
|
|
// tables
|
|
|
|
//
|
2015-07-08 16:35:56 +02:00
|
|
|
return new PlainTableBuilder(
|
2018-05-21 23:33:55 +02:00
|
|
|
table_builder_options.ioptions, table_builder_options.moptions,
|
2015-10-09 01:57:35 +02:00
|
|
|
table_builder_options.int_tbl_prop_collector_factories, column_family_id,
|
2015-11-16 21:56:21 +01:00
|
|
|
file, table_options_.user_key_len, table_options_.encoding_type,
|
2019-03-02 00:41:55 +01:00
|
|
|
table_options_.index_sparseness, table_options_.bloom_bits_per_key,
|
|
|
|
table_builder_options.column_family_name, 6,
|
|
|
|
table_options_.huge_page_tlb_size, table_options_.hash_table_ratio,
|
|
|
|
table_options_.store_index_in_file);
|
2013-10-29 04:34:02 +01:00
|
|
|
}
|
2014-01-28 06:58:46 +01:00
|
|
|
|
2014-08-25 23:24:09 +02:00
|
|
|
std::string PlainTableFactory::GetPrintableTableOptions() const {
|
|
|
|
std::string ret;
|
|
|
|
ret.reserve(20000);
|
|
|
|
const int kBufferSize = 200;
|
|
|
|
char buffer[kBufferSize];
|
|
|
|
|
|
|
|
snprintf(buffer, kBufferSize, " user_key_len: %u\n",
|
2015-10-28 18:46:01 +01:00
|
|
|
table_options_.user_key_len);
|
2014-08-25 23:24:09 +02:00
|
|
|
ret.append(buffer);
|
2019-03-02 00:41:55 +01:00
|
|
|
snprintf(buffer, kBufferSize, " bloom_bits_per_key: %d\n",
|
|
|
|
table_options_.bloom_bits_per_key);
|
|
|
|
ret.append(buffer);
|
|
|
|
snprintf(buffer, kBufferSize, " hash_table_ratio: %lf\n",
|
|
|
|
table_options_.hash_table_ratio);
|
|
|
|
ret.append(buffer);
|
2015-07-02 01:13:49 +02:00
|
|
|
snprintf(buffer, kBufferSize, " index_sparseness: %" ROCKSDB_PRIszt "\n",
|
2015-10-28 18:46:01 +01:00
|
|
|
table_options_.index_sparseness);
|
2014-08-25 23:24:09 +02:00
|
|
|
ret.append(buffer);
|
2019-03-02 00:41:55 +01:00
|
|
|
snprintf(buffer, kBufferSize, " huge_page_tlb_size: %" ROCKSDB_PRIszt "\n",
|
|
|
|
table_options_.huge_page_tlb_size);
|
|
|
|
ret.append(buffer);
|
2014-08-25 23:24:09 +02:00
|
|
|
snprintf(buffer, kBufferSize, " encoding_type: %d\n",
|
2015-10-28 18:46:01 +01:00
|
|
|
table_options_.encoding_type);
|
2014-08-25 23:24:09 +02:00
|
|
|
ret.append(buffer);
|
|
|
|
snprintf(buffer, kBufferSize, " full_scan_mode: %d\n",
|
2015-10-28 18:46:01 +01:00
|
|
|
table_options_.full_scan_mode);
|
2014-08-25 23:24:09 +02:00
|
|
|
ret.append(buffer);
|
2019-03-02 00:41:55 +01:00
|
|
|
snprintf(buffer, kBufferSize, " store_index_in_file: %d\n",
|
|
|
|
table_options_.store_index_in_file);
|
|
|
|
ret.append(buffer);
|
2014-08-25 23:24:09 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-30 23:58:46 +01:00
|
|
|
const PlainTableOptions& PlainTableFactory::table_options() const {
|
2015-10-28 18:46:01 +01:00
|
|
|
return table_options_;
|
|
|
|
}
|
|
|
|
|
2017-07-29 01:23:50 +02:00
|
|
|
Status GetPlainTableOptionsFromString(const PlainTableOptions& table_options,
|
|
|
|
const std::string& opts_str,
|
|
|
|
PlainTableOptions* new_table_options) {
|
2020-04-22 02:35:28 +02:00
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.input_strings_escaped = false;
|
|
|
|
config_options.ignore_unknown_options = false;
|
|
|
|
return GetPlainTableOptionsFromString(config_options, table_options, opts_str,
|
|
|
|
new_table_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status GetPlainTableOptionsFromString(const ConfigOptions& config_options,
|
|
|
|
const PlainTableOptions& table_options,
|
|
|
|
const std::string& opts_str,
|
|
|
|
PlainTableOptions* new_table_options) {
|
2017-07-29 01:23:50 +02:00
|
|
|
std::unordered_map<std::string, std::string> opts_map;
|
|
|
|
Status s = StringToMap(opts_str, &opts_map);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
2020-04-22 02:35:28 +02:00
|
|
|
|
|
|
|
return GetPlainTableOptionsFromMap(config_options, table_options, opts_map,
|
2017-07-29 01:23:50 +02:00
|
|
|
new_table_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status GetMemTableRepFactoryFromString(
|
|
|
|
const std::string& opts_str,
|
|
|
|
std::unique_ptr<MemTableRepFactory>* new_mem_factory) {
|
|
|
|
std::vector<std::string> opts_list = StringSplit(opts_str, ':');
|
|
|
|
size_t len = opts_list.size();
|
|
|
|
|
2018-02-16 01:43:23 +01:00
|
|
|
if (opts_list.empty() || opts_list.size() > 2) {
|
2017-07-29 01:23:50 +02:00
|
|
|
return Status::InvalidArgument("Can't parse memtable_factory option ",
|
|
|
|
opts_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
MemTableRepFactory* mem_factory = nullptr;
|
|
|
|
|
|
|
|
if (opts_list[0] == "skip_list") {
|
|
|
|
// Expecting format
|
|
|
|
// skip_list:<lookahead>
|
|
|
|
if (2 == len) {
|
|
|
|
size_t lookahead = ParseSizeT(opts_list[1]);
|
|
|
|
mem_factory = new SkipListFactory(lookahead);
|
|
|
|
} else if (1 == len) {
|
|
|
|
mem_factory = new SkipListFactory();
|
|
|
|
}
|
|
|
|
} 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]);
|
|
|
|
mem_factory = NewHashSkipListRepFactory(hash_bucket_count);
|
|
|
|
} else if (1 == len) {
|
|
|
|
mem_factory = NewHashSkipListRepFactory();
|
|
|
|
}
|
|
|
|
} 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]);
|
|
|
|
mem_factory = NewHashLinkListRepFactory(hash_bucket_count);
|
|
|
|
} else if (1 == len) {
|
|
|
|
mem_factory = NewHashLinkListRepFactory();
|
|
|
|
}
|
|
|
|
} else if (opts_list[0] == "vector") {
|
|
|
|
// Expecting format
|
|
|
|
// vector:<count>
|
|
|
|
if (2 == len) {
|
|
|
|
size_t count = ParseSizeT(opts_list[1]);
|
|
|
|
mem_factory = new VectorRepFactory(count);
|
|
|
|
} else if (1 == len) {
|
|
|
|
mem_factory = new VectorRepFactory();
|
|
|
|
}
|
|
|
|
} else if (opts_list[0] == "cuckoo") {
|
2019-02-08 01:06:40 +01:00
|
|
|
return Status::NotSupported(
|
|
|
|
"cuckoo hash memtable is not supported anymore.");
|
2017-07-29 01:23:50 +02:00
|
|
|
} else {
|
|
|
|
return Status::InvalidArgument("Unrecognized memtable_factory option ",
|
|
|
|
opts_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mem_factory != nullptr) {
|
|
|
|
new_mem_factory->reset(mem_factory);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2020-04-22 02:35:28 +02:00
|
|
|
std::string ParsePlainTableOptions(const ConfigOptions& config_options,
|
|
|
|
const std::string& name,
|
2017-07-29 01:23:50 +02:00
|
|
|
const std::string& org_value,
|
2020-04-22 02:35:28 +02:00
|
|
|
PlainTableOptions* new_options) {
|
|
|
|
const std::string& value = config_options.input_strings_escaped
|
|
|
|
? UnescapeOptionString(org_value)
|
|
|
|
: org_value;
|
2017-07-29 01:23:50 +02:00
|
|
|
const auto iter = plain_table_type_info.find(name);
|
|
|
|
if (iter == plain_table_type_info.end()) {
|
2020-04-22 02:35:28 +02:00
|
|
|
if (config_options.ignore_unknown_options) {
|
2017-07-29 01:23:50 +02:00
|
|
|
return "";
|
|
|
|
} else {
|
|
|
|
return "Unrecognized option";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto& opt_info = iter->second;
|
2020-05-21 19:56:40 +02:00
|
|
|
Status s =
|
|
|
|
opt_info.Parse(config_options, name, value,
|
|
|
|
reinterpret_cast<char*>(new_options) + opt_info.offset_);
|
2020-04-29 03:02:11 +02:00
|
|
|
if (s.ok()) {
|
|
|
|
return "";
|
|
|
|
} else {
|
|
|
|
return s.ToString();
|
2017-07-29 01:23:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status GetPlainTableOptionsFromMap(
|
|
|
|
const PlainTableOptions& table_options,
|
|
|
|
const std::unordered_map<std::string, std::string>& opts_map,
|
|
|
|
PlainTableOptions* new_table_options, bool input_strings_escaped,
|
2020-04-22 02:35:28 +02:00
|
|
|
bool ignore_unknown_options) {
|
|
|
|
ConfigOptions config_options;
|
|
|
|
config_options.input_strings_escaped = input_strings_escaped;
|
|
|
|
config_options.ignore_unknown_options = ignore_unknown_options;
|
|
|
|
return GetPlainTableOptionsFromMap(config_options, table_options, opts_map,
|
|
|
|
new_table_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status GetPlainTableOptionsFromMap(
|
|
|
|
const ConfigOptions& config_options, const PlainTableOptions& table_options,
|
|
|
|
const std::unordered_map<std::string, std::string>& opts_map,
|
|
|
|
PlainTableOptions* new_table_options) {
|
2017-07-29 01:23:50 +02:00
|
|
|
assert(new_table_options);
|
|
|
|
*new_table_options = table_options;
|
|
|
|
for (const auto& o : opts_map) {
|
2020-04-22 02:35:28 +02:00
|
|
|
auto error_message = ParsePlainTableOptions(config_options, o.first,
|
|
|
|
o.second, new_table_options);
|
2017-07-29 01:23:50 +02:00
|
|
|
if (error_message != "") {
|
|
|
|
const auto iter = plain_table_type_info.find(o.first);
|
|
|
|
if (iter == plain_table_type_info.end() ||
|
2020-04-22 02:35:28 +02:00
|
|
|
!config_options
|
|
|
|
.input_strings_escaped || // !input_strings_escaped indicates
|
|
|
|
// the old API, where everything is
|
|
|
|
// parsable.
|
2020-04-03 19:48:46 +02:00
|
|
|
(!iter->second.IsByName() && !iter->second.IsDeprecated())) {
|
2017-07-29 01:23:50 +02:00
|
|
|
// Restore "new_options" to the default "base_options".
|
|
|
|
*new_table_options = table_options;
|
|
|
|
return Status::InvalidArgument("Can't parse PlainTableOptions:",
|
|
|
|
o.first + " " + error_message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2014-07-18 09:08:38 +02:00
|
|
|
extern TableFactory* NewPlainTableFactory(const PlainTableOptions& options) {
|
|
|
|
return new PlainTableFactory(options);
|
2014-01-28 06:58:46 +01:00
|
|
|
}
|
|
|
|
|
2014-06-19 01:36:48 +02:00
|
|
|
const std::string PlainTablePropertyNames::kEncodingType =
|
|
|
|
"rocksdb.plain.table.encoding.type";
|
|
|
|
|
2014-07-19 01:58:13 +02:00
|
|
|
const std::string PlainTablePropertyNames::kBloomVersion =
|
|
|
|
"rocksdb.plain.table.bloom.version";
|
|
|
|
|
|
|
|
const std::string PlainTablePropertyNames::kNumBloomBlocks =
|
|
|
|
"rocksdb.plain.table.bloom.numblocks";
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2014-04-15 22:39:26 +02:00
|
|
|
#endif // ROCKSDB_LITE
|