2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2014-09-17 19:49:13 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-02-07 18:35:15 +00:00
|
|
|
#include <map>
|
2014-11-18 21:21:02 +00:00
|
|
|
#include <stdexcept>
|
2016-09-20 20:02:41 +00:00
|
|
|
#include <string>
|
Add OptionsUtil::LoadOptionsFromFile() API
Summary:
This patch adds OptionsUtil::LoadOptionsFromFile() and
OptionsUtil::LoadLatestOptionsFromDB(), which allow developers
to construct DBOptions and ColumnFamilyOptions from a RocksDB
options file. Note that most pointer-typed options such as
merge_operator will not be constructed.
With this API, developers no longer need to remember all the
options in order to reopen an existing rocksdb instance like
the following:
DBOptions db_options;
std::vector<std::string> cf_names;
std::vector<ColumnFamilyOptions> cf_opts;
// Load primitive-typed options from an existing DB
OptionsUtil::LoadLatestOptionsFromDB(
dbname, &db_options, &cf_names, &cf_opts);
// Initialize necessary pointer-typed options
cf_opts[0].merge_operator.reset(new MyMergeOperator());
...
// Construct the vector of ColumnFamilyDescriptor
std::vector<ColumnFamilyDescriptor> cf_descs;
for (size_t i = 0; i < cf_opts.size(); ++i) {
cf_descs.emplace_back(cf_names[i], cf_opts[i]);
}
// Open the DB
DB* db = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
auto s = DB::Open(db_options, dbname, cf_descs,
&handles, &db);
Test Plan:
Augment existing tests in column_family_test
options_test
db_test
Reviewers: igor, IslamAbdelRahman, sdong, anthony
Reviewed By: anthony
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D49095
2015-11-12 14:52:43 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2015-08-26 23:13:56 +00:00
|
|
|
#include "rocksdb/options.h"
|
2014-11-05 00:23:05 +00:00
|
|
|
#include "rocksdb/status.h"
|
2015-10-11 19:17:42 +00:00
|
|
|
#include "rocksdb/table.h"
|
2014-09-17 19:49:13 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2020-09-14 23:59:00 +00:00
|
|
|
struct ColumnFamilyOptions;
|
2020-04-22 00:35:28 +00:00
|
|
|
struct ConfigOptions;
|
2020-09-14 23:59:00 +00:00
|
|
|
struct DBOptions;
|
2021-04-23 03:42:50 +00:00
|
|
|
struct ImmutableCFOptions;
|
2020-09-14 23:59:00 +00:00
|
|
|
struct ImmutableDBOptions;
|
|
|
|
struct MutableDBOptions;
|
|
|
|
struct MutableCFOptions;
|
|
|
|
struct Options;
|
2014-09-17 19:49:13 +00:00
|
|
|
|
2020-04-24 22:30:12 +00:00
|
|
|
std::vector<CompressionType> GetSupportedCompressions();
|
|
|
|
|
2020-11-03 03:20:15 +00:00
|
|
|
std::vector<CompressionType> GetSupportedDictCompressions();
|
|
|
|
|
Implement XXH3 block checksum type (#9069)
Summary:
XXH3 - latest hash function that is extremely fast on large
data, easily faster than crc32c on most any x86_64 hardware. In
integrating this hash function, I have handled the compression type byte
in a non-standard way to avoid using the streaming API (extra data
movement and active code size because of hash function complexity). This
approach got a thumbs-up from Yann Collet.
Existing functionality change:
* reject bad ChecksumType in options with InvalidArgument
This change split off from https://github.com/facebook/rocksdb/issues/9058 because context-aware checksum is
likely to be handled through different configuration than ChecksumType.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/9069
Test Plan:
tests updated, and substantially expanded. Unit tests now check
that we don't accidentally change the values generated by the checksum
algorithms ("schema test") and that we properly handle
invalid/unrecognized checksum types in options or in file footer.
DBTestBase::ChangeOptions (etc.) updated from two to one configuration
changing from default CRC32c ChecksumType. The point of this test code
is to detect possible interactions among features, and the likelihood of
some bad interaction being detected by including configurations other
than XXH3 and CRC32c--and then not detected by stress/crash test--is
extremely low.
Stress/crash test also updated (manual run long enough to see it accepts
new checksum type). db_bench also updated for microbenchmarking
checksums.
### Performance microbenchmark (PORTABLE=0 DEBUG_LEVEL=0, Broadwell processor)
./db_bench -benchmarks=crc32c,xxhash,xxhash64,xxh3,crc32c,xxhash,xxhash64,xxh3,crc32c,xxhash,xxhash64,xxh3
crc32c : 0.200 micros/op 5005220 ops/sec; 19551.6 MB/s (4096 per op)
xxhash : 0.807 micros/op 1238408 ops/sec; 4837.5 MB/s (4096 per op)
xxhash64 : 0.421 micros/op 2376514 ops/sec; 9283.3 MB/s (4096 per op)
xxh3 : 0.171 micros/op 5858391 ops/sec; 22884.3 MB/s (4096 per op)
crc32c : 0.206 micros/op 4859566 ops/sec; 18982.7 MB/s (4096 per op)
xxhash : 0.793 micros/op 1260850 ops/sec; 4925.2 MB/s (4096 per op)
xxhash64 : 0.410 micros/op 2439182 ops/sec; 9528.1 MB/s (4096 per op)
xxh3 : 0.161 micros/op 6202872 ops/sec; 24230.0 MB/s (4096 per op)
crc32c : 0.203 micros/op 4924686 ops/sec; 19237.1 MB/s (4096 per op)
xxhash : 0.839 micros/op 1192388 ops/sec; 4657.8 MB/s (4096 per op)
xxhash64 : 0.424 micros/op 2357391 ops/sec; 9208.6 MB/s (4096 per op)
xxh3 : 0.162 micros/op 6182678 ops/sec; 24151.1 MB/s (4096 per op)
As you can see, especially once warmed up, xxh3 is fastest.
### Performance macrobenchmark (PORTABLE=0 DEBUG_LEVEL=0, Broadwell processor)
Test
for I in `seq 1 50`; do for CHK in 0 1 2 3 4; do TEST_TMPDIR=/dev/shm/rocksdb$CHK ./db_bench -benchmarks=fillseq -memtablerep=vector -allow_concurrent_memtable_write=false -num=30000000 -checksum_type=$CHK 2>&1 | grep 'micros/op' | tee -a results-$CHK & done; wait; done
Results (ops/sec)
for FILE in results*; do echo -n "$FILE "; awk '{ s += $5; c++; } END { print 1.0 * s / c; }' < $FILE; done
results-0 252118 # kNoChecksum
results-1 251588 # kCRC32c
results-2 251863 # kxxHash
results-3 252016 # kxxHash64
results-4 252038 # kXXH3
Reviewed By: mrambacher
Differential Revision: D31905249
Pulled By: pdillinger
fbshipit-source-id: cb9b998ebe2523fc7c400eedf62124a78bf4b4d1
2021-10-29 05:13:47 +00:00
|
|
|
std::vector<ChecksumType> GetSupportedChecksums();
|
|
|
|
|
2021-11-04 16:08:12 +00:00
|
|
|
inline bool IsSupportedChecksumType(ChecksumType type) {
|
2021-11-04 21:59:37 +00:00
|
|
|
// Avoid annoying compiler warning-as-error (-Werror=type-limits)
|
|
|
|
auto min = kNoChecksum;
|
|
|
|
auto max = kXXH3;
|
|
|
|
return type >= min && type <= max;
|
2021-11-04 16:08:12 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 23:59:00 +00:00
|
|
|
// Checks that the combination of DBOptions and ColumnFamilyOptions are valid
|
|
|
|
Status ValidateOptions(const DBOptions& db_opts,
|
|
|
|
const ColumnFamilyOptions& cf_opts);
|
|
|
|
|
2016-09-23 23:34:04 +00:00
|
|
|
DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options,
|
|
|
|
const MutableDBOptions& mutable_db_options);
|
|
|
|
|
2016-09-15 05:10:28 +00:00
|
|
|
ColumnFamilyOptions BuildColumnFamilyOptions(
|
|
|
|
const ColumnFamilyOptions& ioptions,
|
|
|
|
const MutableCFOptions& mutable_cf_options);
|
2021-05-05 20:59:21 +00:00
|
|
|
|
|
|
|
void UpdateColumnFamilyOptions(const ImmutableCFOptions& ioptions,
|
|
|
|
ColumnFamilyOptions* cf_opts);
|
|
|
|
void UpdateColumnFamilyOptions(const MutableCFOptions& moptions,
|
|
|
|
ColumnFamilyOptions* cf_opts);
|
2016-09-15 05:10:28 +00:00
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
2020-09-14 23:59:00 +00:00
|
|
|
std::unique_ptr<Configurable> DBOptionsAsConfigurable(
|
|
|
|
const MutableDBOptions& opts);
|
2021-10-19 17:42:04 +00:00
|
|
|
std::unique_ptr<Configurable> DBOptionsAsConfigurable(
|
|
|
|
const DBOptions& opts,
|
|
|
|
const std::unordered_map<std::string, std::string>* opt_map = nullptr);
|
2020-09-14 23:59:00 +00:00
|
|
|
std::unique_ptr<Configurable> CFOptionsAsConfigurable(
|
|
|
|
const MutableCFOptions& opts);
|
|
|
|
std::unique_ptr<Configurable> CFOptionsAsConfigurable(
|
|
|
|
const ColumnFamilyOptions& opts,
|
|
|
|
const std::unordered_map<std::string, std::string>* opt_map = nullptr);
|
|
|
|
|
2017-07-28 23:23:50 +00:00
|
|
|
extern Status StringToMap(
|
|
|
|
const std::string& opts_str,
|
|
|
|
std::unordered_map<std::string, std::string>* opts_map);
|
2016-09-15 05:10:28 +00:00
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
2017-11-18 01:02:13 +00:00
|
|
|
struct OptionsHelper {
|
2020-09-14 23:59:00 +00:00
|
|
|
static const std::string kCFOptionsName /*= "ColumnFamilyOptions"*/;
|
|
|
|
static const std::string kDBOptionsName /*= "DBOptions" */;
|
2017-11-18 01:02:13 +00:00
|
|
|
static std::map<CompactionStyle, std::string> compaction_style_to_string;
|
|
|
|
static std::map<CompactionPri, std::string> compaction_pri_to_string;
|
|
|
|
static std::map<CompactionStopStyle, std::string>
|
|
|
|
compaction_stop_style_to_string;
|
|
|
|
static std::unordered_map<std::string, ChecksumType> checksum_type_string_map;
|
2018-01-23 22:36:54 +00:00
|
|
|
static std::unordered_map<std::string, CompressionType>
|
|
|
|
compression_type_string_map;
|
2017-11-18 01:02:13 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
2017-12-11 21:12:12 +00:00
|
|
|
static std::unordered_map<std::string, CompactionStopStyle>
|
|
|
|
compaction_stop_style_string_map;
|
2017-11-18 01:02:13 +00:00
|
|
|
static std::unordered_map<std::string, EncodingType> encoding_type_string_map;
|
|
|
|
static std::unordered_map<std::string, CompactionStyle>
|
|
|
|
compaction_style_string_map;
|
|
|
|
static std::unordered_map<std::string, CompactionPri>
|
|
|
|
compaction_pri_string_map;
|
2022-01-25 22:58:48 +00:00
|
|
|
static std::unordered_map<std::string, Temperature> temperature_string_map;
|
2017-11-18 01:02:13 +00:00
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
};
|
|
|
|
|
|
|
|
// Some aliasing
|
|
|
|
static auto& compaction_style_to_string =
|
|
|
|
OptionsHelper::compaction_style_to_string;
|
|
|
|
static auto& compaction_pri_to_string = OptionsHelper::compaction_pri_to_string;
|
|
|
|
static auto& compaction_stop_style_to_string =
|
|
|
|
OptionsHelper::compaction_stop_style_to_string;
|
|
|
|
static auto& checksum_type_string_map = OptionsHelper::checksum_type_string_map;
|
|
|
|
#ifndef ROCKSDB_LITE
|
2017-12-11 21:12:12 +00:00
|
|
|
static auto& compaction_stop_style_string_map =
|
|
|
|
OptionsHelper::compaction_stop_style_string_map;
|
2017-11-18 01:02:13 +00:00
|
|
|
static auto& compression_type_string_map =
|
|
|
|
OptionsHelper::compression_type_string_map;
|
|
|
|
static auto& encoding_type_string_map = OptionsHelper::encoding_type_string_map;
|
|
|
|
static auto& compaction_style_string_map =
|
|
|
|
OptionsHelper::compaction_style_string_map;
|
|
|
|
static auto& compaction_pri_string_map =
|
|
|
|
OptionsHelper::compaction_pri_string_map;
|
2022-01-25 22:58:48 +00:00
|
|
|
static auto& temperature_string_map = OptionsHelper::temperature_string_map;
|
2017-11-18 01:02:13 +00:00
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|