fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
236 lines
8.8 KiB
236 lines
8.8 KiB
6 years ago
|
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
||
11 years ago
|
// 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.
|
||
|
|
||
11 years ago
|
#ifndef ROCKSDB_LITE
|
||
6 years ago
|
#include "table/plain/plain_table_factory.h"
|
||
11 years ago
|
|
||
|
#include <stdint.h>
|
||
7 years ago
|
#include <memory>
|
||
11 years ago
|
#include "db/dbformat.h"
|
||
7 years ago
|
#include "options/options_helper.h"
|
||
|
#include "port/port.h"
|
||
|
#include "rocksdb/convenience.h"
|
||
6 years ago
|
#include "table/plain/plain_table_builder.h"
|
||
|
#include "table/plain/plain_table_reader.h"
|
||
7 years ago
|
#include "util/string_util.h"
|
||
11 years ago
|
|
||
|
namespace rocksdb {
|
||
|
|
||
9 years ago
|
Status PlainTableFactory::NewTableReader(
|
||
9 years ago
|
const TableReaderOptions& table_reader_options,
|
||
6 years ago
|
std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
|
||
|
std::unique_ptr<TableReader>* table,
|
||
7 years ago
|
bool /*prefetch_index_and_filter_in_cache*/) const {
|
||
9 years ago
|
return PlainTableReader::Open(
|
||
|
table_reader_options.ioptions, table_reader_options.env_options,
|
||
|
table_reader_options.internal_comparator, std::move(file), file_size,
|
||
9 years ago
|
table, table_options_.bloom_bits_per_key, table_options_.hash_table_ratio,
|
||
|
table_options_.index_sparseness, table_options_.huge_page_tlb_size,
|
||
6 years ago
|
table_options_.full_scan_mode, table_reader_options.immortal,
|
||
|
table_reader_options.prefix_extractor);
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
TableBuilder* PlainTableFactory::NewTableBuilder(
|
||
9 years ago
|
const TableBuilderOptions& table_builder_options, uint32_t column_family_id,
|
||
9 years ago
|
WritableFileWriter* file) const {
|
||
10 years ago
|
// Ignore the skip_filters flag. PlainTable format is optimized for small
|
||
|
// in-memory dbs. The skip_filters optimization is not useful for plain
|
||
|
// tables
|
||
|
//
|
||
9 years ago
|
return new PlainTableBuilder(
|
||
7 years ago
|
table_builder_options.ioptions, table_builder_options.moptions,
|
||
9 years ago
|
table_builder_options.int_tbl_prop_collector_factories, column_family_id,
|
||
9 years ago
|
file, table_options_.user_key_len, table_options_.encoding_type,
|
||
6 years ago
|
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);
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
10 years ago
|
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",
|
||
9 years ago
|
table_options_.user_key_len);
|
||
10 years ago
|
ret.append(buffer);
|
||
6 years ago
|
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);
|
||
10 years ago
|
snprintf(buffer, kBufferSize, " index_sparseness: %" ROCKSDB_PRIszt "\n",
|
||
9 years ago
|
table_options_.index_sparseness);
|
||
10 years ago
|
ret.append(buffer);
|
||
6 years ago
|
snprintf(buffer, kBufferSize, " huge_page_tlb_size: %" ROCKSDB_PRIszt "\n",
|
||
|
table_options_.huge_page_tlb_size);
|
||
|
ret.append(buffer);
|
||
10 years ago
|
snprintf(buffer, kBufferSize, " encoding_type: %d\n",
|
||
9 years ago
|
table_options_.encoding_type);
|
||
10 years ago
|
ret.append(buffer);
|
||
|
snprintf(buffer, kBufferSize, " full_scan_mode: %d\n",
|
||
9 years ago
|
table_options_.full_scan_mode);
|
||
10 years ago
|
ret.append(buffer);
|
||
6 years ago
|
snprintf(buffer, kBufferSize, " store_index_in_file: %d\n",
|
||
|
table_options_.store_index_in_file);
|
||
|
ret.append(buffer);
|
||
10 years ago
|
return ret;
|
||
|
}
|
||
|
|
||
9 years ago
|
const PlainTableOptions& PlainTableFactory::table_options() const {
|
||
9 years ago
|
return table_options_;
|
||
|
}
|
||
|
|
||
7 years ago
|
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,
|
||
|
std::unique_ptr<MemTableRepFactory>* new_mem_factory) {
|
||
|
std::vector<std::string> opts_list = StringSplit(opts_str, ':');
|
||
|
size_t len = opts_list.size();
|
||
|
|
||
7 years ago
|
if (opts_list.empty() || opts_list.size() > 2) {
|
||
7 years ago
|
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") {
|
||
6 years ago
|
return Status::NotSupported(
|
||
|
"cuckoo hash memtable is not supported anymore.");
|
||
7 years ago
|
} else {
|
||
|
return Status::InvalidArgument("Unrecognized memtable_factory option ",
|
||
|
opts_str);
|
||
|
}
|
||
|
|
||
|
if (mem_factory != nullptr) {
|
||
|
new_mem_factory->reset(mem_factory);
|
||
|
}
|
||
|
|
||
|
return Status::OK();
|
||
|
}
|
||
|
|
||
|
std::string ParsePlainTableOptions(const std::string& name,
|
||
|
const std::string& org_value,
|
||
|
PlainTableOptions* new_options,
|
||
|
bool input_strings_escaped = false,
|
||
|
bool ignore_unknown_options = false) {
|
||
|
const std::string& value =
|
||
|
input_strings_escaped ? UnescapeOptionString(org_value) : org_value;
|
||
|
const auto iter = plain_table_type_info.find(name);
|
||
|
if (iter == plain_table_type_info.end()) {
|
||
|
if (ignore_unknown_options) {
|
||
|
return "";
|
||
|
} else {
|
||
|
return "Unrecognized option";
|
||
|
}
|
||
|
}
|
||
|
const auto& opt_info = iter->second;
|
||
|
if (opt_info.verification != OptionVerificationType::kDeprecated &&
|
||
|
!ParseOptionHelper(reinterpret_cast<char*>(new_options) + opt_info.offset,
|
||
|
opt_info.type, value)) {
|
||
|
return "Invalid value";
|
||
|
}
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
Status GetPlainTableOptionsFromMap(
|
||
|
const PlainTableOptions& table_options,
|
||
|
const std::unordered_map<std::string, std::string>& opts_map,
|
||
|
PlainTableOptions* new_table_options, bool input_strings_escaped,
|
||
7 years ago
|
bool /*ignore_unknown_options*/) {
|
||
7 years ago
|
assert(new_table_options);
|
||
|
*new_table_options = table_options;
|
||
|
for (const auto& o : opts_map) {
|
||
|
auto error_message = ParsePlainTableOptions(
|
||
|
o.first, o.second, new_table_options, input_strings_escaped);
|
||
|
if (error_message != "") {
|
||
|
const auto iter = plain_table_type_info.find(o.first);
|
||
|
if (iter == plain_table_type_info.end() ||
|
||
|
!input_strings_escaped || // !input_strings_escaped indicates
|
||
|
// the old API, where everything is
|
||
|
// parsable.
|
||
|
(iter->second.verification != OptionVerificationType::kByName &&
|
||
|
iter->second.verification !=
|
||
|
OptionVerificationType::kByNameAllowNull &&
|
||
7 years ago
|
iter->second.verification !=
|
||
|
OptionVerificationType::kByNameAllowFromNull &&
|
||
7 years ago
|
iter->second.verification != OptionVerificationType::kDeprecated)) {
|
||
|
// 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();
|
||
|
}
|
||
|
|
||
10 years ago
|
extern TableFactory* NewPlainTableFactory(const PlainTableOptions& options) {
|
||
|
return new PlainTableFactory(options);
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
const std::string PlainTablePropertyNames::kEncodingType =
|
||
|
"rocksdb.plain.table.encoding.type";
|
||
|
|
||
10 years ago
|
const std::string PlainTablePropertyNames::kBloomVersion =
|
||
|
"rocksdb.plain.table.bloom.version";
|
||
|
|
||
|
const std::string PlainTablePropertyNames::kNumBloomBlocks =
|
||
|
"rocksdb.plain.table.bloom.numblocks";
|
||
|
|
||
11 years ago
|
} // namespace rocksdb
|
||
11 years ago
|
#endif // ROCKSDB_LITE
|