2019-12-09 08:49:32 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// 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).
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifdef GFLAGS
|
|
|
|
#include "db_stress_tool/db_stress_common.h"
|
2020-06-18 18:51:14 +02:00
|
|
|
#include "db_stress_tool/db_stress_compaction_filter.h"
|
2019-12-09 08:49:32 +01:00
|
|
|
#include "db_stress_tool/db_stress_driver.h"
|
2020-08-11 01:16:19 +02:00
|
|
|
#include "db_stress_tool/db_stress_table_properties_collector.h"
|
2019-12-11 05:01:25 +01:00
|
|
|
#include "rocksdb/convenience.h"
|
2021-09-29 13:01:57 +02:00
|
|
|
#include "rocksdb/filter_policy.h"
|
2021-06-28 08:53:47 +02:00
|
|
|
#include "rocksdb/secondary_cache.h"
|
2020-02-26 01:43:33 +01:00
|
|
|
#include "rocksdb/sst_file_manager.h"
|
2020-12-17 20:51:04 +01:00
|
|
|
#include "rocksdb/types.h"
|
2021-06-28 08:53:47 +02:00
|
|
|
#include "rocksdb/utilities/object_registry.h"
|
2020-07-03 05:51:48 +02:00
|
|
|
#include "util/cast_util.h"
|
Begin forward compatibility for new backup meta schema (#8069)
Summary:
This does not add any new public APIs or published
functionality, but adds the ability to read and use (and in tests,
write) backups with a new meta file schema, based on the old schema
but not forward-compatible (before this change). The new schema enables
some capabilities not in the old:
* Explicit versioning, so that users get clean error messages the next
time we want to break forward compatibility.
* Ignoring unrecognized fields (with warning), so that new non-critical
features can be added without breaking forward compatibility.
* Rejecting future "non-ignorable" fields, so that new features critical
to some use-cases could potentially be added outside of linear schema
versions, with broken forward compatibility.
* Fields at the end of the meta file, such as for checksum of the meta
file's contents (up to that point)
* New optional 'size' field for each file, which is checked when present
* Optionally omitting 'crc32' field, so that we aren't required to have
a crc32c checksum for files to take a backup. (E.g. to support backup
via hard links and to better support file custom checksums.)
Because we do not have a JSON parser and to share code, the new schema
is simply derived from the old schema.
BackupEngine code is updated to allow missing checksums in some places,
and to make that easier, `has_checksum` and `verify_checksum_after_work`
are eliminated. Empty `checksum_hex` indicates checksum is unknown. I'm
not too afraid of regressing on data integrity, because
(a) we have pretty good test coverage of corruption detection in backups, and
(b) we are increasingly relying on the DB itself for data integrity rather than
it being an exclusive feature of backups.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8069
Test Plan:
new unit tests, added to crash test (some local run with
boosted backup probability)
Reviewed By: ajkr
Differential Revision: D27139824
Pulled By: pdillinger
fbshipit-source-id: 9e0e4decfb42bb84783d64d2d246456d97e8e8c5
2021-03-20 04:14:38 +01:00
|
|
|
#include "utilities/backupable/backupable_db_impl.h"
|
2020-07-09 23:33:42 +02:00
|
|
|
#include "utilities/fault_injection_fs.h"
|
2021-11-08 19:26:48 +01:00
|
|
|
#include "utilities/fault_injection_secondary_cache.h"
|
2019-12-09 08:49:32 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2021-06-17 21:28:00 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
std::shared_ptr<const FilterPolicy> CreateFilterPolicy() {
|
|
|
|
if (FLAGS_bloom_bits < 0) {
|
|
|
|
return BlockBasedTableOptions().filter_policy;
|
|
|
|
}
|
|
|
|
const FilterPolicy* new_policy;
|
Add Bloom/Ribbon hybrid API support (#8679)
Summary:
This is essentially resurrection and fixing of the part of
https://github.com/facebook/rocksdb/issues/8198 that was reverted in https://github.com/facebook/rocksdb/issues/8212, using data added in https://github.com/facebook/rocksdb/issues/8246. Basically,
when configuring Ribbon filter, you can specify an LSM level before which
Bloom will be used instead of Ribbon. But Bloom is only considered for
Leveled and Universal compaction styles and file going into a known LSM
level. This way, SST file writer, FIFO compaction, etc. use Ribbon filter as
you would expect with NewRibbonFilterPolicy.
So that this can be controlled with a single int value and so that flushes
can be distinguished from intra-L0, we consider flush to go to level -1 for
the purposes of this option. (Explained in API comment.)
I also expect the most common and recommended Ribbon configuration to
use Bloom during flush, to minimize slowing down writes and because according
to my estimates, Ribbon only pays off if the structure lives in memory for
more than an hour. Thus, I have changed the default for NewRibbonFilterPolicy
to be this mild hybrid configuration. I don't really want to add something like
NewHybridFilterPolicy because at least the mild hybrid configuration (Bloom for
flush, Ribbon otherwise) should be considered a natural choice.
C APIs also updated, but because they don't support overloading,
rocksdb_filterpolicy_create_ribbon is kept pure ribbon for clarity and
rocksdb_filterpolicy_create_ribbon_hybrid must be called for a hybrid
configuration. While touching C API, I changed bits per key options from
int to double.
BuiltinFilterPolicy is needed so that LevelThresholdFilterPolicy doesn't inherit
unused fields from BloomFilterPolicy.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8679
Test Plan: new + updated tests, including crash test
Reviewed By: jay-zhuang
Differential Revision: D30445797
Pulled By: pdillinger
fbshipit-source-id: 6f5aeddfd6d79f7e55493b563c2d1d2d568892e1
2021-08-21 02:59:24 +02:00
|
|
|
if (FLAGS_use_block_based_filter) {
|
|
|
|
if (FLAGS_ribbon_starting_level < 999) {
|
|
|
|
fprintf(
|
|
|
|
stderr,
|
|
|
|
"Cannot combine use_block_based_filter and ribbon_starting_level\n");
|
|
|
|
exit(1);
|
2021-06-17 21:28:00 +02:00
|
|
|
} else {
|
|
|
|
new_policy = NewBloomFilterPolicy(FLAGS_bloom_bits, true);
|
|
|
|
}
|
Add Bloom/Ribbon hybrid API support (#8679)
Summary:
This is essentially resurrection and fixing of the part of
https://github.com/facebook/rocksdb/issues/8198 that was reverted in https://github.com/facebook/rocksdb/issues/8212, using data added in https://github.com/facebook/rocksdb/issues/8246. Basically,
when configuring Ribbon filter, you can specify an LSM level before which
Bloom will be used instead of Ribbon. But Bloom is only considered for
Leveled and Universal compaction styles and file going into a known LSM
level. This way, SST file writer, FIFO compaction, etc. use Ribbon filter as
you would expect with NewRibbonFilterPolicy.
So that this can be controlled with a single int value and so that flushes
can be distinguished from intra-L0, we consider flush to go to level -1 for
the purposes of this option. (Explained in API comment.)
I also expect the most common and recommended Ribbon configuration to
use Bloom during flush, to minimize slowing down writes and because according
to my estimates, Ribbon only pays off if the structure lives in memory for
more than an hour. Thus, I have changed the default for NewRibbonFilterPolicy
to be this mild hybrid configuration. I don't really want to add something like
NewHybridFilterPolicy because at least the mild hybrid configuration (Bloom for
flush, Ribbon otherwise) should be considered a natural choice.
C APIs also updated, but because they don't support overloading,
rocksdb_filterpolicy_create_ribbon is kept pure ribbon for clarity and
rocksdb_filterpolicy_create_ribbon_hybrid must be called for a hybrid
configuration. While touching C API, I changed bits per key options from
int to double.
BuiltinFilterPolicy is needed so that LevelThresholdFilterPolicy doesn't inherit
unused fields from BloomFilterPolicy.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8679
Test Plan: new + updated tests, including crash test
Reviewed By: jay-zhuang
Differential Revision: D30445797
Pulled By: pdillinger
fbshipit-source-id: 6f5aeddfd6d79f7e55493b563c2d1d2d568892e1
2021-08-21 02:59:24 +02:00
|
|
|
} else if (FLAGS_ribbon_starting_level >= 999) {
|
|
|
|
// Use Bloom API
|
|
|
|
new_policy = NewBloomFilterPolicy(FLAGS_bloom_bits, false);
|
|
|
|
} else {
|
|
|
|
new_policy = NewRibbonFilterPolicy(
|
|
|
|
FLAGS_bloom_bits, /* bloom_before_level */ FLAGS_ribbon_starting_level);
|
2021-06-17 21:28:00 +02:00
|
|
|
}
|
|
|
|
return std::shared_ptr<const FilterPolicy>(new_policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
StressTest::StressTest()
|
2021-06-28 08:53:47 +02:00
|
|
|
: cache_(NewCache(FLAGS_cache_size, FLAGS_cache_numshardbits)),
|
2019-12-09 08:49:32 +01:00
|
|
|
compressed_cache_(NewLRUCache(FLAGS_compressed_cache_size)),
|
2021-06-17 21:28:00 +02:00
|
|
|
filter_policy_(CreateFilterPolicy()),
|
2019-12-09 08:49:32 +01:00
|
|
|
db_(nullptr),
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
txn_db_(nullptr),
|
|
|
|
#endif
|
2021-03-15 12:32:24 +01:00
|
|
|
clock_(db_stress_env->GetSystemClock().get()),
|
2019-12-09 08:49:32 +01:00
|
|
|
new_column_family_name_(1),
|
|
|
|
num_times_reopened_(0),
|
2019-12-20 17:46:52 +01:00
|
|
|
db_preload_finished_(false),
|
2021-07-01 23:15:49 +02:00
|
|
|
cmp_db_(nullptr),
|
|
|
|
is_db_stopped_(false) {
|
2019-12-09 08:49:32 +01:00
|
|
|
if (FLAGS_destroy_db_initially) {
|
|
|
|
std::vector<std::string> files;
|
2019-12-21 01:13:19 +01:00
|
|
|
db_stress_env->GetChildren(FLAGS_db, &files);
|
2019-12-09 08:49:32 +01:00
|
|
|
for (unsigned int i = 0; i < files.size(); i++) {
|
|
|
|
if (Slice(files[i]).starts_with("heap-")) {
|
2019-12-21 01:13:19 +01:00
|
|
|
db_stress_env->DeleteFile(FLAGS_db + "/" + files[i]);
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
}
|
2019-12-20 19:25:48 +01:00
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
Options options;
|
2020-03-17 00:54:29 +01:00
|
|
|
options.env = db_stress_env;
|
2019-12-16 23:28:06 +01:00
|
|
|
// Remove files without preserving manfiest files
|
2019-12-20 19:25:48 +01:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
const Status s = !FLAGS_use_blob_db
|
|
|
|
? DestroyDB(FLAGS_db, options)
|
|
|
|
: blob_db::DestroyBlobDB(FLAGS_db, options,
|
|
|
|
blob_db::BlobDBOptions());
|
|
|
|
#else
|
|
|
|
const Status s = DestroyDB(FLAGS_db, options);
|
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "Cannot destroy original db: %s\n", s.ToString().c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StressTest::~StressTest() {
|
|
|
|
for (auto cf : column_families_) {
|
|
|
|
delete cf;
|
|
|
|
}
|
|
|
|
column_families_.clear();
|
|
|
|
delete db_;
|
|
|
|
|
|
|
|
assert(secondaries_.size() == secondary_cfh_lists_.size());
|
|
|
|
size_t n = secondaries_.size();
|
|
|
|
for (size_t i = 0; i != n; ++i) {
|
|
|
|
for (auto* cf : secondary_cfh_lists_[i]) {
|
|
|
|
delete cf;
|
|
|
|
}
|
|
|
|
secondary_cfh_lists_[i].clear();
|
|
|
|
delete secondaries_[i];
|
|
|
|
}
|
|
|
|
secondaries_.clear();
|
2019-12-20 17:46:52 +01:00
|
|
|
|
|
|
|
for (auto* cf : cmp_cfhs_) {
|
|
|
|
delete cf;
|
|
|
|
}
|
|
|
|
cmp_cfhs_.clear();
|
|
|
|
delete cmp_db_;
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
|
2021-06-28 08:53:47 +02:00
|
|
|
std::shared_ptr<Cache> StressTest::NewCache(size_t capacity,
|
|
|
|
int32_t num_shard_bits) {
|
2021-07-06 18:17:13 +02:00
|
|
|
ConfigOptions config_options;
|
2019-12-09 08:49:32 +01:00
|
|
|
if (capacity <= 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (FLAGS_use_clock_cache) {
|
|
|
|
auto cache = NewClockCache((size_t)capacity);
|
|
|
|
if (!cache) {
|
|
|
|
fprintf(stderr, "Clock cache not supported.");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return cache;
|
|
|
|
} else {
|
2021-06-28 08:53:47 +02:00
|
|
|
LRUCacheOptions opts;
|
|
|
|
opts.capacity = capacity;
|
|
|
|
opts.num_shard_bits = num_shard_bits;
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
std::shared_ptr<SecondaryCache> secondary_cache;
|
|
|
|
if (!FLAGS_secondary_cache_uri.empty()) {
|
2021-07-06 18:17:13 +02:00
|
|
|
Status s = SecondaryCache::CreateFromString(
|
|
|
|
config_options, FLAGS_secondary_cache_uri, &secondary_cache);
|
2021-06-28 08:53:47 +02:00
|
|
|
if (secondary_cache == nullptr) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"No secondary cache registered matching string: %s status=%s\n",
|
|
|
|
FLAGS_secondary_cache_uri.c_str(), s.ToString().c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
2021-11-08 19:26:48 +01:00
|
|
|
if (FLAGS_secondary_cache_fault_one_in > 0) {
|
|
|
|
secondary_cache = std::make_shared<FaultInjectionSecondaryCache>(
|
2021-11-29 23:26:54 +01:00
|
|
|
secondary_cache, static_cast<uint32_t>(FLAGS_seed),
|
|
|
|
FLAGS_secondary_cache_fault_one_in);
|
2021-11-08 19:26:48 +01:00
|
|
|
}
|
2021-06-28 08:53:47 +02:00
|
|
|
opts.secondary_cache = secondary_cache;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return NewLRUCache(opts);
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-02 20:39:20 +01:00
|
|
|
std::vector<std::string> StressTest::GetBlobCompressionTags() {
|
|
|
|
std::vector<std::string> compression_tags{"kNoCompression"};
|
|
|
|
|
|
|
|
if (Snappy_Supported()) {
|
|
|
|
compression_tags.emplace_back("kSnappyCompression");
|
|
|
|
}
|
|
|
|
if (LZ4_Supported()) {
|
|
|
|
compression_tags.emplace_back("kLZ4Compression");
|
|
|
|
}
|
|
|
|
if (ZSTD_Supported()) {
|
|
|
|
compression_tags.emplace_back("kZSTD");
|
|
|
|
}
|
|
|
|
|
|
|
|
return compression_tags;
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
bool StressTest::BuildOptionsTable() {
|
|
|
|
if (FLAGS_set_options_one_in <= 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unordered_map<std::string, std::vector<std::string>> options_tbl = {
|
|
|
|
{"write_buffer_size",
|
|
|
|
{ToString(options_.write_buffer_size),
|
|
|
|
ToString(options_.write_buffer_size * 2),
|
|
|
|
ToString(options_.write_buffer_size * 4)}},
|
|
|
|
{"max_write_buffer_number",
|
|
|
|
{ToString(options_.max_write_buffer_number),
|
|
|
|
ToString(options_.max_write_buffer_number * 2),
|
|
|
|
ToString(options_.max_write_buffer_number * 4)}},
|
|
|
|
{"arena_block_size",
|
|
|
|
{
|
|
|
|
ToString(options_.arena_block_size),
|
|
|
|
ToString(options_.write_buffer_size / 4),
|
|
|
|
ToString(options_.write_buffer_size / 8),
|
|
|
|
}},
|
|
|
|
{"memtable_huge_page_size", {"0", ToString(2 * 1024 * 1024)}},
|
|
|
|
{"max_successive_merges", {"0", "2", "4"}},
|
|
|
|
{"inplace_update_num_locks", {"100", "200", "300"}},
|
|
|
|
// TODO(ljin): enable test for this option
|
|
|
|
// {"disable_auto_compactions", {"100", "200", "300"}},
|
|
|
|
{"soft_rate_limit", {"0", "0.5", "0.9"}},
|
|
|
|
{"hard_rate_limit", {"0", "1.1", "2.0"}},
|
|
|
|
{"level0_file_num_compaction_trigger",
|
|
|
|
{
|
|
|
|
ToString(options_.level0_file_num_compaction_trigger),
|
|
|
|
ToString(options_.level0_file_num_compaction_trigger + 2),
|
|
|
|
ToString(options_.level0_file_num_compaction_trigger + 4),
|
|
|
|
}},
|
|
|
|
{"level0_slowdown_writes_trigger",
|
|
|
|
{
|
|
|
|
ToString(options_.level0_slowdown_writes_trigger),
|
|
|
|
ToString(options_.level0_slowdown_writes_trigger + 2),
|
|
|
|
ToString(options_.level0_slowdown_writes_trigger + 4),
|
|
|
|
}},
|
|
|
|
{"level0_stop_writes_trigger",
|
|
|
|
{
|
|
|
|
ToString(options_.level0_stop_writes_trigger),
|
|
|
|
ToString(options_.level0_stop_writes_trigger + 2),
|
|
|
|
ToString(options_.level0_stop_writes_trigger + 4),
|
|
|
|
}},
|
|
|
|
{"max_compaction_bytes",
|
|
|
|
{
|
|
|
|
ToString(options_.target_file_size_base * 5),
|
|
|
|
ToString(options_.target_file_size_base * 15),
|
|
|
|
ToString(options_.target_file_size_base * 100),
|
|
|
|
}},
|
|
|
|
{"target_file_size_base",
|
|
|
|
{
|
|
|
|
ToString(options_.target_file_size_base),
|
|
|
|
ToString(options_.target_file_size_base * 2),
|
|
|
|
ToString(options_.target_file_size_base * 4),
|
|
|
|
}},
|
|
|
|
{"target_file_size_multiplier",
|
|
|
|
{
|
|
|
|
ToString(options_.target_file_size_multiplier),
|
|
|
|
"1",
|
|
|
|
"2",
|
|
|
|
}},
|
|
|
|
{"max_bytes_for_level_base",
|
|
|
|
{
|
|
|
|
ToString(options_.max_bytes_for_level_base / 2),
|
|
|
|
ToString(options_.max_bytes_for_level_base),
|
|
|
|
ToString(options_.max_bytes_for_level_base * 2),
|
|
|
|
}},
|
|
|
|
{"max_bytes_for_level_multiplier",
|
|
|
|
{
|
|
|
|
ToString(options_.max_bytes_for_level_multiplier),
|
|
|
|
"1",
|
|
|
|
"2",
|
|
|
|
}},
|
|
|
|
{"max_sequential_skip_in_iterations", {"4", "8", "12"}},
|
|
|
|
};
|
|
|
|
|
2021-02-02 20:39:20 +01:00
|
|
|
if (FLAGS_allow_setting_blob_options_dynamically) {
|
|
|
|
options_tbl.emplace("enable_blob_files",
|
|
|
|
std::vector<std::string>{"false", "true"});
|
|
|
|
options_tbl.emplace("min_blob_size",
|
2021-03-22 22:36:07 +01:00
|
|
|
std::vector<std::string>{"0", "8", "16"});
|
2021-02-02 20:39:20 +01:00
|
|
|
options_tbl.emplace("blob_file_size",
|
|
|
|
std::vector<std::string>{"1M", "16M", "256M", "1G"});
|
|
|
|
options_tbl.emplace("blob_compression_type", GetBlobCompressionTags());
|
|
|
|
options_tbl.emplace("enable_blob_garbage_collection",
|
|
|
|
std::vector<std::string>{"false", "true"});
|
|
|
|
options_tbl.emplace(
|
|
|
|
"blob_garbage_collection_age_cutoff",
|
|
|
|
std::vector<std::string>{"0.0", "0.25", "0.5", "0.75", "1.0"});
|
Make it possible to force the garbage collection of the oldest blob files (#8994)
Summary:
The current BlobDB garbage collection logic works by relocating the valid
blobs from the oldest blob files as they are encountered during compaction,
and cleaning up blob files once they contain nothing but garbage. However,
with sufficiently skewed workloads, it is theoretically possible to end up in a
situation when few or no compactions get scheduled for the SST files that contain
references to the oldest blob files, which can lead to increased space amp due
to the lack of GC.
In order to efficiently handle such workloads, the patch adds a new BlobDB
configuration option called `blob_garbage_collection_force_threshold`,
which signals to BlobDB to schedule targeted compactions for the SST files
that keep alive the oldest batch of blob files if the overall ratio of garbage in
the given blob files meets the threshold *and* all the given blob files are
eligible for GC based on `blob_garbage_collection_age_cutoff`. (For example,
if the new option is set to 0.9, targeted compactions will get scheduled if the
sum of garbage bytes meets or exceeds 90% of the sum of total bytes in the
oldest blob files, assuming all affected blob files are below the age-based cutoff.)
The net result of these targeted compactions is that the valid blobs in the oldest
blob files are relocated and the oldest blob files themselves cleaned up (since
*all* SST files that rely on them get compacted away).
These targeted compactions are similar to periodic compactions in the sense
that they force certain SST files that otherwise would not get picked up to undergo
compaction and also in the sense that instead of merging files from multiple levels,
they target a single file. (Note: such compactions might still include neighboring files
from the same level due to the need of having a "clean cut" boundary but they never
include any files from any other level.)
This functionality is currently only supported with the leveled compaction style
and is inactive by default (since the default value is set to 1.0, i.e. 100%).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8994
Test Plan: Ran `make check` and tested using `db_bench` and the stress/crash tests.
Reviewed By: riversand963
Differential Revision: D31489850
Pulled By: ltamasi
fbshipit-source-id: 44057d511726a0e2a03c5d9313d7511b3f0c4eab
2021-10-12 03:00:44 +02:00
|
|
|
options_tbl.emplace("blob_garbage_collection_force_threshold",
|
|
|
|
std::vector<std::string>{"0.5", "0.75", "1.0"});
|
2021-11-20 02:52:42 +01:00
|
|
|
options_tbl.emplace("blob_compaction_readahead_size",
|
|
|
|
std::vector<std::string>{"0", "1M", "4M"});
|
2021-02-02 20:39:20 +01:00
|
|
|
}
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
options_table_ = std::move(options_tbl);
|
|
|
|
|
|
|
|
for (const auto& iter : options_table_) {
|
|
|
|
options_index_.push_back(iter.first);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StressTest::InitDb() {
|
2021-03-15 12:32:24 +01:00
|
|
|
uint64_t now = clock_->NowMicros();
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, "%s Initializing db_stress\n",
|
2021-03-15 12:32:24 +01:00
|
|
|
clock_->TimeToString(now / 1000000).c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
PrintEnv();
|
|
|
|
Open();
|
|
|
|
BuildOptionsTable();
|
|
|
|
}
|
|
|
|
|
2020-06-18 18:51:14 +02:00
|
|
|
void StressTest::FinishInitDb(SharedState* shared) {
|
|
|
|
if (FLAGS_read_only) {
|
2021-03-15 12:32:24 +01:00
|
|
|
uint64_t now = clock_->NowMicros();
|
2020-06-18 18:51:14 +02:00
|
|
|
fprintf(stdout, "%s Preloading db with %" PRIu64 " KVs\n",
|
2021-03-15 12:32:24 +01:00
|
|
|
clock_->TimeToString(now / 1000000).c_str(), FLAGS_max_key);
|
2020-06-18 18:51:14 +02:00
|
|
|
PreloadDbAndReopenAsReadOnly(FLAGS_max_key, shared);
|
|
|
|
}
|
2021-12-15 21:53:32 +01:00
|
|
|
|
2021-12-18 07:04:05 +01:00
|
|
|
if (shared->HasHistory()) {
|
2021-12-15 21:53:32 +01:00
|
|
|
// The way it works right now is, if there's any history, that means the
|
|
|
|
// previous run mutating the DB had all its operations traced, in which case
|
|
|
|
// we should always be able to `Restore()` the expected values to match the
|
|
|
|
// `db_`'s current seqno.
|
|
|
|
Status s = shared->Restore(db_);
|
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "Error restoring historical expected values: %s\n",
|
|
|
|
s.ToString().c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-06 01:12:12 +01:00
|
|
|
if ((FLAGS_sync_fault_injection || FLAGS_disable_wal) && IsStateTracked()) {
|
2021-12-07 22:40:46 +01:00
|
|
|
Status s = shared->SaveAtAndAfter(db_);
|
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "Error enabling history tracing: %s\n",
|
|
|
|
s.ToString().c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2021-12-18 07:04:05 +01:00
|
|
|
|
|
|
|
if (FLAGS_enable_compaction_filter) {
|
|
|
|
auto* compaction_filter_factory =
|
|
|
|
reinterpret_cast<DbStressCompactionFilterFactory*>(
|
|
|
|
options_.compaction_filter_factory.get());
|
|
|
|
assert(compaction_filter_factory);
|
|
|
|
// This must be called only after any potential `SharedState::Restore()` has
|
|
|
|
// completed in order for the `compaction_filter_factory` to operate on the
|
|
|
|
// correct latest values file.
|
|
|
|
compaction_filter_factory->SetSharedState(shared);
|
|
|
|
fprintf(stdout, "Compaction filter factory: %s\n",
|
|
|
|
compaction_filter_factory->Name());
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StressTest::VerifySecondaries() {
|
|
|
|
#ifndef ROCKSDB_LITE
|
2019-12-20 17:46:52 +01:00
|
|
|
if (FLAGS_test_secondary) {
|
2021-03-15 12:32:24 +01:00
|
|
|
uint64_t now = clock_->NowMicros();
|
|
|
|
fprintf(stdout, "%s Start to verify secondaries against primary\n",
|
|
|
|
clock_->TimeToString(static_cast<uint64_t>(now) / 1000000).c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
for (size_t k = 0; k != secondaries_.size(); ++k) {
|
|
|
|
Status s = secondaries_[k]->TryCatchUpWithPrimary();
|
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "Secondary failed to catch up with primary\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ReadOptions ropts;
|
|
|
|
ropts.total_order_seek = true;
|
|
|
|
// Verify only the default column family since the primary may have
|
|
|
|
// dropped other column families after most recent reopen.
|
|
|
|
std::unique_ptr<Iterator> iter1(db_->NewIterator(ropts));
|
|
|
|
std::unique_ptr<Iterator> iter2(secondaries_[k]->NewIterator(ropts));
|
|
|
|
for (iter1->SeekToFirst(), iter2->SeekToFirst();
|
|
|
|
iter1->Valid() && iter2->Valid(); iter1->Next(), iter2->Next()) {
|
|
|
|
if (iter1->key().compare(iter2->key()) != 0 ||
|
|
|
|
iter1->value().compare(iter2->value())) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Secondary %d contains different data from "
|
|
|
|
"primary.\nPrimary: %s : %s\nSecondary: %s : %s\n",
|
|
|
|
static_cast<int>(k),
|
|
|
|
iter1->key().ToString(/*hex=*/true).c_str(),
|
|
|
|
iter1->value().ToString(/*hex=*/true).c_str(),
|
|
|
|
iter2->key().ToString(/*hex=*/true).c_str(),
|
|
|
|
iter2->value().ToString(/*hex=*/true).c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (iter1->Valid() && !iter2->Valid()) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Secondary %d record count is smaller than that of primary\n",
|
|
|
|
static_cast<int>(k));
|
|
|
|
return false;
|
|
|
|
} else if (!iter1->Valid() && iter2->Valid()) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Secondary %d record count is larger than that of primary\n",
|
|
|
|
static_cast<int>(k));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-12-20 17:46:52 +01:00
|
|
|
if (FLAGS_test_secondary) {
|
2021-03-15 12:32:24 +01:00
|
|
|
uint64_t now = clock_->NowMicros();
|
|
|
|
fprintf(stdout, "%s Verification of secondaries succeeded\n",
|
|
|
|
clock_->TimeToString(static_cast<uint64_t>(now) / 1000000).c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status StressTest::AssertSame(DB* db, ColumnFamilyHandle* cf,
|
|
|
|
ThreadState::SnapshotState& snap_state) {
|
|
|
|
Status s;
|
|
|
|
if (cf->GetName() != snap_state.cf_at_name) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
ReadOptions ropt;
|
|
|
|
ropt.snapshot = snap_state.snapshot;
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
Slice ts;
|
|
|
|
if (!snap_state.timestamp.empty()) {
|
|
|
|
ts = snap_state.timestamp;
|
|
|
|
ropt.timestamp = &ts;
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
PinnableSlice exp_v(&snap_state.value);
|
|
|
|
exp_v.PinSelf();
|
|
|
|
PinnableSlice v;
|
|
|
|
s = db->Get(ropt, cf, snap_state.key, &v);
|
|
|
|
if (!s.ok() && !s.IsNotFound()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
if (snap_state.status != s) {
|
|
|
|
return Status::Corruption(
|
|
|
|
"The snapshot gave inconsistent results for key " +
|
|
|
|
ToString(Hash(snap_state.key.c_str(), snap_state.key.size(), 0)) +
|
|
|
|
" in cf " + cf->GetName() + ": (" + snap_state.status.ToString() +
|
|
|
|
") vs. (" + s.ToString() + ")");
|
|
|
|
}
|
|
|
|
if (s.ok()) {
|
|
|
|
if (exp_v != v) {
|
|
|
|
return Status::Corruption("The snapshot gave inconsistent values: (" +
|
|
|
|
exp_v.ToString() + ") vs. (" + v.ToString() +
|
|
|
|
")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (snap_state.key_vec != nullptr) {
|
|
|
|
// When `prefix_extractor` is set, seeking to beginning and scanning
|
|
|
|
// across prefixes are only supported with `total_order_seek` set.
|
|
|
|
ropt.total_order_seek = true;
|
|
|
|
std::unique_ptr<Iterator> iterator(db->NewIterator(ropt));
|
|
|
|
std::unique_ptr<std::vector<bool>> tmp_bitvec(
|
|
|
|
new std::vector<bool>(FLAGS_max_key));
|
|
|
|
for (iterator->SeekToFirst(); iterator->Valid(); iterator->Next()) {
|
|
|
|
uint64_t key_val;
|
|
|
|
if (GetIntVal(iterator->key().ToString(), &key_val)) {
|
|
|
|
(*tmp_bitvec.get())[key_val] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!std::equal(snap_state.key_vec->begin(), snap_state.key_vec->end(),
|
|
|
|
tmp_bitvec.get()->begin())) {
|
|
|
|
return Status::Corruption("Found inconsistent keys at this snapshot");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StressTest::VerificationAbort(SharedState* shared, std::string msg,
|
|
|
|
Status s) const {
|
2019-12-20 17:46:52 +01:00
|
|
|
fprintf(stderr, "Verification failed: %s. Status is %s\n", msg.c_str(),
|
|
|
|
s.ToString().c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StressTest::VerificationAbort(SharedState* shared, std::string msg, int cf,
|
|
|
|
int64_t key) const {
|
2020-10-13 21:37:07 +02:00
|
|
|
auto key_str = Key(key);
|
|
|
|
Slice key_slice = key_str;
|
2019-12-20 17:46:52 +01:00
|
|
|
fprintf(stderr,
|
2020-10-13 21:37:07 +02:00
|
|
|
"Verification failed for column family %d key %s (%" PRIi64 "): %s\n",
|
|
|
|
cf, key_slice.ToString(true).c_str(), key, msg.c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StressTest::PrintStatistics() {
|
|
|
|
if (dbstats) {
|
|
|
|
fprintf(stdout, "STATISTICS:\n%s\n", dbstats->ToString().c_str());
|
|
|
|
}
|
|
|
|
if (dbstats_secondaries) {
|
|
|
|
fprintf(stdout, "Secondary instances STATISTICS:\n%s\n",
|
|
|
|
dbstats_secondaries->ToString().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Currently PreloadDb has to be single-threaded.
|
|
|
|
void StressTest::PreloadDbAndReopenAsReadOnly(int64_t number_of_keys,
|
|
|
|
SharedState* shared) {
|
|
|
|
WriteOptions write_opts;
|
|
|
|
write_opts.disableWAL = FLAGS_disable_wal;
|
|
|
|
if (FLAGS_sync) {
|
|
|
|
write_opts.sync = true;
|
|
|
|
}
|
|
|
|
char value[100];
|
|
|
|
int cf_idx = 0;
|
|
|
|
Status s;
|
|
|
|
for (auto cfh : column_families_) {
|
|
|
|
for (int64_t k = 0; k != number_of_keys; ++k) {
|
|
|
|
std::string key_str = Key(k);
|
|
|
|
Slice key = key_str;
|
|
|
|
size_t sz = GenerateValue(0 /*value_base*/, value, sizeof(value));
|
|
|
|
Slice v(value, sz);
|
|
|
|
shared->Put(cf_idx, k, 0, true /* pending */);
|
|
|
|
|
|
|
|
if (FLAGS_use_merge) {
|
|
|
|
if (!FLAGS_use_txn) {
|
|
|
|
s = db_->Merge(write_opts, cfh, key, v);
|
|
|
|
} else {
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
Transaction* txn;
|
|
|
|
s = NewTxn(write_opts, &txn);
|
|
|
|
if (s.ok()) {
|
|
|
|
s = txn->Merge(cfh, key, v);
|
|
|
|
if (s.ok()) {
|
|
|
|
s = CommitTxn(txn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!FLAGS_use_txn) {
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
std::string ts_str;
|
|
|
|
Slice ts;
|
|
|
|
if (FLAGS_user_timestamp_size > 0) {
|
|
|
|
ts_str = NowNanosStr();
|
|
|
|
ts = ts_str;
|
|
|
|
write_opts.timestamp = &ts;
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
s = db_->Put(write_opts, cfh, key, v);
|
|
|
|
} else {
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
Transaction* txn;
|
|
|
|
s = NewTxn(write_opts, &txn);
|
|
|
|
if (s.ok()) {
|
|
|
|
s = txn->Put(cfh, key, v);
|
|
|
|
if (s.ok()) {
|
|
|
|
s = CommitTxn(txn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shared->Put(cf_idx, k, 0, false /* pending */);
|
|
|
|
if (!s.ok()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!s.ok()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++cf_idx;
|
|
|
|
}
|
|
|
|
if (s.ok()) {
|
|
|
|
s = db_->Flush(FlushOptions(), column_families_);
|
|
|
|
}
|
|
|
|
if (s.ok()) {
|
|
|
|
for (auto cf : column_families_) {
|
|
|
|
delete cf;
|
|
|
|
}
|
|
|
|
column_families_.clear();
|
|
|
|
delete db_;
|
|
|
|
db_ = nullptr;
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
txn_db_ = nullptr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
db_preload_finished_.store(true);
|
2021-03-15 12:32:24 +01:00
|
|
|
auto now = clock_->NowMicros();
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, "%s Reopening database in read-only\n",
|
2021-03-15 12:32:24 +01:00
|
|
|
clock_->TimeToString(now / 1000000).c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
// Reopen as read-only, can ignore all options related to updates
|
|
|
|
Open();
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Failed to preload db");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status StressTest::SetOptions(ThreadState* thread) {
|
|
|
|
assert(FLAGS_set_options_one_in > 0);
|
|
|
|
std::unordered_map<std::string, std::string> opts;
|
|
|
|
std::string name =
|
|
|
|
options_index_[thread->rand.Next() % options_index_.size()];
|
|
|
|
int value_idx = thread->rand.Next() % options_table_[name].size();
|
|
|
|
if (name == "soft_rate_limit" || name == "hard_rate_limit") {
|
|
|
|
opts["soft_rate_limit"] = options_table_["soft_rate_limit"][value_idx];
|
|
|
|
opts["hard_rate_limit"] = options_table_["hard_rate_limit"][value_idx];
|
|
|
|
} else if (name == "level0_file_num_compaction_trigger" ||
|
|
|
|
name == "level0_slowdown_writes_trigger" ||
|
|
|
|
name == "level0_stop_writes_trigger") {
|
|
|
|
opts["level0_file_num_compaction_trigger"] =
|
|
|
|
options_table_["level0_file_num_compaction_trigger"][value_idx];
|
|
|
|
opts["level0_slowdown_writes_trigger"] =
|
|
|
|
options_table_["level0_slowdown_writes_trigger"][value_idx];
|
|
|
|
opts["level0_stop_writes_trigger"] =
|
|
|
|
options_table_["level0_stop_writes_trigger"][value_idx];
|
|
|
|
} else {
|
|
|
|
opts[name] = options_table_[name][value_idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
int rand_cf_idx = thread->rand.Next() % FLAGS_column_families;
|
|
|
|
auto cfh = column_families_[rand_cf_idx];
|
|
|
|
return db_->SetOptions(cfh, opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
Status StressTest::NewTxn(WriteOptions& write_opts, Transaction** txn) {
|
|
|
|
if (!FLAGS_use_txn) {
|
|
|
|
return Status::InvalidArgument("NewTxn when FLAGS_use_txn is not set");
|
|
|
|
}
|
|
|
|
static std::atomic<uint64_t> txn_id = {0};
|
|
|
|
TransactionOptions txn_options;
|
2020-12-31 05:29:56 +01:00
|
|
|
txn_options.lock_timeout = 600000; // 10 min
|
2020-06-30 23:26:37 +02:00
|
|
|
txn_options.deadlock_detect = true;
|
2019-12-09 08:49:32 +01:00
|
|
|
*txn = txn_db_->BeginTransaction(write_opts, txn_options);
|
|
|
|
auto istr = std::to_string(txn_id.fetch_add(1));
|
|
|
|
Status s = (*txn)->SetName("xid" + istr);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status StressTest::CommitTxn(Transaction* txn) {
|
|
|
|
if (!FLAGS_use_txn) {
|
|
|
|
return Status::InvalidArgument("CommitTxn when FLAGS_use_txn is not set");
|
|
|
|
}
|
|
|
|
Status s = txn->Prepare();
|
|
|
|
if (s.ok()) {
|
|
|
|
s = txn->Commit();
|
|
|
|
}
|
|
|
|
delete txn;
|
|
|
|
return s;
|
|
|
|
}
|
2019-12-21 08:10:58 +01:00
|
|
|
|
|
|
|
Status StressTest::RollbackTxn(Transaction* txn) {
|
|
|
|
if (!FLAGS_use_txn) {
|
|
|
|
return Status::InvalidArgument(
|
|
|
|
"RollbackTxn when FLAGS_use_txn is not"
|
|
|
|
" set");
|
|
|
|
}
|
|
|
|
Status s = txn->Rollback();
|
|
|
|
delete txn;
|
|
|
|
return s;
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void StressTest::OperateDb(ThreadState* thread) {
|
|
|
|
ReadOptions read_opts(FLAGS_verify_checksum, true);
|
|
|
|
WriteOptions write_opts;
|
|
|
|
auto shared = thread->shared;
|
|
|
|
char value[100];
|
|
|
|
std::string from_db;
|
|
|
|
if (FLAGS_sync) {
|
|
|
|
write_opts.sync = true;
|
|
|
|
}
|
|
|
|
write_opts.disableWAL = FLAGS_disable_wal;
|
2021-12-14 22:33:16 +01:00
|
|
|
const int prefix_bound = static_cast<int>(FLAGS_readpercent) +
|
|
|
|
static_cast<int>(FLAGS_prefixpercent);
|
|
|
|
const int write_bound = prefix_bound + static_cast<int>(FLAGS_writepercent);
|
|
|
|
const int del_bound = write_bound + static_cast<int>(FLAGS_delpercent);
|
|
|
|
const int delrange_bound =
|
|
|
|
del_bound + static_cast<int>(FLAGS_delrangepercent);
|
|
|
|
const int iterate_bound =
|
|
|
|
delrange_bound + static_cast<int>(FLAGS_iterpercent);
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
const uint64_t ops_per_open = FLAGS_ops_per_thread / (FLAGS_reopen + 1);
|
|
|
|
|
2020-04-11 02:18:56 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
if (FLAGS_read_fault_one_in) {
|
|
|
|
fault_fs_guard->SetThreadLocalReadErrorContext(thread->shared->GetSeed(),
|
|
|
|
FLAGS_read_fault_one_in);
|
|
|
|
}
|
2020-12-17 20:51:04 +01:00
|
|
|
if (FLAGS_write_fault_one_in) {
|
2021-07-01 23:15:49 +02:00
|
|
|
IOStatus error_msg;
|
|
|
|
if (FLAGS_injest_error_severity <= 1 || FLAGS_injest_error_severity > 2) {
|
|
|
|
error_msg = IOStatus::IOError("Retryable IO Error");
|
|
|
|
error_msg.SetRetryable(true);
|
|
|
|
} else if (FLAGS_injest_error_severity == 2) {
|
|
|
|
// Ingest the fatal error
|
|
|
|
error_msg = IOStatus::IOError("Fatal IO Error");
|
|
|
|
error_msg.SetDataLoss(true);
|
|
|
|
}
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
std::vector<FileType> types = {FileType::kTableFile,
|
|
|
|
FileType::kDescriptorFile,
|
|
|
|
FileType::kCurrentFile};
|
2020-12-17 20:51:04 +01:00
|
|
|
fault_fs_guard->SetRandomWriteError(
|
2021-07-01 01:45:44 +02:00
|
|
|
thread->shared->GetSeed(), FLAGS_write_fault_one_in, error_msg,
|
|
|
|
/*inject_for_all_file_types=*/false, types);
|
2020-12-17 20:51:04 +01:00
|
|
|
}
|
2020-04-11 02:18:56 +02:00
|
|
|
#endif // NDEBUG
|
2019-12-09 08:49:32 +01:00
|
|
|
thread->stats.Start();
|
|
|
|
for (int open_cnt = 0; open_cnt <= FLAGS_reopen; ++open_cnt) {
|
2019-12-20 17:46:52 +01:00
|
|
|
if (thread->shared->HasVerificationFailedYet() ||
|
|
|
|
thread->shared->ShouldStopTest()) {
|
2019-12-09 08:49:32 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (open_cnt != 0) {
|
|
|
|
thread->stats.FinishedSingleOp();
|
|
|
|
MutexLock l(thread->shared->GetMutex());
|
|
|
|
while (!thread->snapshot_queue.empty()) {
|
|
|
|
db_->ReleaseSnapshot(thread->snapshot_queue.front().second.snapshot);
|
|
|
|
delete thread->snapshot_queue.front().second.key_vec;
|
|
|
|
thread->snapshot_queue.pop();
|
|
|
|
}
|
|
|
|
thread->shared->IncVotedReopen();
|
|
|
|
if (thread->shared->AllVotedReopen()) {
|
2019-12-11 05:01:25 +01:00
|
|
|
thread->shared->GetStressTest()->Reopen(thread);
|
2019-12-09 08:49:32 +01:00
|
|
|
thread->shared->GetCondVar()->SignalAll();
|
|
|
|
} else {
|
|
|
|
thread->shared->GetCondVar()->Wait();
|
|
|
|
}
|
|
|
|
// Commenting this out as we don't want to reset stats on each open.
|
|
|
|
// thread->stats.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint64_t i = 0; i < ops_per_open; i++) {
|
|
|
|
if (thread->shared->HasVerificationFailedYet()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change Options
|
2019-12-13 22:25:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_set_options_one_in)) {
|
2019-12-09 08:49:32 +01:00
|
|
|
SetOptions(thread);
|
|
|
|
}
|
|
|
|
|
2019-12-13 22:25:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_set_in_place_one_in)) {
|
2019-12-09 08:49:32 +01:00
|
|
|
options_.inplace_update_support ^= options_.inplace_update_support;
|
|
|
|
}
|
|
|
|
|
2019-12-20 17:46:52 +01:00
|
|
|
if (thread->tid == 0 && FLAGS_verify_db_one_in > 0 &&
|
|
|
|
thread->rand.OneIn(FLAGS_verify_db_one_in)) {
|
|
|
|
ContinuouslyVerifyDb(thread);
|
|
|
|
if (thread->shared->ShouldStopTest()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
MaybeClearOneColumnFamily(thread);
|
|
|
|
|
2019-12-13 22:25:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_sync_wal_one_in)) {
|
2019-12-11 06:53:43 +01:00
|
|
|
Status s = db_->SyncWAL();
|
|
|
|
if (!s.ok() && !s.IsNotSupported()) {
|
2019-12-20 17:46:52 +01:00
|
|
|
fprintf(stderr, "SyncWAL() failed: %s\n", s.ToString().c_str());
|
2019-12-11 06:53:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:03:14 +01:00
|
|
|
int rand_column_family = thread->rand.Next() % FLAGS_column_families;
|
|
|
|
ColumnFamilyHandle* column_family = column_families_[rand_column_family];
|
2019-12-09 08:49:32 +01:00
|
|
|
|
2019-12-19 23:03:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_compact_files_one_in)) {
|
|
|
|
TestCompactFiles(thread, column_family);
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
2019-12-19 23:03:14 +01:00
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
int64_t rand_key = GenerateOneKey(thread, i);
|
|
|
|
std::string keystr = Key(rand_key);
|
|
|
|
Slice key = keystr;
|
|
|
|
std::unique_ptr<MutexLock> lock;
|
|
|
|
if (ShouldAcquireMutexOnKey()) {
|
|
|
|
lock.reset(new MutexLock(
|
|
|
|
shared->GetMutexForKey(rand_column_family, rand_key)));
|
|
|
|
}
|
|
|
|
|
2019-12-13 22:25:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_compact_range_one_in)) {
|
2019-12-10 20:40:09 +01:00
|
|
|
TestCompactRange(thread, rand_key, key, column_family);
|
|
|
|
if (thread->shared->HasVerificationFailedYet()) {
|
|
|
|
break;
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> rand_column_families =
|
|
|
|
GenerateColumnFamilies(FLAGS_column_families, rand_column_family);
|
|
|
|
|
2019-12-13 22:25:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_flush_one_in)) {
|
2019-12-19 23:03:14 +01:00
|
|
|
Status status = TestFlush(rand_column_families);
|
2019-12-09 08:49:32 +01:00
|
|
|
if (!status.ok()) {
|
|
|
|
fprintf(stdout, "Unable to perform Flush(): %s\n",
|
|
|
|
status.ToString().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-20 21:05:48 +01:00
|
|
|
#ifndef ROCKSDB_LITE
|
2020-03-19 01:11:06 +01:00
|
|
|
// Verify GetLiveFiles with a 1 in N chance.
|
2020-12-17 20:51:04 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_get_live_files_one_in) &&
|
|
|
|
!FLAGS_write_fault_one_in) {
|
2020-03-19 01:11:06 +01:00
|
|
|
Status status = VerifyGetLiveFiles();
|
2019-12-20 21:05:48 +01:00
|
|
|
if (!status.ok()) {
|
2020-03-19 01:11:06 +01:00
|
|
|
VerificationAbort(shared, "VerifyGetLiveFiles status not OK", status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify GetSortedWalFiles with a 1 in N chance.
|
|
|
|
if (thread->rand.OneInOpt(FLAGS_get_sorted_wal_files_one_in)) {
|
|
|
|
Status status = VerifyGetSortedWalFiles();
|
|
|
|
if (!status.ok()) {
|
|
|
|
VerificationAbort(shared, "VerifyGetSortedWalFiles status not OK",
|
|
|
|
status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify GetCurrentWalFile with a 1 in N chance.
|
|
|
|
if (thread->rand.OneInOpt(FLAGS_get_current_wal_file_one_in)) {
|
|
|
|
Status status = VerifyGetCurrentWalFile();
|
|
|
|
if (!status.ok()) {
|
|
|
|
VerificationAbort(shared, "VerifyGetCurrentWalFile status not OK",
|
2019-12-20 21:05:48 +01:00
|
|
|
status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
2019-12-13 22:25:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_pause_background_one_in)) {
|
2019-12-19 23:03:14 +01:00
|
|
|
Status status = TestPauseBackground(thread);
|
2019-12-11 00:45:25 +01:00
|
|
|
if (!status.ok()) {
|
2019-12-19 23:03:14 +01:00
|
|
|
VerificationAbort(
|
|
|
|
shared, "Pause/ContinueBackgroundWork status not OK", status);
|
2019-12-11 00:45:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-18 05:43:06 +01:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
if (thread->rand.OneInOpt(FLAGS_verify_checksum_one_in)) {
|
|
|
|
Status status = db_->VerifyChecksum();
|
|
|
|
if (!status.ok()) {
|
|
|
|
VerificationAbort(shared, "VerifyChecksum status not OK", status);
|
|
|
|
}
|
|
|
|
}
|
2020-07-14 21:10:56 +02:00
|
|
|
|
|
|
|
if (thread->rand.OneInOpt(FLAGS_get_property_one_in)) {
|
|
|
|
TestGetProperty(thread);
|
|
|
|
}
|
2019-12-18 05:43:06 +01:00
|
|
|
#endif
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
std::vector<int64_t> rand_keys = GenerateKeys(rand_key);
|
|
|
|
|
2019-12-13 22:25:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_ingest_external_file_one_in)) {
|
2019-12-09 08:49:32 +01:00
|
|
|
TestIngestExternalFile(thread, rand_column_families, rand_keys, lock);
|
|
|
|
}
|
|
|
|
|
2019-12-13 22:25:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_backup_one_in)) {
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
2020-09-04 05:11:45 +02:00
|
|
|
// Beyond a certain DB size threshold, this test becomes heavier than
|
|
|
|
// it's worth.
|
|
|
|
uint64_t total_size = 0;
|
|
|
|
if (FLAGS_backup_max_size > 0) {
|
|
|
|
std::vector<FileAttributes> files;
|
|
|
|
db_stress_env->GetChildrenFileAttributes(FLAGS_db, &files);
|
|
|
|
for (auto& file : files) {
|
|
|
|
total_size += file.size_bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (total_size <= FLAGS_backup_max_size) {
|
|
|
|
Status s = TestBackupRestore(thread, rand_column_families, rand_keys);
|
|
|
|
if (!s.ok()) {
|
|
|
|
VerificationAbort(shared, "Backup/restore gave inconsistent state",
|
|
|
|
s);
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-13 22:25:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_checkpoint_one_in)) {
|
2019-12-09 08:49:32 +01:00
|
|
|
Status s = TestCheckpoint(thread, rand_column_families, rand_keys);
|
|
|
|
if (!s.ok()) {
|
|
|
|
VerificationAbort(shared, "Checkpoint gave inconsistent state", s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-21 06:42:19 +01:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
if (thread->rand.OneInOpt(FLAGS_approximate_size_one_in)) {
|
|
|
|
Status s =
|
|
|
|
TestApproximateSize(thread, i, rand_column_families, rand_keys);
|
|
|
|
if (!s.ok()) {
|
|
|
|
VerificationAbort(shared, "ApproximateSize Failed", s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // !ROCKSDB_LITE
|
2019-12-13 22:25:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_acquire_snapshot_one_in)) {
|
2019-12-19 23:03:14 +01:00
|
|
|
TestAcquireSnapshot(thread, rand_column_family, keystr, i);
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
2019-12-19 23:03:14 +01:00
|
|
|
|
|
|
|
/*always*/ {
|
|
|
|
Status s = MaybeReleaseSnapshots(thread, i);
|
2019-12-09 08:49:32 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
VerificationAbort(shared, "Snapshot gave inconsistent state", s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
// Assign timestamps if necessary.
|
|
|
|
std::string read_ts_str;
|
|
|
|
std::string write_ts_str;
|
|
|
|
Slice read_ts;
|
|
|
|
Slice write_ts;
|
|
|
|
if (ShouldAcquireMutexOnKey() && FLAGS_user_timestamp_size > 0) {
|
|
|
|
read_ts_str = GenerateTimestampForRead();
|
|
|
|
read_ts = read_ts_str;
|
|
|
|
read_opts.timestamp = &read_ts;
|
|
|
|
write_ts_str = NowNanosStr();
|
|
|
|
write_ts = write_ts_str;
|
|
|
|
write_opts.timestamp = &write_ts;
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
int prob_op = thread->rand.Uniform(100);
|
|
|
|
// Reset this in case we pick something other than a read op. We don't
|
|
|
|
// want to use a stale value when deciding at the beginning of the loop
|
|
|
|
// whether to vote to reopen
|
2019-12-20 17:46:52 +01:00
|
|
|
if (prob_op >= 0 && prob_op < static_cast<int>(FLAGS_readpercent)) {
|
2019-12-13 22:25:14 +01:00
|
|
|
assert(0 <= prob_op);
|
2019-12-09 08:49:32 +01:00
|
|
|
// OPERATION read
|
|
|
|
if (FLAGS_use_multiget) {
|
|
|
|
// Leave room for one more iteration of the loop with a single key
|
|
|
|
// batch. This is to ensure that each thread does exactly the same
|
|
|
|
// number of ops
|
|
|
|
int multiget_batch_size = static_cast<int>(
|
|
|
|
std::min(static_cast<uint64_t>(thread->rand.Uniform(64)),
|
|
|
|
FLAGS_ops_per_thread - i - 1));
|
|
|
|
// If its the last iteration, ensure that multiget_batch_size is 1
|
|
|
|
multiget_batch_size = std::max(multiget_batch_size, 1);
|
|
|
|
rand_keys = GenerateNKeys(thread, multiget_batch_size, i);
|
|
|
|
TestMultiGet(thread, read_opts, rand_column_families, rand_keys);
|
|
|
|
i += multiget_batch_size - 1;
|
|
|
|
} else {
|
|
|
|
TestGet(thread, read_opts, rand_column_families, rand_keys);
|
|
|
|
}
|
2021-12-14 22:33:16 +01:00
|
|
|
} else if (prob_op < prefix_bound) {
|
2019-12-20 17:46:52 +01:00
|
|
|
assert(static_cast<int>(FLAGS_readpercent) <= prob_op);
|
2019-12-09 08:49:32 +01:00
|
|
|
// OPERATION prefix scan
|
|
|
|
// keys are 8 bytes long, prefix size is FLAGS_prefix_size. There are
|
|
|
|
// (8 - FLAGS_prefix_size) bytes besides the prefix. So there will
|
|
|
|
// be 2 ^ ((8 - FLAGS_prefix_size) * 8) possible keys with the same
|
|
|
|
// prefix
|
|
|
|
TestPrefixScan(thread, read_opts, rand_column_families, rand_keys);
|
2021-12-14 22:33:16 +01:00
|
|
|
} else if (prob_op < write_bound) {
|
|
|
|
assert(prefix_bound <= prob_op);
|
2019-12-09 08:49:32 +01:00
|
|
|
// OPERATION write
|
|
|
|
TestPut(thread, write_opts, read_opts, rand_column_families, rand_keys,
|
|
|
|
value, lock);
|
2021-12-14 22:33:16 +01:00
|
|
|
} else if (prob_op < del_bound) {
|
|
|
|
assert(write_bound <= prob_op);
|
2019-12-09 08:49:32 +01:00
|
|
|
// OPERATION delete
|
|
|
|
TestDelete(thread, write_opts, rand_column_families, rand_keys, lock);
|
2021-12-14 22:33:16 +01:00
|
|
|
} else if (prob_op < delrange_bound) {
|
|
|
|
assert(del_bound <= prob_op);
|
2019-12-09 08:49:32 +01:00
|
|
|
// OPERATION delete range
|
|
|
|
TestDeleteRange(thread, write_opts, rand_column_families, rand_keys,
|
|
|
|
lock);
|
2021-12-14 22:33:16 +01:00
|
|
|
} else if (prob_op < iterate_bound) {
|
|
|
|
assert(delrange_bound <= prob_op);
|
2019-12-09 08:49:32 +01:00
|
|
|
// OPERATION iterate
|
|
|
|
int num_seeks = static_cast<int>(
|
|
|
|
std::min(static_cast<uint64_t>(thread->rand.Uniform(4)),
|
|
|
|
FLAGS_ops_per_thread - i - 1));
|
|
|
|
rand_keys = GenerateNKeys(thread, num_seeks, i);
|
|
|
|
i += num_seeks - 1;
|
|
|
|
TestIterate(thread, read_opts, rand_column_families, rand_keys);
|
2021-12-14 22:33:16 +01:00
|
|
|
} else {
|
|
|
|
assert(iterate_bound <= prob_op);
|
|
|
|
TestCustomOperations(thread, rand_column_families);
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
thread->stats.FinishedSingleOp();
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
uint32_t tid = thread->tid;
|
|
|
|
assert(secondaries_.empty() ||
|
|
|
|
static_cast<size_t>(tid) < secondaries_.size());
|
2019-12-19 23:03:14 +01:00
|
|
|
if (thread->rand.OneInOpt(FLAGS_secondary_catch_up_one_in)) {
|
2019-12-09 08:49:32 +01:00
|
|
|
Status s = secondaries_[tid]->TryCatchUpWithPrimary();
|
|
|
|
if (!s.ok()) {
|
|
|
|
VerificationAbort(shared, "Secondary instance failed to catch up", s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!thread->snapshot_queue.empty()) {
|
|
|
|
db_->ReleaseSnapshot(thread->snapshot_queue.front().second.snapshot);
|
|
|
|
delete thread->snapshot_queue.front().second.key_vec;
|
|
|
|
thread->snapshot_queue.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
thread->stats.Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
// Generated a list of keys that close to boundaries of SST keys.
|
|
|
|
// If there isn't any SST file in the DB, return empty list.
|
|
|
|
std::vector<std::string> StressTest::GetWhiteBoxKeys(ThreadState* thread,
|
|
|
|
DB* db,
|
|
|
|
ColumnFamilyHandle* cfh,
|
|
|
|
size_t num_keys) {
|
|
|
|
ColumnFamilyMetaData cfmd;
|
|
|
|
db->GetColumnFamilyMetaData(cfh, &cfmd);
|
|
|
|
std::vector<std::string> boundaries;
|
|
|
|
for (const LevelMetaData& lmd : cfmd.levels) {
|
|
|
|
for (const SstFileMetaData& sfmd : lmd.files) {
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
// If FLAGS_user_timestamp_size > 0, then both smallestkey and largestkey
|
|
|
|
// have timestamps.
|
|
|
|
const auto& skey = sfmd.smallestkey;
|
|
|
|
const auto& lkey = sfmd.largestkey;
|
|
|
|
assert(skey.size() >= FLAGS_user_timestamp_size);
|
|
|
|
assert(lkey.size() >= FLAGS_user_timestamp_size);
|
|
|
|
boundaries.push_back(
|
|
|
|
skey.substr(0, skey.size() - FLAGS_user_timestamp_size));
|
|
|
|
boundaries.push_back(
|
|
|
|
lkey.substr(0, lkey.size() - FLAGS_user_timestamp_size));
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (boundaries.empty()) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> ret;
|
|
|
|
for (size_t j = 0; j < num_keys; j++) {
|
|
|
|
std::string k =
|
|
|
|
boundaries[thread->rand.Uniform(static_cast<int>(boundaries.size()))];
|
|
|
|
if (thread->rand.OneIn(3)) {
|
|
|
|
// Reduce one byte from the string
|
|
|
|
for (int i = static_cast<int>(k.length()) - 1; i >= 0; i--) {
|
|
|
|
uint8_t cur = k[i];
|
|
|
|
if (cur > 0) {
|
|
|
|
k[i] = static_cast<char>(cur - 1);
|
|
|
|
break;
|
|
|
|
} else if (i > 0) {
|
2020-01-31 01:05:44 +01:00
|
|
|
k[i] = 0xFFu;
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (thread->rand.OneIn(2)) {
|
|
|
|
// Add one byte to the string
|
|
|
|
for (int i = static_cast<int>(k.length()) - 1; i >= 0; i--) {
|
|
|
|
uint8_t cur = k[i];
|
|
|
|
if (cur < 255) {
|
|
|
|
k[i] = static_cast<char>(cur + 1);
|
|
|
|
break;
|
|
|
|
} else if (i > 0) {
|
|
|
|
k[i] = 0x00;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret.push_back(k);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
|
|
|
// Given a key K, this creates an iterator which scans to K and then
|
|
|
|
// does a random sequence of Next/Prev operations.
|
|
|
|
Status StressTest::TestIterate(ThreadState* thread,
|
|
|
|
const ReadOptions& read_opts,
|
|
|
|
const std::vector<int>& rand_column_families,
|
|
|
|
const std::vector<int64_t>& rand_keys) {
|
|
|
|
Status s;
|
|
|
|
const Snapshot* snapshot = db_->GetSnapshot();
|
|
|
|
ReadOptions readoptionscopy = read_opts;
|
|
|
|
readoptionscopy.snapshot = snapshot;
|
|
|
|
|
2020-01-28 23:42:21 +01:00
|
|
|
bool expect_total_order = false;
|
2019-12-09 08:49:32 +01:00
|
|
|
if (thread->rand.OneIn(16)) {
|
|
|
|
// When prefix extractor is used, it's useful to cover total order seek.
|
|
|
|
readoptionscopy.total_order_seek = true;
|
2020-01-28 23:42:21 +01:00
|
|
|
expect_total_order = true;
|
|
|
|
} else if (thread->rand.OneIn(4)) {
|
|
|
|
readoptionscopy.total_order_seek = false;
|
|
|
|
readoptionscopy.auto_prefix_mode = true;
|
|
|
|
expect_total_order = true;
|
|
|
|
} else if (options_.prefix_extractor.get() == nullptr) {
|
|
|
|
expect_total_order = true;
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string upper_bound_str;
|
|
|
|
Slice upper_bound;
|
|
|
|
if (thread->rand.OneIn(16)) {
|
|
|
|
// in 1/16 chance, set a iterator upper bound
|
|
|
|
int64_t rand_upper_key = GenerateOneKey(thread, FLAGS_ops_per_thread);
|
|
|
|
upper_bound_str = Key(rand_upper_key);
|
|
|
|
upper_bound = Slice(upper_bound_str);
|
|
|
|
// uppder_bound can be smaller than seek key, but the query itself
|
|
|
|
// should not crash either.
|
|
|
|
readoptionscopy.iterate_upper_bound = &upper_bound;
|
|
|
|
}
|
|
|
|
std::string lower_bound_str;
|
|
|
|
Slice lower_bound;
|
|
|
|
if (thread->rand.OneIn(16)) {
|
|
|
|
// in 1/16 chance, enable iterator lower bound
|
|
|
|
int64_t rand_lower_key = GenerateOneKey(thread, FLAGS_ops_per_thread);
|
|
|
|
lower_bound_str = Key(rand_lower_key);
|
|
|
|
lower_bound = Slice(lower_bound_str);
|
|
|
|
// uppder_bound can be smaller than seek key, but the query itself
|
|
|
|
// should not crash either.
|
|
|
|
readoptionscopy.iterate_lower_bound = &lower_bound;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto cfh = column_families_[rand_column_families[0]];
|
|
|
|
std::unique_ptr<Iterator> iter(db_->NewIterator(readoptionscopy, cfh));
|
|
|
|
|
|
|
|
std::vector<std::string> key_str;
|
|
|
|
if (thread->rand.OneIn(16)) {
|
|
|
|
// Generate keys close to lower or upper bound of SST files.
|
|
|
|
key_str = GetWhiteBoxKeys(thread, db_, cfh, rand_keys.size());
|
|
|
|
}
|
|
|
|
if (key_str.empty()) {
|
|
|
|
// If key string is not geneerated using white block keys,
|
|
|
|
// Use randomized key passe in.
|
|
|
|
for (int64_t rkey : rand_keys) {
|
|
|
|
key_str.push_back(Key(rkey));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-20 23:54:30 +01:00
|
|
|
std::string op_logs;
|
|
|
|
const size_t kOpLogsLimit = 10000;
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
for (const std::string& skey : key_str) {
|
2019-12-20 23:54:30 +01:00
|
|
|
if (op_logs.size() > kOpLogsLimit) {
|
|
|
|
// Shouldn't take too much memory for the history log. Clear it.
|
|
|
|
op_logs = "(cleared...)\n";
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
Slice key = skey;
|
|
|
|
|
|
|
|
if (readoptionscopy.iterate_upper_bound != nullptr &&
|
|
|
|
thread->rand.OneIn(2)) {
|
|
|
|
// 1/2 chance, change the upper bound.
|
|
|
|
// It is possible that it is changed without first use, but there is no
|
|
|
|
// problem with that.
|
|
|
|
int64_t rand_upper_key = GenerateOneKey(thread, FLAGS_ops_per_thread);
|
|
|
|
upper_bound_str = Key(rand_upper_key);
|
|
|
|
upper_bound = Slice(upper_bound_str);
|
2019-12-20 23:54:30 +01:00
|
|
|
} else if (readoptionscopy.iterate_lower_bound != nullptr &&
|
|
|
|
thread->rand.OneIn(4)) {
|
|
|
|
// 1/4 chance, change the lower bound.
|
|
|
|
// It is possible that it is changed without first use, but there is no
|
|
|
|
// problem with that.
|
|
|
|
int64_t rand_lower_key = GenerateOneKey(thread, FLAGS_ops_per_thread);
|
|
|
|
lower_bound_str = Key(rand_lower_key);
|
|
|
|
lower_bound = Slice(lower_bound_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record some options to op_logs;
|
|
|
|
op_logs += "total_order_seek: ";
|
|
|
|
op_logs += (readoptionscopy.total_order_seek ? "1 " : "0 ");
|
2020-01-28 23:42:21 +01:00
|
|
|
op_logs += "auto_prefix_mode: ";
|
|
|
|
op_logs += (readoptionscopy.auto_prefix_mode ? "1 " : "0 ");
|
2019-12-20 23:54:30 +01:00
|
|
|
if (readoptionscopy.iterate_upper_bound != nullptr) {
|
|
|
|
op_logs += "ub: " + upper_bound.ToString(true) + " ";
|
|
|
|
}
|
|
|
|
if (readoptionscopy.iterate_lower_bound != nullptr) {
|
|
|
|
op_logs += "lb: " + lower_bound.ToString(true) + " ";
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set up an iterator and does the same without bounds and with total
|
|
|
|
// order seek and compare the results. This is to identify bugs related
|
|
|
|
// to bounds, prefix extractor or reseeking. Sometimes we are comparing
|
|
|
|
// iterators with the same set-up, and it doesn't hurt to check them
|
|
|
|
// to be equal.
|
|
|
|
ReadOptions cmp_ro;
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
cmp_ro.timestamp = readoptionscopy.timestamp;
|
2019-12-09 08:49:32 +01:00
|
|
|
cmp_ro.snapshot = snapshot;
|
|
|
|
cmp_ro.total_order_seek = true;
|
|
|
|
ColumnFamilyHandle* cmp_cfh =
|
|
|
|
GetControlCfh(thread, rand_column_families[0]);
|
|
|
|
std::unique_ptr<Iterator> cmp_iter(db_->NewIterator(cmp_ro, cmp_cfh));
|
|
|
|
bool diverged = false;
|
|
|
|
|
2020-01-28 23:42:21 +01:00
|
|
|
bool support_seek_first_or_last = expect_total_order;
|
2019-12-20 23:54:30 +01:00
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
LastIterateOp last_op;
|
2019-12-20 23:54:30 +01:00
|
|
|
if (support_seek_first_or_last && thread->rand.OneIn(100)) {
|
|
|
|
iter->SeekToFirst();
|
|
|
|
cmp_iter->SeekToFirst();
|
|
|
|
last_op = kLastOpSeekToFirst;
|
|
|
|
op_logs += "STF ";
|
|
|
|
} else if (support_seek_first_or_last && thread->rand.OneIn(100)) {
|
|
|
|
iter->SeekToLast();
|
|
|
|
cmp_iter->SeekToLast();
|
|
|
|
last_op = kLastOpSeekToLast;
|
|
|
|
op_logs += "STL ";
|
|
|
|
} else if (thread->rand.OneIn(8)) {
|
2019-12-09 08:49:32 +01:00
|
|
|
iter->SeekForPrev(key);
|
|
|
|
cmp_iter->SeekForPrev(key);
|
|
|
|
last_op = kLastOpSeekForPrev;
|
2019-12-20 23:54:30 +01:00
|
|
|
op_logs += "SFP " + key.ToString(true) + " ";
|
2019-12-09 08:49:32 +01:00
|
|
|
} else {
|
|
|
|
iter->Seek(key);
|
|
|
|
cmp_iter->Seek(key);
|
|
|
|
last_op = kLastOpSeek;
|
2019-12-20 23:54:30 +01:00
|
|
|
op_logs += "S " + key.ToString(true) + " ";
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
VerifyIterator(thread, cmp_cfh, readoptionscopy, iter.get(), cmp_iter.get(),
|
2019-12-20 23:54:30 +01:00
|
|
|
last_op, key, op_logs, &diverged);
|
2019-12-09 08:49:32 +01:00
|
|
|
|
|
|
|
bool no_reverse =
|
2020-01-28 23:42:21 +01:00
|
|
|
(FLAGS_memtablerep == "prefix_hash" && !expect_total_order);
|
2019-12-09 08:49:32 +01:00
|
|
|
for (uint64_t i = 0; i < FLAGS_num_iterations && iter->Valid(); i++) {
|
|
|
|
if (no_reverse || thread->rand.OneIn(2)) {
|
|
|
|
iter->Next();
|
|
|
|
if (!diverged) {
|
|
|
|
assert(cmp_iter->Valid());
|
|
|
|
cmp_iter->Next();
|
|
|
|
}
|
2019-12-20 23:54:30 +01:00
|
|
|
op_logs += "N";
|
2019-12-09 08:49:32 +01:00
|
|
|
} else {
|
|
|
|
iter->Prev();
|
|
|
|
if (!diverged) {
|
|
|
|
assert(cmp_iter->Valid());
|
|
|
|
cmp_iter->Prev();
|
|
|
|
}
|
2019-12-20 23:54:30 +01:00
|
|
|
op_logs += "P";
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
last_op = kLastOpNextOrPrev;
|
|
|
|
VerifyIterator(thread, cmp_cfh, readoptionscopy, iter.get(),
|
2019-12-20 23:54:30 +01:00
|
|
|
cmp_iter.get(), last_op, key, op_logs, &diverged);
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
thread->stats.AddIterations(1);
|
|
|
|
} else {
|
2020-01-03 01:43:55 +01:00
|
|
|
fprintf(stderr, "TestIterate error: %s\n", s.ToString().c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
break;
|
|
|
|
}
|
2019-12-20 23:54:30 +01:00
|
|
|
|
|
|
|
op_logs += "; ";
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
db_->ReleaseSnapshot(snapshot);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-12-20 21:05:48 +01:00
|
|
|
#ifndef ROCKSDB_LITE
|
2020-03-19 01:11:06 +01:00
|
|
|
// Test the return status of GetLiveFiles.
|
|
|
|
Status StressTest::VerifyGetLiveFiles() const {
|
|
|
|
std::vector<std::string> live_file;
|
|
|
|
uint64_t manifest_size = 0;
|
|
|
|
return db_->GetLiveFiles(live_file, &manifest_size);
|
|
|
|
}
|
2019-12-20 21:05:48 +01:00
|
|
|
|
2020-03-19 01:11:06 +01:00
|
|
|
// Test the return status of GetSortedWalFiles.
|
|
|
|
Status StressTest::VerifyGetSortedWalFiles() const {
|
|
|
|
VectorLogPtr log_ptr;
|
|
|
|
return db_->GetSortedWalFiles(log_ptr);
|
|
|
|
}
|
2019-12-20 21:05:48 +01:00
|
|
|
|
2020-03-19 01:11:06 +01:00
|
|
|
// Test the return status of GetCurrentWalFile.
|
|
|
|
Status StressTest::VerifyGetCurrentWalFile() const {
|
|
|
|
std::unique_ptr<LogFile> cur_wal_file;
|
|
|
|
return db_->GetCurrentWalFile(&cur_wal_file);
|
2019-12-20 21:05:48 +01:00
|
|
|
}
|
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
// Compare the two iterator, iter and cmp_iter are in the same position,
|
|
|
|
// unless iter might be made invalidate or undefined because of
|
|
|
|
// upper or lower bounds, or prefix extractor.
|
|
|
|
// Will flag failure if the verification fails.
|
|
|
|
// diverged = true if the two iterator is already diverged.
|
|
|
|
// True if verification passed, false if not.
|
|
|
|
void StressTest::VerifyIterator(ThreadState* thread,
|
|
|
|
ColumnFamilyHandle* cmp_cfh,
|
|
|
|
const ReadOptions& ro, Iterator* iter,
|
|
|
|
Iterator* cmp_iter, LastIterateOp op,
|
2019-12-20 23:54:30 +01:00
|
|
|
const Slice& seek_key,
|
|
|
|
const std::string& op_logs, bool* diverged) {
|
2019-12-09 08:49:32 +01:00
|
|
|
if (*diverged) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-20 23:54:30 +01:00
|
|
|
if (op == kLastOpSeekToFirst && ro.iterate_lower_bound != nullptr) {
|
|
|
|
// SeekToFirst() with lower bound is not well defined.
|
|
|
|
*diverged = true;
|
|
|
|
return;
|
|
|
|
} else if (op == kLastOpSeekToLast && ro.iterate_upper_bound != nullptr) {
|
|
|
|
// SeekToLast() with higher bound is not well defined.
|
|
|
|
*diverged = true;
|
|
|
|
return;
|
|
|
|
} else if (op == kLastOpSeek && ro.iterate_lower_bound != nullptr &&
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
(options_.comparator->CompareWithoutTimestamp(
|
|
|
|
*ro.iterate_lower_bound, /*a_has_ts=*/false, seek_key,
|
|
|
|
/*b_has_ts=*/false) >= 0 ||
|
2019-12-20 23:54:30 +01:00
|
|
|
(ro.iterate_upper_bound != nullptr &&
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
options_.comparator->CompareWithoutTimestamp(
|
|
|
|
*ro.iterate_lower_bound, /*a_has_ts=*/false,
|
|
|
|
*ro.iterate_upper_bound, /*b_has_ts*/ false) >= 0))) {
|
2019-12-09 08:49:32 +01:00
|
|
|
// Lower bound behavior is not well defined if it is larger than
|
|
|
|
// seek key or upper bound. Disable the check for now.
|
|
|
|
*diverged = true;
|
|
|
|
return;
|
2019-12-20 23:54:30 +01:00
|
|
|
} else if (op == kLastOpSeekForPrev && ro.iterate_upper_bound != nullptr &&
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
(options_.comparator->CompareWithoutTimestamp(
|
|
|
|
*ro.iterate_upper_bound, /*a_has_ts=*/false, seek_key,
|
|
|
|
/*b_has_ts=*/false) <= 0 ||
|
2019-12-20 23:54:30 +01:00
|
|
|
(ro.iterate_lower_bound != nullptr &&
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
options_.comparator->CompareWithoutTimestamp(
|
|
|
|
*ro.iterate_lower_bound, /*a_has_ts=*/false,
|
|
|
|
*ro.iterate_upper_bound, /*b_has_ts=*/false) >= 0))) {
|
2019-12-09 08:49:32 +01:00
|
|
|
// Uppder bound behavior is not well defined if it is smaller than
|
|
|
|
// seek key or lower bound. Disable the check for now.
|
|
|
|
*diverged = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-28 23:42:21 +01:00
|
|
|
const SliceTransform* pe = (ro.total_order_seek || ro.auto_prefix_mode)
|
|
|
|
? nullptr
|
|
|
|
: options_.prefix_extractor.get();
|
2020-01-08 22:30:51 +01:00
|
|
|
const Comparator* cmp = options_.comparator;
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
if (iter->Valid() && !cmp_iter->Valid()) {
|
2020-01-08 22:30:51 +01:00
|
|
|
if (pe != nullptr) {
|
|
|
|
if (!pe->InDomain(seek_key)) {
|
|
|
|
// Prefix seek a non-in-domain key is undefined. Skip checking for
|
|
|
|
// this scenario.
|
|
|
|
*diverged = true;
|
|
|
|
return;
|
|
|
|
} else if (!pe->InDomain(iter->key())) {
|
|
|
|
// out of range is iterator key is not in domain anymore.
|
|
|
|
*diverged = true;
|
|
|
|
return;
|
|
|
|
} else if (pe->Transform(iter->key()) != pe->Transform(seek_key)) {
|
|
|
|
*diverged = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stderr,
|
2019-12-20 23:54:30 +01:00
|
|
|
"Control interator is invalid but iterator has key %s "
|
2019-12-09 08:49:32 +01:00
|
|
|
"%s\n",
|
2019-12-20 23:54:30 +01:00
|
|
|
iter->key().ToString(true).c_str(), op_logs.c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
|
|
|
|
*diverged = true;
|
|
|
|
} else if (cmp_iter->Valid()) {
|
|
|
|
// Iterator is not valid. It can be legimate if it has already been
|
|
|
|
// out of upper or lower bound, or filtered out by prefix iterator.
|
|
|
|
const Slice& total_order_key = cmp_iter->key();
|
|
|
|
|
|
|
|
if (pe != nullptr) {
|
|
|
|
if (!pe->InDomain(seek_key)) {
|
|
|
|
// Prefix seek a non-in-domain key is undefined. Skip checking for
|
|
|
|
// this scenario.
|
|
|
|
*diverged = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pe->InDomain(total_order_key) ||
|
|
|
|
pe->Transform(total_order_key) != pe->Transform(seek_key)) {
|
|
|
|
// If the prefix is exhausted, the only thing needs to check
|
|
|
|
// is the iterator isn't return a position in prefix.
|
|
|
|
// Either way, checking can stop from here.
|
|
|
|
*diverged = true;
|
|
|
|
if (!iter->Valid() || !pe->InDomain(iter->key()) ||
|
|
|
|
pe->Transform(iter->key()) != pe->Transform(seek_key)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf(stderr,
|
2019-12-20 23:54:30 +01:00
|
|
|
"Iterator stays in prefix but contol doesn't"
|
|
|
|
" iterator key %s control iterator key %s %s\n",
|
2019-12-09 08:49:32 +01:00
|
|
|
iter->key().ToString(true).c_str(),
|
2019-12-20 23:54:30 +01:00
|
|
|
cmp_iter->key().ToString(true).c_str(), op_logs.c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check upper or lower bounds.
|
|
|
|
if (!*diverged) {
|
|
|
|
if ((iter->Valid() && iter->key() != cmp_iter->key()) ||
|
|
|
|
(!iter->Valid() &&
|
|
|
|
(ro.iterate_upper_bound == nullptr ||
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
cmp->CompareWithoutTimestamp(total_order_key, /*a_has_ts=*/false,
|
|
|
|
*ro.iterate_upper_bound,
|
|
|
|
/*b_has_ts=*/false) < 0) &&
|
2019-12-09 08:49:32 +01:00
|
|
|
(ro.iterate_lower_bound == nullptr ||
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
cmp->CompareWithoutTimestamp(total_order_key, /*a_has_ts=*/false,
|
|
|
|
*ro.iterate_lower_bound,
|
|
|
|
/*b_has_ts=*/false) > 0))) {
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"Iterator diverged from control iterator which"
|
2019-12-20 23:54:30 +01:00
|
|
|
" has value %s %s\n",
|
|
|
|
total_order_key.ToString(true).c_str(), op_logs.c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
if (iter->Valid()) {
|
|
|
|
fprintf(stderr, "iterator has value %s\n",
|
|
|
|
iter->key().ToString(true).c_str());
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "iterator is not valid\n");
|
|
|
|
}
|
|
|
|
*diverged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*diverged) {
|
|
|
|
fprintf(stderr, "Control CF %s\n", cmp_cfh->GetName().c_str());
|
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
// Fail fast to preserve the DB state.
|
|
|
|
thread->shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ROCKSDB_LITE
|
|
|
|
Status StressTest::TestBackupRestore(
|
|
|
|
ThreadState* /* thread */,
|
|
|
|
const std::vector<int>& /* rand_column_families */,
|
|
|
|
const std::vector<int64_t>& /* rand_keys */) {
|
|
|
|
assert(false);
|
|
|
|
fprintf(stderr,
|
|
|
|
"RocksDB lite does not support "
|
|
|
|
"TestBackupRestore\n");
|
|
|
|
std::terminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
Status StressTest::TestCheckpoint(
|
|
|
|
ThreadState* /* thread */,
|
|
|
|
const std::vector<int>& /* rand_column_families */,
|
|
|
|
const std::vector<int64_t>& /* rand_keys */) {
|
|
|
|
assert(false);
|
|
|
|
fprintf(stderr,
|
|
|
|
"RocksDB lite does not support "
|
|
|
|
"TestCheckpoint\n");
|
|
|
|
std::terminate();
|
|
|
|
}
|
2019-12-19 23:03:14 +01:00
|
|
|
|
|
|
|
void StressTest::TestCompactFiles(ThreadState* /* thread */,
|
|
|
|
ColumnFamilyHandle* /* column_family */) {
|
|
|
|
assert(false);
|
|
|
|
fprintf(stderr,
|
|
|
|
"RocksDB lite does not support "
|
|
|
|
"CompactFiles\n");
|
|
|
|
std::terminate();
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
#else // ROCKSDB_LITE
|
|
|
|
Status StressTest::TestBackupRestore(
|
|
|
|
ThreadState* thread, const std::vector<int>& rand_column_families,
|
|
|
|
const std::vector<int64_t>& rand_keys) {
|
|
|
|
std::string backup_dir = FLAGS_db + "/.backup" + ToString(thread->tid);
|
|
|
|
std::string restore_dir = FLAGS_db + "/.restore" + ToString(thread->tid);
|
|
|
|
BackupableDBOptions backup_opts(backup_dir);
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
2020-09-04 05:11:45 +02:00
|
|
|
// For debugging, get info_log from live options
|
|
|
|
backup_opts.info_log = db_->GetDBOptions().info_log.get();
|
|
|
|
if (thread->rand.OneIn(10)) {
|
|
|
|
backup_opts.share_table_files = false;
|
|
|
|
} else {
|
|
|
|
backup_opts.share_table_files = true;
|
|
|
|
if (thread->rand.OneIn(5)) {
|
|
|
|
backup_opts.share_files_with_checksum = false;
|
|
|
|
} else {
|
|
|
|
backup_opts.share_files_with_checksum = true;
|
|
|
|
if (thread->rand.OneIn(2)) {
|
|
|
|
// old
|
Restore file size in backup table file names (and other cleanup) (#7400)
Summary:
Prior to 6.12, backup files using share_files_with_checksum had
the file size encoded in the file name, after the last '\_' and before
the last '.'. We considered this an implementation detail subject to
change, and indeed removed this information from the file name (with an
option to use old behavior) because it was considered
ineffective/inefficient for file name uniqueness. However, some
downstream RocksDB users were relying on this information since the file
size is not explicitly in the backup manifest file.
This primary purpose of this change is "retrofitting" the 6.12 release
(not yet a public release) to simultaneously support the benefits of the
new naming scheme (I/O performance and data correctness at scale) and
preserve the file size information, both as default behaviors. With this
change, we are essentially making the file size information encoded in
the file name an official, though obscure, extension of the backup meta
file format.
We preserve an option (kLegacyCrc32cAndFileSize) to use the original
"legacy" naming scheme, with its caveats, and make it easy to omit the
file size information (no kFlagIncludeFileSize), for more compact file
names. But note that changing the naming scheme used on an existing db
and backup directory can lead to transient space amplification, as some
files will be stored under two names in the shared_checksum directory.
Because some backups were saved using the original 6.12 naming scheme,
we offer two ways of dealing with those files: SST files generated by
older 6.12 versions can either use the default naming scheme in effect
when the SST files were generated (kFlagMatchInterimNaming, default, no
transient space amplification) or can use a new naming scheme (no
kFlagMatchInterimNaming, potential space amplification because some
already stored files getting a new name).
We don't have a natural way to detect which files were generated by
previous 6.12 versions, but this change hacks one in by changing DB
session ids to now use a more concise encoding, reducing file name
length, saving ~dozen bytes from SST files, and making them visually
distinct from DB ids so that they are less likely to be mixed up.
Two final auxiliary notes:
Recognizing that the backup file names have become a de facto part of
the backup meta schema, this change makes them easier to parse and
extend by putting a distinct marker, 's', before DB session ids embedded
in the name. When we extend this to allow custom checksums in the name,
they can get their own marker to ensure safe parsing. For backward
compatibility, file size does not get a marker but is assumed for
`_[0-9]+[.]`
Another change from initial 6.12 default behavior is never including
file custom checksum in the file name. Looking ahead to 6.13, we do not
want the default behavior to cause backup space amplification for
someone turning on file custom checksum checking in BackupEngine; we
want that to be an easy decision. When implemented, including file
custom checksums in backup file names will be a non-default option.
Actual file name patterns and priorities, as regexes:
kLegacyCrc32cAndFileSize OR pre-6.12 SST file ->
[0-9]+_[0-9]+_[0-9]+[.]sst
kFlagMatchInterimNaming set (default) AND early 6.12 SST file ->
[0-9]+_[0-9a-fA-F-]+[.]sst
kUseDbSessionId AND NOT kFlagIncludeFileSize ->
[0-9]+_s[0-9A-Z]{20}[.]sst
kUseDbSessionId AND kFlagIncludeFileSize (default) ->
[0-9]+_s[0-9A-Z]{20}_[0-9]+[.]sst
We might add opt-in options for more '\_' separated data in the name,
but embedded file size, if present, will always be after last '\_' and
before '.sst'.
This change was originally applied to version 6.12. (See https://github.com/facebook/rocksdb/issues/7390)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7400
Test Plan:
unit tests included. Sync point callbacks are used to mimic
previous version SST files.
Reviewed By: ajkr
Differential Revision: D23759587
Pulled By: pdillinger
fbshipit-source-id: f62d8af4e0978de0a34f26288cfbe66049b70025
2020-09-17 19:22:56 +02:00
|
|
|
backup_opts.share_files_with_checksum_naming =
|
|
|
|
BackupableDBOptions::kLegacyCrc32cAndFileSize;
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
2020-09-04 05:11:45 +02:00
|
|
|
} else {
|
|
|
|
// new
|
|
|
|
backup_opts.share_files_with_checksum_naming =
|
Restore file size in backup table file names (and other cleanup) (#7400)
Summary:
Prior to 6.12, backup files using share_files_with_checksum had
the file size encoded in the file name, after the last '\_' and before
the last '.'. We considered this an implementation detail subject to
change, and indeed removed this information from the file name (with an
option to use old behavior) because it was considered
ineffective/inefficient for file name uniqueness. However, some
downstream RocksDB users were relying on this information since the file
size is not explicitly in the backup manifest file.
This primary purpose of this change is "retrofitting" the 6.12 release
(not yet a public release) to simultaneously support the benefits of the
new naming scheme (I/O performance and data correctness at scale) and
preserve the file size information, both as default behaviors. With this
change, we are essentially making the file size information encoded in
the file name an official, though obscure, extension of the backup meta
file format.
We preserve an option (kLegacyCrc32cAndFileSize) to use the original
"legacy" naming scheme, with its caveats, and make it easy to omit the
file size information (no kFlagIncludeFileSize), for more compact file
names. But note that changing the naming scheme used on an existing db
and backup directory can lead to transient space amplification, as some
files will be stored under two names in the shared_checksum directory.
Because some backups were saved using the original 6.12 naming scheme,
we offer two ways of dealing with those files: SST files generated by
older 6.12 versions can either use the default naming scheme in effect
when the SST files were generated (kFlagMatchInterimNaming, default, no
transient space amplification) or can use a new naming scheme (no
kFlagMatchInterimNaming, potential space amplification because some
already stored files getting a new name).
We don't have a natural way to detect which files were generated by
previous 6.12 versions, but this change hacks one in by changing DB
session ids to now use a more concise encoding, reducing file name
length, saving ~dozen bytes from SST files, and making them visually
distinct from DB ids so that they are less likely to be mixed up.
Two final auxiliary notes:
Recognizing that the backup file names have become a de facto part of
the backup meta schema, this change makes them easier to parse and
extend by putting a distinct marker, 's', before DB session ids embedded
in the name. When we extend this to allow custom checksums in the name,
they can get their own marker to ensure safe parsing. For backward
compatibility, file size does not get a marker but is assumed for
`_[0-9]+[.]`
Another change from initial 6.12 default behavior is never including
file custom checksum in the file name. Looking ahead to 6.13, we do not
want the default behavior to cause backup space amplification for
someone turning on file custom checksum checking in BackupEngine; we
want that to be an easy decision. When implemented, including file
custom checksums in backup file names will be a non-default option.
Actual file name patterns and priorities, as regexes:
kLegacyCrc32cAndFileSize OR pre-6.12 SST file ->
[0-9]+_[0-9]+_[0-9]+[.]sst
kFlagMatchInterimNaming set (default) AND early 6.12 SST file ->
[0-9]+_[0-9a-fA-F-]+[.]sst
kUseDbSessionId AND NOT kFlagIncludeFileSize ->
[0-9]+_s[0-9A-Z]{20}[.]sst
kUseDbSessionId AND kFlagIncludeFileSize (default) ->
[0-9]+_s[0-9A-Z]{20}_[0-9]+[.]sst
We might add opt-in options for more '\_' separated data in the name,
but embedded file size, if present, will always be after last '\_' and
before '.sst'.
This change was originally applied to version 6.12. (See https://github.com/facebook/rocksdb/issues/7390)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7400
Test Plan:
unit tests included. Sync point callbacks are used to mimic
previous version SST files.
Reviewed By: ajkr
Differential Revision: D23759587
Pulled By: pdillinger
fbshipit-source-id: f62d8af4e0978de0a34f26288cfbe66049b70025
2020-09-17 19:22:56 +02:00
|
|
|
BackupableDBOptions::kUseDbSessionId;
|
|
|
|
}
|
|
|
|
if (thread->rand.OneIn(2)) {
|
|
|
|
backup_opts.share_files_with_checksum_naming =
|
|
|
|
backup_opts.share_files_with_checksum_naming |
|
|
|
|
BackupableDBOptions::kFlagIncludeFileSize;
|
|
|
|
}
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
2020-09-04 05:11:45 +02:00
|
|
|
}
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
BackupEngine* backup_engine = nullptr;
|
2020-09-08 19:46:55 +02:00
|
|
|
std::string from = "a backup/restore operation";
|
2019-12-21 01:13:19 +01:00
|
|
|
Status s = BackupEngine::Open(db_stress_env, backup_opts, &backup_engine);
|
2020-09-08 19:46:55 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
from = "BackupEngine::Open";
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
if (s.ok()) {
|
Begin forward compatibility for new backup meta schema (#8069)
Summary:
This does not add any new public APIs or published
functionality, but adds the ability to read and use (and in tests,
write) backups with a new meta file schema, based on the old schema
but not forward-compatible (before this change). The new schema enables
some capabilities not in the old:
* Explicit versioning, so that users get clean error messages the next
time we want to break forward compatibility.
* Ignoring unrecognized fields (with warning), so that new non-critical
features can be added without breaking forward compatibility.
* Rejecting future "non-ignorable" fields, so that new features critical
to some use-cases could potentially be added outside of linear schema
versions, with broken forward compatibility.
* Fields at the end of the meta file, such as for checksum of the meta
file's contents (up to that point)
* New optional 'size' field for each file, which is checked when present
* Optionally omitting 'crc32' field, so that we aren't required to have
a crc32c checksum for files to take a backup. (E.g. to support backup
via hard links and to better support file custom checksums.)
Because we do not have a JSON parser and to share code, the new schema
is simply derived from the old schema.
BackupEngine code is updated to allow missing checksums in some places,
and to make that easier, `has_checksum` and `verify_checksum_after_work`
are eliminated. Empty `checksum_hex` indicates checksum is unknown. I'm
not too afraid of regressing on data integrity, because
(a) we have pretty good test coverage of corruption detection in backups, and
(b) we are increasingly relying on the DB itself for data integrity rather than
it being an exclusive feature of backups.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8069
Test Plan:
new unit tests, added to crash test (some local run with
boosted backup probability)
Reviewed By: ajkr
Differential Revision: D27139824
Pulled By: pdillinger
fbshipit-source-id: 9e0e4decfb42bb84783d64d2d246456d97e8e8c5
2021-03-20 04:14:38 +01:00
|
|
|
if (thread->rand.OneIn(2)) {
|
|
|
|
TEST_FutureSchemaVersion2Options test_opts;
|
|
|
|
test_opts.crc32c_checksums = thread->rand.OneIn(2) == 0;
|
|
|
|
test_opts.file_sizes = thread->rand.OneIn(2) == 0;
|
|
|
|
TEST_EnableWriteFutureSchemaVersion2(backup_engine, test_opts);
|
|
|
|
}
|
2022-01-06 01:12:12 +01:00
|
|
|
CreateBackupOptions create_opts;
|
|
|
|
if (FLAGS_disable_wal) {
|
|
|
|
// The verification can only work when latest value of `key` is backed up,
|
|
|
|
// which requires flushing in case of WAL disabled.
|
|
|
|
//
|
|
|
|
// Note this triggers a flush with a key lock held. Meanwhile, operations
|
|
|
|
// like flush/compaction may attempt to grab key locks like in
|
|
|
|
// `DbStressCompactionFilter`. The philosophy around preventing deadlock
|
|
|
|
// is the background operation key lock acquisition only tries but does
|
|
|
|
// not wait for the lock. So here in the foreground it is OK to hold the
|
|
|
|
// lock and wait on a background operation (flush).
|
|
|
|
create_opts.flush_before_backup = true;
|
|
|
|
}
|
|
|
|
s = backup_engine->CreateNewBackup(create_opts, db_);
|
2020-09-08 19:46:55 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
from = "BackupEngine::CreateNewBackup";
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
if (s.ok()) {
|
|
|
|
delete backup_engine;
|
|
|
|
backup_engine = nullptr;
|
2019-12-21 01:13:19 +01:00
|
|
|
s = BackupEngine::Open(db_stress_env, backup_opts, &backup_engine);
|
2020-09-08 19:46:55 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
from = "BackupEngine::Open (again)";
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
2020-09-04 05:11:45 +02:00
|
|
|
std::vector<BackupInfo> backup_info;
|
Make backups openable as read-only DBs (#8142)
Summary:
A current limitation of backups is that you don't know the
exact database state of when the backup was taken. With this new
feature, you can at least inspect the backup's DB state without
restoring it by opening it as a read-only DB.
Rather than add something like OpenAsReadOnlyDB to the BackupEngine API,
which would inhibit opening stackable DB implementations read-only
(if/when their APIs support it), we instead provide a DB name and Env
that can be used to open as a read-only DB.
Possible follow-up work:
* Add a version of GetBackupInfo for a single backup.
* Let CreateNewBackup return the BackupID of the newly-created backup.
Implementation details:
Refactored ChrootFileSystem to split off new base class RemapFileSystem,
which allows more general remapping of files. We use this base class to
implement BackupEngineImpl::RemapSharedFileSystem.
To minimize API impact, I decided to just add these fields `name_for_open`
and `env_for_open` to those set by GetBackupInfo when
include_file_details=true. Creating the RemapSharedFileSystem adds a bit
to the memory consumption, perhaps unnecessarily in some cases, but this
has been mitigated by (a) only initialize the RemapSharedFileSystem
lazily when GetBackupInfo with include_file_details=true is called, and
(b) using the existing `shared_ptr<FileInfo>` objects to hold most of the
mapping data.
To enhance API safety, RemapSharedFileSystem is wrapped by new
ReadOnlyFileSystem which rejects any attempts to write. This uncovered a
couple of places in which DB::OpenForReadOnly would write to the
filesystem, so I fixed these. Added a release note because this affects
logging.
Additional minor refactoring in backupable_db.cc to support the new
functionality.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8142
Test Plan:
new test (run with ASAN and UBSAN), added to stress test and
ran it for a while with amplified backup_one_in
Reviewed By: ajkr
Differential Revision: D27535408
Pulled By: pdillinger
fbshipit-source-id: 04666d310aa0261ef6b2385c43ca793ce1dfd148
2021-04-06 23:36:45 +02:00
|
|
|
// If inplace_not_restore, we verify the backup by opening it as a
|
|
|
|
// read-only DB. If !inplace_not_restore, we restore it to a temporary
|
|
|
|
// directory for verification.
|
|
|
|
bool inplace_not_restore = thread->rand.OneIn(3);
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
2020-09-04 05:11:45 +02:00
|
|
|
if (s.ok()) {
|
Make backups openable as read-only DBs (#8142)
Summary:
A current limitation of backups is that you don't know the
exact database state of when the backup was taken. With this new
feature, you can at least inspect the backup's DB state without
restoring it by opening it as a read-only DB.
Rather than add something like OpenAsReadOnlyDB to the BackupEngine API,
which would inhibit opening stackable DB implementations read-only
(if/when their APIs support it), we instead provide a DB name and Env
that can be used to open as a read-only DB.
Possible follow-up work:
* Add a version of GetBackupInfo for a single backup.
* Let CreateNewBackup return the BackupID of the newly-created backup.
Implementation details:
Refactored ChrootFileSystem to split off new base class RemapFileSystem,
which allows more general remapping of files. We use this base class to
implement BackupEngineImpl::RemapSharedFileSystem.
To minimize API impact, I decided to just add these fields `name_for_open`
and `env_for_open` to those set by GetBackupInfo when
include_file_details=true. Creating the RemapSharedFileSystem adds a bit
to the memory consumption, perhaps unnecessarily in some cases, but this
has been mitigated by (a) only initialize the RemapSharedFileSystem
lazily when GetBackupInfo with include_file_details=true is called, and
(b) using the existing `shared_ptr<FileInfo>` objects to hold most of the
mapping data.
To enhance API safety, RemapSharedFileSystem is wrapped by new
ReadOnlyFileSystem which rejects any attempts to write. This uncovered a
couple of places in which DB::OpenForReadOnly would write to the
filesystem, so I fixed these. Added a release note because this affects
logging.
Additional minor refactoring in backupable_db.cc to support the new
functionality.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8142
Test Plan:
new test (run with ASAN and UBSAN), added to stress test and
ran it for a while with amplified backup_one_in
Reviewed By: ajkr
Differential Revision: D27535408
Pulled By: pdillinger
fbshipit-source-id: 04666d310aa0261ef6b2385c43ca793ce1dfd148
2021-04-06 23:36:45 +02:00
|
|
|
backup_engine->GetBackupInfo(&backup_info,
|
|
|
|
/*include_file_details*/ inplace_not_restore);
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
2020-09-04 05:11:45 +02:00
|
|
|
if (backup_info.empty()) {
|
|
|
|
s = Status::NotFound("no backups found");
|
2020-09-08 19:46:55 +02:00
|
|
|
from = "BackupEngine::GetBackupInfo";
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
2020-09-04 05:11:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (s.ok() && thread->rand.OneIn(2)) {
|
|
|
|
s = backup_engine->VerifyBackup(
|
|
|
|
backup_info.front().backup_id,
|
|
|
|
thread->rand.OneIn(2) /* verify_with_checksum */);
|
2020-09-08 19:46:55 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
from = "BackupEngine::VerifyBackup";
|
|
|
|
}
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
2020-09-04 05:11:45 +02:00
|
|
|
}
|
2020-09-11 07:53:47 +02:00
|
|
|
const bool allow_persistent = thread->tid == 0; // not too many
|
2020-09-08 19:46:55 +02:00
|
|
|
bool from_latest = false;
|
Make backups openable as read-only DBs (#8142)
Summary:
A current limitation of backups is that you don't know the
exact database state of when the backup was taken. With this new
feature, you can at least inspect the backup's DB state without
restoring it by opening it as a read-only DB.
Rather than add something like OpenAsReadOnlyDB to the BackupEngine API,
which would inhibit opening stackable DB implementations read-only
(if/when their APIs support it), we instead provide a DB name and Env
that can be used to open as a read-only DB.
Possible follow-up work:
* Add a version of GetBackupInfo for a single backup.
* Let CreateNewBackup return the BackupID of the newly-created backup.
Implementation details:
Refactored ChrootFileSystem to split off new base class RemapFileSystem,
which allows more general remapping of files. We use this base class to
implement BackupEngineImpl::RemapSharedFileSystem.
To minimize API impact, I decided to just add these fields `name_for_open`
and `env_for_open` to those set by GetBackupInfo when
include_file_details=true. Creating the RemapSharedFileSystem adds a bit
to the memory consumption, perhaps unnecessarily in some cases, but this
has been mitigated by (a) only initialize the RemapSharedFileSystem
lazily when GetBackupInfo with include_file_details=true is called, and
(b) using the existing `shared_ptr<FileInfo>` objects to hold most of the
mapping data.
To enhance API safety, RemapSharedFileSystem is wrapped by new
ReadOnlyFileSystem which rejects any attempts to write. This uncovered a
couple of places in which DB::OpenForReadOnly would write to the
filesystem, so I fixed these. Added a release note because this affects
logging.
Additional minor refactoring in backupable_db.cc to support the new
functionality.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8142
Test Plan:
new test (run with ASAN and UBSAN), added to stress test and
ran it for a while with amplified backup_one_in
Reviewed By: ajkr
Differential Revision: D27535408
Pulled By: pdillinger
fbshipit-source-id: 04666d310aa0261ef6b2385c43ca793ce1dfd148
2021-04-06 23:36:45 +02:00
|
|
|
int count = static_cast<int>(backup_info.size());
|
|
|
|
if (s.ok() && !inplace_not_restore) {
|
2020-09-08 19:46:55 +02:00
|
|
|
if (count > 1) {
|
|
|
|
s = backup_engine->RestoreDBFromBackup(
|
|
|
|
RestoreOptions(), backup_info[thread->rand.Uniform(count)].backup_id,
|
|
|
|
restore_dir /* db_dir */, restore_dir /* wal_dir */);
|
|
|
|
if (!s.ok()) {
|
|
|
|
from = "BackupEngine::RestoreDBFromBackup";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
from_latest = true;
|
|
|
|
s = backup_engine->RestoreDBFromLatestBackup(RestoreOptions(),
|
|
|
|
restore_dir /* db_dir */,
|
|
|
|
restore_dir /* wal_dir */);
|
|
|
|
if (!s.ok()) {
|
|
|
|
from = "BackupEngine::RestoreDBFromLatestBackup";
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
Make backups openable as read-only DBs (#8142)
Summary:
A current limitation of backups is that you don't know the
exact database state of when the backup was taken. With this new
feature, you can at least inspect the backup's DB state without
restoring it by opening it as a read-only DB.
Rather than add something like OpenAsReadOnlyDB to the BackupEngine API,
which would inhibit opening stackable DB implementations read-only
(if/when their APIs support it), we instead provide a DB name and Env
that can be used to open as a read-only DB.
Possible follow-up work:
* Add a version of GetBackupInfo for a single backup.
* Let CreateNewBackup return the BackupID of the newly-created backup.
Implementation details:
Refactored ChrootFileSystem to split off new base class RemapFileSystem,
which allows more general remapping of files. We use this base class to
implement BackupEngineImpl::RemapSharedFileSystem.
To minimize API impact, I decided to just add these fields `name_for_open`
and `env_for_open` to those set by GetBackupInfo when
include_file_details=true. Creating the RemapSharedFileSystem adds a bit
to the memory consumption, perhaps unnecessarily in some cases, but this
has been mitigated by (a) only initialize the RemapSharedFileSystem
lazily when GetBackupInfo with include_file_details=true is called, and
(b) using the existing `shared_ptr<FileInfo>` objects to hold most of the
mapping data.
To enhance API safety, RemapSharedFileSystem is wrapped by new
ReadOnlyFileSystem which rejects any attempts to write. This uncovered a
couple of places in which DB::OpenForReadOnly would write to the
filesystem, so I fixed these. Added a release note because this affects
logging.
Additional minor refactoring in backupable_db.cc to support the new
functionality.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8142
Test Plan:
new test (run with ASAN and UBSAN), added to stress test and
ran it for a while with amplified backup_one_in
Reviewed By: ajkr
Differential Revision: D27535408
Pulled By: pdillinger
fbshipit-source-id: 04666d310aa0261ef6b2385c43ca793ce1dfd148
2021-04-06 23:36:45 +02:00
|
|
|
if (s.ok() && !inplace_not_restore) {
|
|
|
|
// Purge early if restoring, to ensure the restored directory doesn't
|
|
|
|
// have some secret dependency on the backup directory.
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
2020-09-04 05:11:45 +02:00
|
|
|
uint32_t to_keep = 0;
|
2020-09-11 07:53:47 +02:00
|
|
|
if (allow_persistent) {
|
Fix, enable, and enhance backup/restore in db_stress (#7348)
Summary:
Although added to db_stress, testing of backup/restore
was never integrated into the crash test, originally concerned about
performance. I've enabled it now and to address the peformance concern,
testing backup/restore is always skipped once the db exceeds a certain
size threshold, default 100MB. This should provide sufficient
opportunity for testing BackupEngine without bogging down everything
else with heavier and heavier operations.
Also fixed backup/restore in db_stress by making sure PurgeOldBackups
can remove manifest files, which are normally kept around for db_stress.
Added more coverage of backup options, and up to three backups being
saved in one backup directory (in some cases).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7348
Test Plan:
ran 'make blackbox_crash_test' for a while, with heightened
probabilitly of taking backups (1/10k). Also confirmed with some debug
output that the code is being covered, TestBackupRestore only takes
a few seconds to complete when triggered, and even at 1/10k and ~50MB
database, there's <,~ 1 thread testing backups at any time.
Reviewed By: ajkr
Differential Revision: D23510835
Pulled By: pdillinger
fbshipit-source-id: b6b8735591808141f81f10773ac31634cf03b6c0
2020-09-04 05:11:45 +02:00
|
|
|
// allow one thread to keep up to 2 backups
|
|
|
|
to_keep = thread->rand.Uniform(3);
|
|
|
|
}
|
|
|
|
s = backup_engine->PurgeOldBackups(to_keep);
|
2020-09-08 19:46:55 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
from = "BackupEngine::PurgeOldBackups";
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
DB* restored_db = nullptr;
|
|
|
|
std::vector<ColumnFamilyHandle*> restored_cf_handles;
|
2020-09-09 20:16:50 +02:00
|
|
|
// Not yet implemented: opening restored BlobDB or TransactionDB
|
|
|
|
if (s.ok() && !FLAGS_use_txn && !FLAGS_use_blob_db) {
|
2019-12-09 08:49:32 +01:00
|
|
|
Options restore_options(options_);
|
|
|
|
restore_options.listeners.clear();
|
2020-09-14 23:18:42 +02:00
|
|
|
// Avoid dangling/shared file descriptors, for reliable destroy
|
|
|
|
restore_options.sst_file_manager = nullptr;
|
2019-12-09 08:49:32 +01:00
|
|
|
std::vector<ColumnFamilyDescriptor> cf_descriptors;
|
|
|
|
// TODO(ajkr): `column_family_names_` is not safe to access here when
|
|
|
|
// `clear_column_family_one_in != 0`. But we can't easily switch to
|
|
|
|
// `ListColumnFamilies` to get names because it won't necessarily give
|
|
|
|
// the same order as `column_family_names_`.
|
|
|
|
assert(FLAGS_clear_column_family_one_in == 0);
|
|
|
|
for (auto name : column_family_names_) {
|
|
|
|
cf_descriptors.emplace_back(name, ColumnFamilyOptions(restore_options));
|
|
|
|
}
|
Make backups openable as read-only DBs (#8142)
Summary:
A current limitation of backups is that you don't know the
exact database state of when the backup was taken. With this new
feature, you can at least inspect the backup's DB state without
restoring it by opening it as a read-only DB.
Rather than add something like OpenAsReadOnlyDB to the BackupEngine API,
which would inhibit opening stackable DB implementations read-only
(if/when their APIs support it), we instead provide a DB name and Env
that can be used to open as a read-only DB.
Possible follow-up work:
* Add a version of GetBackupInfo for a single backup.
* Let CreateNewBackup return the BackupID of the newly-created backup.
Implementation details:
Refactored ChrootFileSystem to split off new base class RemapFileSystem,
which allows more general remapping of files. We use this base class to
implement BackupEngineImpl::RemapSharedFileSystem.
To minimize API impact, I decided to just add these fields `name_for_open`
and `env_for_open` to those set by GetBackupInfo when
include_file_details=true. Creating the RemapSharedFileSystem adds a bit
to the memory consumption, perhaps unnecessarily in some cases, but this
has been mitigated by (a) only initialize the RemapSharedFileSystem
lazily when GetBackupInfo with include_file_details=true is called, and
(b) using the existing `shared_ptr<FileInfo>` objects to hold most of the
mapping data.
To enhance API safety, RemapSharedFileSystem is wrapped by new
ReadOnlyFileSystem which rejects any attempts to write. This uncovered a
couple of places in which DB::OpenForReadOnly would write to the
filesystem, so I fixed these. Added a release note because this affects
logging.
Additional minor refactoring in backupable_db.cc to support the new
functionality.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8142
Test Plan:
new test (run with ASAN and UBSAN), added to stress test and
ran it for a while with amplified backup_one_in
Reviewed By: ajkr
Differential Revision: D27535408
Pulled By: pdillinger
fbshipit-source-id: 04666d310aa0261ef6b2385c43ca793ce1dfd148
2021-04-06 23:36:45 +02:00
|
|
|
if (inplace_not_restore) {
|
|
|
|
BackupInfo& info = backup_info[thread->rand.Uniform(count)];
|
|
|
|
restore_options.env = info.env_for_open.get();
|
|
|
|
s = DB::OpenForReadOnly(DBOptions(restore_options), info.name_for_open,
|
|
|
|
cf_descriptors, &restored_cf_handles,
|
|
|
|
&restored_db);
|
|
|
|
if (!s.ok()) {
|
|
|
|
from = "DB::OpenForReadOnly in backup/restore";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s = DB::Open(DBOptions(restore_options), restore_dir, cf_descriptors,
|
|
|
|
&restored_cf_handles, &restored_db);
|
|
|
|
if (!s.ok()) {
|
|
|
|
from = "DB::Open in backup/restore";
|
|
|
|
}
|
2020-09-08 19:46:55 +02:00
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
2020-09-08 19:46:55 +02:00
|
|
|
// Note the column families chosen by `rand_column_families` cannot be
|
|
|
|
// dropped while the locks for `rand_keys` are held. So we should not have
|
|
|
|
// to worry about accessing those column families throughout this function.
|
|
|
|
//
|
|
|
|
// For simplicity, currently only verifies existence/non-existence of a
|
|
|
|
// single key
|
2020-09-11 07:53:47 +02:00
|
|
|
for (size_t i = 0; restored_db && s.ok() && i < rand_column_families.size();
|
2020-09-08 19:46:55 +02:00
|
|
|
++i) {
|
|
|
|
std::string key_str = Key(rand_keys[0]);
|
2019-12-09 08:49:32 +01:00
|
|
|
Slice key = key_str;
|
|
|
|
std::string restored_value;
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
ReadOptions read_opts;
|
|
|
|
std::string ts_str;
|
|
|
|
Slice ts;
|
|
|
|
if (FLAGS_user_timestamp_size > 0) {
|
|
|
|
ts_str = GenerateTimestampForRead();
|
|
|
|
ts = ts_str;
|
|
|
|
read_opts.timestamp = &ts;
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
Status get_status = restored_db->Get(
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
read_opts, restored_cf_handles[rand_column_families[i]], key,
|
2019-12-09 08:49:32 +01:00
|
|
|
&restored_value);
|
2020-09-09 20:16:50 +02:00
|
|
|
bool exists = thread->shared->Exists(rand_column_families[i], rand_keys[0]);
|
2019-12-09 08:49:32 +01:00
|
|
|
if (get_status.ok()) {
|
2020-09-11 07:53:47 +02:00
|
|
|
if (!exists && from_latest && ShouldAcquireMutexOnKey()) {
|
2019-12-09 08:49:32 +01:00
|
|
|
s = Status::Corruption("key exists in restore but not in original db");
|
|
|
|
}
|
|
|
|
} else if (get_status.IsNotFound()) {
|
2020-09-11 07:53:47 +02:00
|
|
|
if (exists && from_latest && ShouldAcquireMutexOnKey()) {
|
2019-12-09 08:49:32 +01:00
|
|
|
s = Status::Corruption("key exists in original db but not in restore");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s = get_status;
|
2020-09-08 19:46:55 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
from = "DB::Get in backup/restore";
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (restored_db != nullptr) {
|
|
|
|
for (auto* cf_handle : restored_cf_handles) {
|
|
|
|
restored_db->DestroyColumnFamilyHandle(cf_handle);
|
|
|
|
}
|
|
|
|
delete restored_db;
|
|
|
|
restored_db = nullptr;
|
|
|
|
}
|
Make backups openable as read-only DBs (#8142)
Summary:
A current limitation of backups is that you don't know the
exact database state of when the backup was taken. With this new
feature, you can at least inspect the backup's DB state without
restoring it by opening it as a read-only DB.
Rather than add something like OpenAsReadOnlyDB to the BackupEngine API,
which would inhibit opening stackable DB implementations read-only
(if/when their APIs support it), we instead provide a DB name and Env
that can be used to open as a read-only DB.
Possible follow-up work:
* Add a version of GetBackupInfo for a single backup.
* Let CreateNewBackup return the BackupID of the newly-created backup.
Implementation details:
Refactored ChrootFileSystem to split off new base class RemapFileSystem,
which allows more general remapping of files. We use this base class to
implement BackupEngineImpl::RemapSharedFileSystem.
To minimize API impact, I decided to just add these fields `name_for_open`
and `env_for_open` to those set by GetBackupInfo when
include_file_details=true. Creating the RemapSharedFileSystem adds a bit
to the memory consumption, perhaps unnecessarily in some cases, but this
has been mitigated by (a) only initialize the RemapSharedFileSystem
lazily when GetBackupInfo with include_file_details=true is called, and
(b) using the existing `shared_ptr<FileInfo>` objects to hold most of the
mapping data.
To enhance API safety, RemapSharedFileSystem is wrapped by new
ReadOnlyFileSystem which rejects any attempts to write. This uncovered a
couple of places in which DB::OpenForReadOnly would write to the
filesystem, so I fixed these. Added a release note because this affects
logging.
Additional minor refactoring in backupable_db.cc to support the new
functionality.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8142
Test Plan:
new test (run with ASAN and UBSAN), added to stress test and
ran it for a while with amplified backup_one_in
Reviewed By: ajkr
Differential Revision: D27535408
Pulled By: pdillinger
fbshipit-source-id: 04666d310aa0261ef6b2385c43ca793ce1dfd148
2021-04-06 23:36:45 +02:00
|
|
|
if (s.ok() && inplace_not_restore) {
|
|
|
|
// Purge late if inplace open read-only
|
|
|
|
uint32_t to_keep = 0;
|
|
|
|
if (allow_persistent) {
|
|
|
|
// allow one thread to keep up to 2 backups
|
|
|
|
to_keep = thread->rand.Uniform(3);
|
|
|
|
}
|
|
|
|
s = backup_engine->PurgeOldBackups(to_keep);
|
|
|
|
if (!s.ok()) {
|
|
|
|
from = "BackupEngine::PurgeOldBackups";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (backup_engine != nullptr) {
|
|
|
|
delete backup_engine;
|
|
|
|
backup_engine = nullptr;
|
|
|
|
}
|
2020-09-11 07:53:47 +02:00
|
|
|
if (s.ok()) {
|
|
|
|
// Preserve directories on failure, or allowed persistent backup
|
|
|
|
if (!allow_persistent) {
|
|
|
|
s = DestroyDir(db_stress_env, backup_dir);
|
|
|
|
if (!s.ok()) {
|
|
|
|
from = "Destroy backup dir";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (s.ok()) {
|
|
|
|
s = DestroyDir(db_stress_env, restore_dir);
|
|
|
|
if (!s.ok()) {
|
|
|
|
from = "Destroy restore dir";
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
if (!s.ok()) {
|
2020-09-08 19:46:55 +02:00
|
|
|
fprintf(stderr, "Failure in %s with: %s\n", from.c_str(),
|
2019-12-20 17:46:52 +01:00
|
|
|
s.ToString().c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-12-21 06:42:19 +01:00
|
|
|
Status StressTest::TestApproximateSize(
|
|
|
|
ThreadState* thread, uint64_t iteration,
|
|
|
|
const std::vector<int>& rand_column_families,
|
|
|
|
const std::vector<int64_t>& rand_keys) {
|
|
|
|
// rand_keys likely only has one key. Just use the first one.
|
|
|
|
assert(!rand_keys.empty());
|
|
|
|
assert(!rand_column_families.empty());
|
|
|
|
int64_t key1 = rand_keys[0];
|
|
|
|
int64_t key2;
|
|
|
|
if (thread->rand.OneIn(2)) {
|
|
|
|
// Two totally random keys. This tends to cover large ranges.
|
|
|
|
key2 = GenerateOneKey(thread, iteration);
|
|
|
|
if (key2 < key1) {
|
|
|
|
std::swap(key1, key2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Unless users pass a very large FLAGS_max_key, it we should not worry
|
|
|
|
// about overflow. It is for testing, so we skip the overflow checking
|
|
|
|
// for simplicity.
|
|
|
|
key2 = key1 + static_cast<int64_t>(thread->rand.Uniform(1000));
|
|
|
|
}
|
|
|
|
std::string key1_str = Key(key1);
|
|
|
|
std::string key2_str = Key(key2);
|
|
|
|
Range range{Slice(key1_str), Slice(key2_str)};
|
|
|
|
SizeApproximationOptions sao;
|
|
|
|
sao.include_memtabtles = thread->rand.OneIn(2);
|
|
|
|
if (sao.include_memtabtles) {
|
|
|
|
sao.include_files = thread->rand.OneIn(2);
|
|
|
|
}
|
|
|
|
if (thread->rand.OneIn(2)) {
|
|
|
|
if (thread->rand.OneIn(2)) {
|
|
|
|
sao.files_size_error_margin = 0.0;
|
|
|
|
} else {
|
|
|
|
sao.files_size_error_margin =
|
|
|
|
static_cast<double>(thread->rand.Uniform(3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint64_t result;
|
|
|
|
return db_->GetApproximateSizes(
|
|
|
|
sao, column_families_[rand_column_families[0]], &range, 1, &result);
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
Status StressTest::TestCheckpoint(ThreadState* thread,
|
|
|
|
const std::vector<int>& rand_column_families,
|
|
|
|
const std::vector<int64_t>& rand_keys) {
|
|
|
|
std::string checkpoint_dir =
|
|
|
|
FLAGS_db + "/.checkpoint" + ToString(thread->tid);
|
|
|
|
Options tmp_opts(options_);
|
|
|
|
tmp_opts.listeners.clear();
|
2020-12-17 20:51:04 +01:00
|
|
|
tmp_opts.env = db_stress_env;
|
2019-12-16 23:28:06 +01:00
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
DestroyDB(checkpoint_dir, tmp_opts);
|
2019-12-16 23:28:06 +01:00
|
|
|
|
2020-06-30 21:00:32 +02:00
|
|
|
if (db_stress_env->FileExists(checkpoint_dir).ok()) {
|
|
|
|
// If the directory might still exist, try to delete the files one by one.
|
|
|
|
// Likely a trash file is still there.
|
2020-07-09 23:33:42 +02:00
|
|
|
Status my_s = DestroyDir(db_stress_env, checkpoint_dir);
|
2020-06-30 21:00:32 +02:00
|
|
|
if (!my_s.ok()) {
|
|
|
|
fprintf(stderr, "Fail to destory directory before checkpoint: %s",
|
|
|
|
my_s.ToString().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
Checkpoint* checkpoint = nullptr;
|
|
|
|
Status s = Checkpoint::Create(db_, &checkpoint);
|
|
|
|
if (s.ok()) {
|
|
|
|
s = checkpoint->CreateCheckpoint(checkpoint_dir);
|
2020-06-30 21:00:32 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "Fail to create checkpoint to %s\n",
|
|
|
|
checkpoint_dir.c_str());
|
|
|
|
std::vector<std::string> files;
|
|
|
|
Status my_s = db_stress_env->GetChildren(checkpoint_dir, &files);
|
|
|
|
if (my_s.ok()) {
|
|
|
|
for (const auto& f : files) {
|
|
|
|
fprintf(stderr, " %s\n", f.c_str());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Fail to get files under the directory to %s\n",
|
|
|
|
my_s.ToString().c_str());
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
2020-12-25 22:14:38 +01:00
|
|
|
delete checkpoint;
|
|
|
|
checkpoint = nullptr;
|
2019-12-09 08:49:32 +01:00
|
|
|
std::vector<ColumnFamilyHandle*> cf_handles;
|
|
|
|
DB* checkpoint_db = nullptr;
|
|
|
|
if (s.ok()) {
|
|
|
|
Options options(options_);
|
|
|
|
options.listeners.clear();
|
|
|
|
std::vector<ColumnFamilyDescriptor> cf_descs;
|
|
|
|
// TODO(ajkr): `column_family_names_` is not safe to access here when
|
|
|
|
// `clear_column_family_one_in != 0`. But we can't easily switch to
|
|
|
|
// `ListColumnFamilies` to get names because it won't necessarily give
|
|
|
|
// the same order as `column_family_names_`.
|
2020-09-11 07:53:47 +02:00
|
|
|
assert(FLAGS_clear_column_family_one_in == 0);
|
2019-12-09 08:49:32 +01:00
|
|
|
if (FLAGS_clear_column_family_one_in == 0) {
|
|
|
|
for (const auto& name : column_family_names_) {
|
|
|
|
cf_descs.emplace_back(name, ColumnFamilyOptions(options));
|
|
|
|
}
|
|
|
|
s = DB::OpenForReadOnly(DBOptions(options), checkpoint_dir, cf_descs,
|
|
|
|
&cf_handles, &checkpoint_db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (checkpoint_db != nullptr) {
|
2020-09-11 07:53:47 +02:00
|
|
|
// Note the column families chosen by `rand_column_families` cannot be
|
|
|
|
// dropped while the locks for `rand_keys` are held. So we should not have
|
|
|
|
// to worry about accessing those column families throughout this function.
|
2019-12-09 08:49:32 +01:00
|
|
|
for (size_t i = 0; s.ok() && i < rand_column_families.size(); ++i) {
|
2020-09-11 07:53:47 +02:00
|
|
|
std::string key_str = Key(rand_keys[0]);
|
2019-12-09 08:49:32 +01:00
|
|
|
Slice key = key_str;
|
|
|
|
std::string value;
|
|
|
|
Status get_status = checkpoint_db->Get(
|
|
|
|
ReadOptions(), cf_handles[rand_column_families[i]], key, &value);
|
|
|
|
bool exists =
|
2020-09-11 07:53:47 +02:00
|
|
|
thread->shared->Exists(rand_column_families[i], rand_keys[0]);
|
2019-12-09 08:49:32 +01:00
|
|
|
if (get_status.ok()) {
|
2020-09-11 07:53:47 +02:00
|
|
|
if (!exists && ShouldAcquireMutexOnKey()) {
|
2019-12-09 08:49:32 +01:00
|
|
|
s = Status::Corruption(
|
|
|
|
"key exists in checkpoint but not in original db");
|
|
|
|
}
|
|
|
|
} else if (get_status.IsNotFound()) {
|
2020-09-11 07:53:47 +02:00
|
|
|
if (exists && ShouldAcquireMutexOnKey()) {
|
2019-12-09 08:49:32 +01:00
|
|
|
s = Status::Corruption(
|
|
|
|
"key exists in original db but not in checkpoint");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s = get_status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto cfh : cf_handles) {
|
|
|
|
delete cfh;
|
|
|
|
}
|
|
|
|
cf_handles.clear();
|
|
|
|
delete checkpoint_db;
|
|
|
|
checkpoint_db = nullptr;
|
|
|
|
}
|
2019-12-16 23:28:06 +01:00
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "A checkpoint operation failed with: %s\n",
|
|
|
|
s.ToString().c_str());
|
2020-06-30 21:00:32 +02:00
|
|
|
} else {
|
|
|
|
DestroyDB(checkpoint_dir, tmp_opts);
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
2019-12-19 23:03:14 +01:00
|
|
|
|
2020-07-14 21:10:56 +02:00
|
|
|
void StressTest::TestGetProperty(ThreadState* thread) const {
|
|
|
|
std::unordered_set<std::string> levelPropertyNames = {
|
|
|
|
DB::Properties::kAggregatedTablePropertiesAtLevel,
|
|
|
|
DB::Properties::kCompressionRatioAtLevelPrefix,
|
|
|
|
DB::Properties::kNumFilesAtLevelPrefix,
|
|
|
|
};
|
|
|
|
std::unordered_set<std::string> unknownPropertyNames = {
|
|
|
|
DB::Properties::kEstimateOldestKeyTime,
|
|
|
|
DB::Properties::kOptionsStatistics,
|
2021-08-17 18:04:09 +02:00
|
|
|
DB::Properties::
|
|
|
|
kLiveSstFilesSizeAtTemperature, // similar to levelPropertyNames, it
|
|
|
|
// requires a number suffix
|
2020-07-14 21:10:56 +02:00
|
|
|
};
|
|
|
|
unknownPropertyNames.insert(levelPropertyNames.begin(),
|
|
|
|
levelPropertyNames.end());
|
|
|
|
|
|
|
|
std::string prop;
|
|
|
|
for (const auto& ppt_name_and_info : InternalStats::ppt_name_to_info) {
|
|
|
|
bool res = db_->GetProperty(ppt_name_and_info.first, &prop);
|
|
|
|
if (unknownPropertyNames.find(ppt_name_and_info.first) ==
|
|
|
|
unknownPropertyNames.end()) {
|
|
|
|
if (!res) {
|
|
|
|
fprintf(stderr, "Failed to get DB property: %s\n",
|
|
|
|
ppt_name_and_info.first.c_str());
|
|
|
|
thread->shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
if (ppt_name_and_info.second.handle_int != nullptr) {
|
|
|
|
uint64_t prop_int;
|
|
|
|
if (!db_->GetIntProperty(ppt_name_and_info.first, &prop_int)) {
|
|
|
|
fprintf(stderr, "Failed to get Int property: %s\n",
|
|
|
|
ppt_name_and_info.first.c_str());
|
|
|
|
thread->shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
}
|
2021-07-19 17:09:35 +02:00
|
|
|
if (ppt_name_and_info.second.handle_map != nullptr) {
|
|
|
|
std::map<std::string, std::string> prop_map;
|
|
|
|
if (!db_->GetMapProperty(ppt_name_and_info.first, &prop_map)) {
|
|
|
|
fprintf(stderr, "Failed to get Map property: %s\n",
|
|
|
|
ppt_name_and_info.first.c_str());
|
|
|
|
thread->shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
}
|
2020-07-14 21:10:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ROCKSDB_NAMESPACE::ColumnFamilyMetaData cf_meta_data;
|
|
|
|
db_->GetColumnFamilyMetaData(&cf_meta_data);
|
|
|
|
int level_size = static_cast<int>(cf_meta_data.levels.size());
|
|
|
|
for (int level = 0; level < level_size; level++) {
|
|
|
|
for (const auto& ppt_name : levelPropertyNames) {
|
|
|
|
bool res = db_->GetProperty(ppt_name + std::to_string(level), &prop);
|
|
|
|
if (!res) {
|
|
|
|
fprintf(stderr, "Failed to get DB property: %s\n",
|
|
|
|
(ppt_name + std::to_string(level)).c_str());
|
|
|
|
thread->shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test for an invalid property name
|
|
|
|
if (thread->rand.OneIn(100)) {
|
|
|
|
if (db_->GetProperty("rocksdb.invalid_property_name", &prop)) {
|
|
|
|
fprintf(stderr, "Failed to return false for invalid property name\n");
|
|
|
|
thread->shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:03:14 +01:00
|
|
|
void StressTest::TestCompactFiles(ThreadState* thread,
|
|
|
|
ColumnFamilyHandle* column_family) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::ColumnFamilyMetaData cf_meta_data;
|
2019-12-19 23:03:14 +01:00
|
|
|
db_->GetColumnFamilyMetaData(column_family, &cf_meta_data);
|
|
|
|
|
2021-11-01 06:13:05 +01:00
|
|
|
if (cf_meta_data.levels.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:03:14 +01:00
|
|
|
// Randomly compact up to three consecutive files from a level
|
|
|
|
const int kMaxRetry = 3;
|
|
|
|
for (int attempt = 0; attempt < kMaxRetry; ++attempt) {
|
|
|
|
size_t random_level =
|
|
|
|
thread->rand.Uniform(static_cast<int>(cf_meta_data.levels.size()));
|
|
|
|
|
|
|
|
const auto& files = cf_meta_data.levels[random_level].files;
|
|
|
|
if (files.size() > 0) {
|
|
|
|
size_t random_file_index =
|
|
|
|
thread->rand.Uniform(static_cast<int>(files.size()));
|
|
|
|
if (files[random_file_index].being_compacted) {
|
|
|
|
// Retry as the selected file is currently being compacted
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> input_files;
|
|
|
|
input_files.push_back(files[random_file_index].name);
|
|
|
|
if (random_file_index > 0 &&
|
|
|
|
!files[random_file_index - 1].being_compacted) {
|
|
|
|
input_files.push_back(files[random_file_index - 1].name);
|
|
|
|
}
|
|
|
|
if (random_file_index + 1 < files.size() &&
|
|
|
|
!files[random_file_index + 1].being_compacted) {
|
|
|
|
input_files.push_back(files[random_file_index + 1].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t output_level =
|
|
|
|
std::min(random_level + 1, cf_meta_data.levels.size() - 1);
|
|
|
|
auto s = db_->CompactFiles(CompactionOptions(), column_family,
|
|
|
|
input_files, static_cast<int>(output_level));
|
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stdout, "Unable to perform CompactFiles(): %s\n",
|
|
|
|
s.ToString().c_str());
|
|
|
|
thread->stats.AddNumCompactFilesFailed(1);
|
|
|
|
} else {
|
|
|
|
thread->stats.AddNumCompactFilesSucceed(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
|
2019-12-19 23:03:14 +01:00
|
|
|
Status StressTest::TestFlush(const std::vector<int>& rand_column_families) {
|
|
|
|
FlushOptions flush_opts;
|
2022-01-06 01:12:12 +01:00
|
|
|
if (FLAGS_atomic_flush) {
|
|
|
|
return db_->Flush(flush_opts, column_families_);
|
|
|
|
}
|
2019-12-19 23:03:14 +01:00
|
|
|
std::vector<ColumnFamilyHandle*> cfhs;
|
|
|
|
std::for_each(rand_column_families.begin(), rand_column_families.end(),
|
|
|
|
[this, &cfhs](int k) { cfhs.push_back(column_families_[k]); });
|
|
|
|
return db_->Flush(flush_opts, cfhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status StressTest::TestPauseBackground(ThreadState* thread) {
|
|
|
|
Status status = db_->PauseBackgroundWork();
|
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
// To avoid stalling/deadlocking ourself in this thread, just
|
|
|
|
// sleep here during pause and let other threads do db operations.
|
|
|
|
// Sleep up to ~16 seconds (2**24 microseconds), but very skewed
|
|
|
|
// toward short pause. (1 chance in 25 of pausing >= 1s;
|
|
|
|
// 1 chance in 625 of pausing full 16s.)
|
|
|
|
int pwr2_micros =
|
|
|
|
std::min(thread->rand.Uniform(25), thread->rand.Uniform(25));
|
2021-03-15 12:32:24 +01:00
|
|
|
clock_->SleepForMicroseconds(1 << pwr2_micros);
|
2019-12-19 23:03:14 +01:00
|
|
|
return db_->ContinueBackgroundWork();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StressTest::TestAcquireSnapshot(ThreadState* thread,
|
|
|
|
int rand_column_family,
|
|
|
|
const std::string& keystr, uint64_t i) {
|
|
|
|
Slice key = keystr;
|
|
|
|
ColumnFamilyHandle* column_family = column_families_[rand_column_family];
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
ReadOptions ropt;
|
2019-12-19 23:03:14 +01:00
|
|
|
#ifndef ROCKSDB_LITE
|
2020-07-03 04:24:25 +02:00
|
|
|
auto db_impl = static_cast_with_check<DBImpl>(db_->GetRootDB());
|
2019-12-19 23:03:14 +01:00
|
|
|
const bool ww_snapshot = thread->rand.OneIn(10);
|
|
|
|
const Snapshot* snapshot =
|
|
|
|
ww_snapshot ? db_impl->GetSnapshotForWriteConflictBoundary()
|
|
|
|
: db_->GetSnapshot();
|
|
|
|
#else
|
|
|
|
const Snapshot* snapshot = db_->GetSnapshot();
|
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
ropt.snapshot = snapshot;
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
|
|
|
|
// Ideally, we want snapshot taking and timestamp generation to be atomic
|
|
|
|
// here, so that the snapshot corresponds to the timestamp. However, it is
|
|
|
|
// not possible with current GetSnapshot() API.
|
|
|
|
std::string ts_str;
|
|
|
|
Slice ts;
|
|
|
|
if (FLAGS_user_timestamp_size > 0) {
|
|
|
|
ts_str = GenerateTimestampForRead();
|
|
|
|
ts = ts_str;
|
|
|
|
ropt.timestamp = &ts;
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:03:14 +01:00
|
|
|
std::string value_at;
|
|
|
|
// When taking a snapshot, we also read a key from that snapshot. We
|
|
|
|
// will later read the same key before releasing the snapshot and
|
|
|
|
// verify that the results are the same.
|
|
|
|
auto status_at = db_->Get(ropt, column_family, key, &value_at);
|
|
|
|
std::vector<bool>* key_vec = nullptr;
|
|
|
|
|
|
|
|
if (FLAGS_compare_full_db_state_snapshot && (thread->tid == 0)) {
|
|
|
|
key_vec = new std::vector<bool>(FLAGS_max_key);
|
|
|
|
// When `prefix_extractor` is set, seeking to beginning and scanning
|
|
|
|
// across prefixes are only supported with `total_order_seek` set.
|
|
|
|
ropt.total_order_seek = true;
|
|
|
|
std::unique_ptr<Iterator> iterator(db_->NewIterator(ropt));
|
|
|
|
for (iterator->SeekToFirst(); iterator->Valid(); iterator->Next()) {
|
|
|
|
uint64_t key_val;
|
|
|
|
if (GetIntVal(iterator->key().ToString(), &key_val)) {
|
|
|
|
(*key_vec)[key_val] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
ThreadState::SnapshotState snap_state = {snapshot,
|
|
|
|
rand_column_family,
|
|
|
|
column_family->GetName(),
|
|
|
|
keystr,
|
|
|
|
status_at,
|
|
|
|
value_at,
|
|
|
|
key_vec,
|
|
|
|
ts_str};
|
2019-12-19 23:03:14 +01:00
|
|
|
uint64_t hold_for = FLAGS_snapshot_hold_ops;
|
|
|
|
if (FLAGS_long_running_snapshots) {
|
|
|
|
// Hold 10% of snapshots for 10x more
|
|
|
|
if (thread->rand.OneIn(10)) {
|
|
|
|
assert(hold_for < port::kMaxInt64 / 10);
|
|
|
|
hold_for *= 10;
|
|
|
|
// Hold 1% of snapshots for 100x more
|
|
|
|
if (thread->rand.OneIn(10)) {
|
|
|
|
assert(hold_for < port::kMaxInt64 / 10);
|
|
|
|
hold_for *= 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint64_t release_at = std::min(FLAGS_ops_per_thread - 1, i + hold_for);
|
|
|
|
thread->snapshot_queue.emplace(release_at, snap_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status StressTest::MaybeReleaseSnapshots(ThreadState* thread, uint64_t i) {
|
|
|
|
while (!thread->snapshot_queue.empty() &&
|
|
|
|
i >= thread->snapshot_queue.front().first) {
|
|
|
|
auto snap_state = thread->snapshot_queue.front().second;
|
|
|
|
assert(snap_state.snapshot);
|
|
|
|
// Note: this is unsafe as the cf might be dropped concurrently. But
|
|
|
|
// it is ok since unclean cf drop is cunnrently not supported by write
|
|
|
|
// prepared transactions.
|
|
|
|
Status s = AssertSame(db_, column_families_[snap_state.cf_at], snap_state);
|
|
|
|
db_->ReleaseSnapshot(snap_state.snapshot);
|
|
|
|
delete snap_state.key_vec;
|
|
|
|
thread->snapshot_queue.pop();
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2019-12-10 20:40:09 +01:00
|
|
|
void StressTest::TestCompactRange(ThreadState* thread, int64_t rand_key,
|
|
|
|
const Slice& start_key,
|
|
|
|
ColumnFamilyHandle* column_family) {
|
|
|
|
int64_t end_key_num;
|
|
|
|
if (port::kMaxInt64 - rand_key < FLAGS_compact_range_width) {
|
|
|
|
end_key_num = port::kMaxInt64;
|
|
|
|
} else {
|
|
|
|
end_key_num = FLAGS_compact_range_width + rand_key;
|
|
|
|
}
|
|
|
|
std::string end_key_buf = Key(end_key_num);
|
|
|
|
Slice end_key(end_key_buf);
|
|
|
|
|
|
|
|
CompactRangeOptions cro;
|
|
|
|
cro.exclusive_manual_compaction = static_cast<bool>(thread->rand.Next() % 2);
|
|
|
|
cro.change_level = static_cast<bool>(thread->rand.Next() % 2);
|
|
|
|
std::vector<BottommostLevelCompaction> bottom_level_styles = {
|
|
|
|
BottommostLevelCompaction::kSkip,
|
|
|
|
BottommostLevelCompaction::kIfHaveCompactionFilter,
|
|
|
|
BottommostLevelCompaction::kForce,
|
|
|
|
BottommostLevelCompaction::kForceOptimized};
|
|
|
|
cro.bottommost_level_compaction =
|
|
|
|
bottom_level_styles[thread->rand.Next() %
|
|
|
|
static_cast<uint32_t>(bottom_level_styles.size())];
|
|
|
|
cro.allow_write_stall = static_cast<bool>(thread->rand.Next() % 2);
|
|
|
|
cro.max_subcompactions = static_cast<uint32_t>(thread->rand.Next() % 4);
|
|
|
|
|
|
|
|
const Snapshot* pre_snapshot = nullptr;
|
2020-01-31 01:05:44 +01:00
|
|
|
uint32_t pre_hash = 0;
|
2019-12-10 20:40:09 +01:00
|
|
|
if (thread->rand.OneIn(2)) {
|
|
|
|
// Do some validation by declaring a snapshot and compare the data before
|
|
|
|
// and after the compaction
|
|
|
|
pre_snapshot = db_->GetSnapshot();
|
|
|
|
pre_hash =
|
|
|
|
GetRangeHash(thread, pre_snapshot, column_family, start_key, end_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
Status status = db_->CompactRange(cro, column_family, &start_key, &end_key);
|
|
|
|
|
|
|
|
if (!status.ok()) {
|
2019-12-20 17:46:52 +01:00
|
|
|
fprintf(stdout, "Unable to perform CompactRange(): %s\n",
|
|
|
|
status.ToString().c_str());
|
2019-12-10 20:40:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pre_snapshot != nullptr) {
|
|
|
|
uint32_t post_hash =
|
|
|
|
GetRangeHash(thread, pre_snapshot, column_family, start_key, end_key);
|
|
|
|
if (pre_hash != post_hash) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Data hash different before and after compact range "
|
|
|
|
"start_key %s end_key %s\n",
|
|
|
|
start_key.ToString(true).c_str(), end_key.ToString(true).c_str());
|
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
// Fail fast to preserve the DB state.
|
|
|
|
thread->shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
db_->ReleaseSnapshot(pre_snapshot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t StressTest::GetRangeHash(ThreadState* thread, const Snapshot* snapshot,
|
|
|
|
ColumnFamilyHandle* column_family,
|
|
|
|
const Slice& start_key,
|
|
|
|
const Slice& end_key) {
|
|
|
|
const std::string kCrcCalculatorSepearator = ";";
|
|
|
|
uint32_t crc = 0;
|
|
|
|
ReadOptions ro;
|
|
|
|
ro.snapshot = snapshot;
|
|
|
|
ro.total_order_seek = true;
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
std::string ts_str;
|
|
|
|
Slice ts;
|
|
|
|
if (FLAGS_user_timestamp_size > 0) {
|
|
|
|
ts_str = GenerateTimestampForRead();
|
|
|
|
ts = ts_str;
|
|
|
|
ro.timestamp = &ts;
|
|
|
|
}
|
2019-12-10 20:40:09 +01:00
|
|
|
std::unique_ptr<Iterator> it(db_->NewIterator(ro, column_family));
|
|
|
|
for (it->Seek(start_key);
|
|
|
|
it->Valid() && options_.comparator->Compare(it->key(), end_key) <= 0;
|
|
|
|
it->Next()) {
|
|
|
|
crc = crc32c::Extend(crc, it->key().data(), it->key().size());
|
|
|
|
crc = crc32c::Extend(crc, kCrcCalculatorSepearator.data(), 1);
|
|
|
|
crc = crc32c::Extend(crc, it->value().data(), it->value().size());
|
|
|
|
crc = crc32c::Extend(crc, kCrcCalculatorSepearator.data(), 1);
|
|
|
|
}
|
|
|
|
if (!it->status().ok()) {
|
|
|
|
fprintf(stderr, "Iterator non-OK when calculating range CRC: %s\n",
|
|
|
|
it->status().ToString().c_str());
|
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
// Fail fast to preserve the DB state.
|
|
|
|
thread->shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
void StressTest::PrintEnv() const {
|
|
|
|
fprintf(stdout, "RocksDB version : %d.%d\n", kMajorVersion,
|
|
|
|
kMinorVersion);
|
|
|
|
fprintf(stdout, "Format version : %d\n", FLAGS_format_version);
|
|
|
|
fprintf(stdout, "TransactionDB : %s\n",
|
|
|
|
FLAGS_use_txn ? "true" : "false");
|
2019-12-20 19:25:48 +01:00
|
|
|
#ifndef ROCKSDB_LITE
|
2021-02-02 20:39:20 +01:00
|
|
|
fprintf(stdout, "Stacked BlobDB : %s\n",
|
2019-12-20 19:25:48 +01:00
|
|
|
FLAGS_use_blob_db ? "true" : "false");
|
|
|
|
#endif // !ROCKSDB_LITE
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, "Read only mode : %s\n",
|
|
|
|
FLAGS_read_only ? "true" : "false");
|
|
|
|
fprintf(stdout, "Atomic flush : %s\n",
|
|
|
|
FLAGS_atomic_flush ? "true" : "false");
|
|
|
|
fprintf(stdout, "Column families : %d\n", FLAGS_column_families);
|
|
|
|
if (!FLAGS_test_batches_snapshots) {
|
|
|
|
fprintf(stdout, "Clear CFs one in : %d\n",
|
|
|
|
FLAGS_clear_column_family_one_in);
|
|
|
|
}
|
|
|
|
fprintf(stdout, "Number of threads : %d\n", FLAGS_threads);
|
|
|
|
fprintf(stdout, "Ops per thread : %lu\n",
|
|
|
|
(unsigned long)FLAGS_ops_per_thread);
|
|
|
|
std::string ttl_state("unused");
|
|
|
|
if (FLAGS_ttl > 0) {
|
2021-09-01 23:14:50 +02:00
|
|
|
ttl_state = ToString(FLAGS_ttl);
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
fprintf(stdout, "Time to live(sec) : %s\n", ttl_state.c_str());
|
|
|
|
fprintf(stdout, "Read percentage : %d%%\n", FLAGS_readpercent);
|
|
|
|
fprintf(stdout, "Prefix percentage : %d%%\n", FLAGS_prefixpercent);
|
|
|
|
fprintf(stdout, "Write percentage : %d%%\n", FLAGS_writepercent);
|
|
|
|
fprintf(stdout, "Delete percentage : %d%%\n", FLAGS_delpercent);
|
|
|
|
fprintf(stdout, "Delete range percentage : %d%%\n", FLAGS_delrangepercent);
|
|
|
|
fprintf(stdout, "No overwrite percentage : %d%%\n",
|
|
|
|
FLAGS_nooverwritepercent);
|
|
|
|
fprintf(stdout, "Iterate percentage : %d%%\n", FLAGS_iterpercent);
|
2021-12-14 22:33:16 +01:00
|
|
|
fprintf(stdout, "Custom ops percentage : %d%%\n", FLAGS_customopspercent);
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, "DB-write-buffer-size : %" PRIu64 "\n",
|
|
|
|
FLAGS_db_write_buffer_size);
|
|
|
|
fprintf(stdout, "Write-buffer-size : %d\n", FLAGS_write_buffer_size);
|
|
|
|
fprintf(stdout, "Iterations : %lu\n",
|
|
|
|
(unsigned long)FLAGS_num_iterations);
|
|
|
|
fprintf(stdout, "Max key : %lu\n",
|
|
|
|
(unsigned long)FLAGS_max_key);
|
|
|
|
fprintf(stdout, "Ratio #ops/#keys : %f\n",
|
|
|
|
(1.0 * FLAGS_ops_per_thread * FLAGS_threads) / FLAGS_max_key);
|
|
|
|
fprintf(stdout, "Num times DB reopens : %d\n", FLAGS_reopen);
|
|
|
|
fprintf(stdout, "Batches/snapshots : %d\n",
|
|
|
|
FLAGS_test_batches_snapshots);
|
|
|
|
fprintf(stdout, "Do update in place : %d\n", FLAGS_in_place_update);
|
|
|
|
fprintf(stdout, "Num keys per lock : %d\n",
|
|
|
|
1 << FLAGS_log2_keys_per_lock);
|
2019-12-21 01:13:19 +01:00
|
|
|
std::string compression = CompressionTypeToString(compression_type_e);
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, "Compression : %s\n", compression.c_str());
|
2019-12-21 01:13:19 +01:00
|
|
|
std::string bottommost_compression =
|
|
|
|
CompressionTypeToString(bottommost_compression_type_e);
|
|
|
|
fprintf(stdout, "Bottommost Compression : %s\n",
|
|
|
|
bottommost_compression.c_str());
|
|
|
|
std::string checksum = ChecksumTypeToString(checksum_type_e);
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, "Checksum type : %s\n", checksum.c_str());
|
2020-09-04 08:49:27 +02:00
|
|
|
fprintf(stdout, "File checksum impl : %s\n",
|
|
|
|
FLAGS_file_checksum_impl.c_str());
|
2019-12-10 17:38:23 +01:00
|
|
|
fprintf(stdout, "Bloom bits / key : %s\n",
|
|
|
|
FormatDoubleParam(FLAGS_bloom_bits).c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, "Max subcompactions : %" PRIu64 "\n",
|
|
|
|
FLAGS_subcompactions);
|
|
|
|
fprintf(stdout, "Use MultiGet : %s\n",
|
|
|
|
FLAGS_use_multiget ? "true" : "false");
|
|
|
|
|
|
|
|
const char* memtablerep = "";
|
|
|
|
switch (FLAGS_rep_factory) {
|
|
|
|
case kSkipList:
|
|
|
|
memtablerep = "skip_list";
|
|
|
|
break;
|
|
|
|
case kHashSkipList:
|
|
|
|
memtablerep = "prefix_hash";
|
|
|
|
break;
|
|
|
|
case kVectorRep:
|
|
|
|
memtablerep = "vector";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stdout, "Memtablerep : %s\n", memtablerep);
|
|
|
|
|
2021-05-06 00:49:29 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
KillPoint* kp = KillPoint::GetInstance();
|
|
|
|
fprintf(stdout, "Test kill odd : %d\n", kp->rocksdb_kill_odds);
|
|
|
|
if (!kp->rocksdb_kill_exclude_prefixes.empty()) {
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, "Skipping kill points prefixes:\n");
|
2021-05-06 00:49:29 +02:00
|
|
|
for (auto& p : kp->rocksdb_kill_exclude_prefixes) {
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, " %s\n", p.c_str());
|
|
|
|
}
|
|
|
|
}
|
2021-05-06 00:49:29 +02:00
|
|
|
#endif
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, "Periodic Compaction Secs : %" PRIu64 "\n",
|
|
|
|
FLAGS_periodic_compaction_seconds);
|
|
|
|
fprintf(stdout, "Compaction TTL : %" PRIu64 "\n",
|
|
|
|
FLAGS_compaction_ttl);
|
2019-12-17 00:24:26 +01:00
|
|
|
fprintf(stdout, "Background Purge : %d\n",
|
|
|
|
static_cast<int>(FLAGS_avoid_unnecessary_blocking_io));
|
|
|
|
fprintf(stdout, "Write DB ID to manifest : %d\n",
|
|
|
|
static_cast<int>(FLAGS_write_dbid_to_manifest));
|
|
|
|
fprintf(stdout, "Max Write Batch Group Size: %" PRIu64 "\n",
|
|
|
|
FLAGS_max_write_batch_group_size_bytes);
|
|
|
|
fprintf(stdout, "Use dynamic level : %d\n",
|
|
|
|
static_cast<int>(FLAGS_level_compaction_dynamic_level_bytes));
|
2020-04-11 02:18:56 +02:00
|
|
|
fprintf(stdout, "Read fault one in : %d\n", FLAGS_read_fault_one_in);
|
2020-12-17 20:51:04 +01:00
|
|
|
fprintf(stdout, "Write fault one in : %d\n", FLAGS_write_fault_one_in);
|
2021-04-28 19:57:11 +02:00
|
|
|
fprintf(stdout, "Open metadata write fault one in:\n");
|
|
|
|
fprintf(stdout, " %d\n",
|
|
|
|
FLAGS_open_metadata_write_fault_one_in);
|
2020-04-16 20:10:53 +02:00
|
|
|
fprintf(stdout, "Sync fault injection : %d\n", FLAGS_sync_fault_injection);
|
2020-06-13 04:24:11 +02:00
|
|
|
fprintf(stdout, "Best efforts recovery : %d\n",
|
|
|
|
static_cast<int>(FLAGS_best_efforts_recovery));
|
2021-05-05 21:53:42 +02:00
|
|
|
fprintf(stdout, "Fail if OPTIONS file error: %d\n",
|
|
|
|
static_cast<int>(FLAGS_fail_if_options_file_error));
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
fprintf(stdout, "User timestamp size bytes : %d\n",
|
|
|
|
static_cast<int>(FLAGS_user_timestamp_size));
|
2019-12-09 08:49:32 +01:00
|
|
|
|
|
|
|
fprintf(stdout, "------------------------------------------------\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void StressTest::Open() {
|
|
|
|
assert(db_ == nullptr);
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
assert(txn_db_ == nullptr);
|
|
|
|
#endif
|
|
|
|
if (FLAGS_options_file.empty()) {
|
|
|
|
BlockBasedTableOptions block_based_options;
|
|
|
|
block_based_options.block_cache = cache_;
|
|
|
|
block_based_options.cache_index_and_filter_blocks =
|
|
|
|
FLAGS_cache_index_and_filter_blocks;
|
2020-10-11 23:52:49 +02:00
|
|
|
block_based_options.metadata_cache_options.top_level_index_pinning =
|
|
|
|
static_cast<PinningTier>(FLAGS_top_level_index_pinning);
|
|
|
|
block_based_options.metadata_cache_options.partition_pinning =
|
|
|
|
static_cast<PinningTier>(FLAGS_partition_pinning);
|
|
|
|
block_based_options.metadata_cache_options.unpartitioned_pinning =
|
|
|
|
static_cast<PinningTier>(FLAGS_unpartitioned_pinning);
|
2019-12-09 08:49:32 +01:00
|
|
|
block_based_options.block_cache_compressed = compressed_cache_;
|
2019-12-21 01:13:19 +01:00
|
|
|
block_based_options.checksum = checksum_type_e;
|
2019-12-09 08:49:32 +01:00
|
|
|
block_based_options.block_size = FLAGS_block_size;
|
|
|
|
block_based_options.format_version =
|
|
|
|
static_cast<uint32_t>(FLAGS_format_version);
|
|
|
|
block_based_options.index_block_restart_interval =
|
|
|
|
static_cast<int32_t>(FLAGS_index_block_restart_interval);
|
|
|
|
block_based_options.filter_policy = filter_policy_;
|
|
|
|
block_based_options.partition_filters = FLAGS_partition_filters;
|
Minimize memory internal fragmentation for Bloom filters (#6427)
Summary:
New experimental option BBTO::optimize_filters_for_memory builds
filters that maximize their use of "usable size" from malloc_usable_size,
which is also used to compute block cache charges.
Rather than always "rounding up," we track state in the
BloomFilterPolicy object to mix essentially "rounding down" and
"rounding up" so that the average FP rate of all generated filters is
the same as without the option. (YMMV as heavily accessed filters might
be unluckily lower accuracy.)
Thus, the option near-minimizes what the block cache considers as
"memory used" for a given target Bloom filter false positive rate and
Bloom filter implementation. There are no forward or backward
compatibility issues with this change, though it only works on the
format_version=5 Bloom filter.
With Jemalloc, we see about 10% reduction in memory footprint (and block
cache charge) for Bloom filters, but 1-2% increase in storage footprint,
due to encoding efficiency losses (FP rate is non-linear with bits/key).
Why not weighted random round up/down rather than state tracking? By
only requiring malloc_usable_size, we don't actually know what the next
larger and next smaller usable sizes for the allocator are. We pick a
requested size, accept and use whatever usable size it has, and use the
difference to inform our next choice. This allows us to narrow in on the
right balance without tracking/predicting usable sizes.
Why not weight history of generated filter false positive rates by
number of keys? This could lead to excess skew in small filters after
generating a large filter.
Results from filter_bench with jemalloc (irrelevant details omitted):
(normal keys/filter, but high variance)
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=30000 -vary_key_count_ratio=0.9
Build avg ns/key: 29.6278
Number of filters: 5516
Total size (MB): 200.046
Reported total allocated memory (MB): 220.597
Reported internal fragmentation: 10.2732%
Bits/key stored: 10.0097
Average FP rate %: 0.965228
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=30000 -vary_key_count_ratio=0.9 -optimize_filters_for_memory
Build avg ns/key: 30.5104
Number of filters: 5464
Total size (MB): 200.015
Reported total allocated memory (MB): 200.322
Reported internal fragmentation: 0.153709%
Bits/key stored: 10.1011
Average FP rate %: 0.966313
(very few keys / filter, optimization not as effective due to ~59 byte
internal fragmentation in blocked Bloom filter representation)
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=1000 -vary_key_count_ratio=0.9
Build avg ns/key: 29.5649
Number of filters: 162950
Total size (MB): 200.001
Reported total allocated memory (MB): 224.624
Reported internal fragmentation: 12.3117%
Bits/key stored: 10.2951
Average FP rate %: 0.821534
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=1000 -vary_key_count_ratio=0.9 -optimize_filters_for_memory
Build avg ns/key: 31.8057
Number of filters: 159849
Total size (MB): 200
Reported total allocated memory (MB): 208.846
Reported internal fragmentation: 4.42297%
Bits/key stored: 10.4948
Average FP rate %: 0.811006
(high keys/filter)
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=1000000 -vary_key_count_ratio=0.9
Build avg ns/key: 29.7017
Number of filters: 164
Total size (MB): 200.352
Reported total allocated memory (MB): 221.5
Reported internal fragmentation: 10.5552%
Bits/key stored: 10.0003
Average FP rate %: 0.969358
$ ./filter_bench -quick -impl=2 -average_keys_per_filter=1000000 -vary_key_count_ratio=0.9 -optimize_filters_for_memory
Build avg ns/key: 30.7131
Number of filters: 160
Total size (MB): 200.928
Reported total allocated memory (MB): 200.938
Reported internal fragmentation: 0.00448054%
Bits/key stored: 10.1852
Average FP rate %: 0.963387
And from db_bench (block cache) with jemalloc:
$ ./db_bench -db=/dev/shm/dbbench.no_optimize -benchmarks=fillrandom -format_version=5 -value_size=90 -bloom_bits=10 -num=2000000 -threads=8 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=false
$ ./db_bench -db=/dev/shm/dbbench -benchmarks=fillrandom -format_version=5 -value_size=90 -bloom_bits=10 -num=2000000 -threads=8 -optimize_filters_for_memory -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=false
$ (for FILE in /dev/shm/dbbench.no_optimize/*.sst; do ./sst_dump --file=$FILE --show_properties | grep 'filter block' ; done) | awk '{ t += $4; } END { print t; }'
17063835
$ (for FILE in /dev/shm/dbbench/*.sst; do ./sst_dump --file=$FILE --show_properties | grep 'filter block' ; done) | awk '{ t += $4; } END { print t; }'
17430747
$ #^ 2.1% additional filter storage
$ ./db_bench -db=/dev/shm/dbbench.no_optimize -use_existing_db -benchmarks=readrandom,stats -statistics -bloom_bits=10 -num=2000000 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=false -duration=10 -cache_index_and_filter_blocks -cache_size=1000000000
rocksdb.block.cache.index.add COUNT : 33
rocksdb.block.cache.index.bytes.insert COUNT : 8440400
rocksdb.block.cache.filter.add COUNT : 33
rocksdb.block.cache.filter.bytes.insert COUNT : 21087528
rocksdb.bloom.filter.useful COUNT : 4963889
rocksdb.bloom.filter.full.positive COUNT : 1214081
rocksdb.bloom.filter.full.true.positive COUNT : 1161999
$ #^ 1.04 % observed FP rate
$ ./db_bench -db=/dev/shm/dbbench -use_existing_db -benchmarks=readrandom,stats -statistics -bloom_bits=10 -num=2000000 -compaction_style=2 -fifo_compaction_max_table_files_size_mb=10000 -fifo_compaction_allow_compaction=false -optimize_filters_for_memory -duration=10 -cache_index_and_filter_blocks -cache_size=1000000000
rocksdb.block.cache.index.add COUNT : 33
rocksdb.block.cache.index.bytes.insert COUNT : 8448592
rocksdb.block.cache.filter.add COUNT : 33
rocksdb.block.cache.filter.bytes.insert COUNT : 18220328
rocksdb.bloom.filter.useful COUNT : 5360933
rocksdb.bloom.filter.full.positive COUNT : 1321315
rocksdb.bloom.filter.full.true.positive COUNT : 1262999
$ #^ 1.08 % observed FP rate, 13.6% less memory usage for filters
(Due to specific key density, this example tends to generate filters that are "worse than average" for internal fragmentation. "Better than average" cases can show little or no improvement.)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6427
Test Plan: unit test added, 'make check' with gcc, clang and valgrind
Reviewed By: siying
Differential Revision: D22124374
Pulled By: pdillinger
fbshipit-source-id: f3e3aa152f9043ddf4fae25799e76341d0d8714e
2020-06-22 22:30:57 +02:00
|
|
|
block_based_options.optimize_filters_for_memory =
|
|
|
|
FLAGS_optimize_filters_for_memory;
|
2019-12-09 08:49:32 +01:00
|
|
|
block_based_options.index_type =
|
|
|
|
static_cast<BlockBasedTableOptions::IndexType>(FLAGS_index_type);
|
2021-12-08 21:43:09 +01:00
|
|
|
block_based_options.prepopulate_block_cache =
|
|
|
|
static_cast<BlockBasedTableOptions::PrepopulateBlockCache>(
|
|
|
|
FLAGS_prepopulate_block_cache);
|
2019-12-09 08:49:32 +01:00
|
|
|
options_.table_factory.reset(
|
|
|
|
NewBlockBasedTableFactory(block_based_options));
|
|
|
|
options_.db_write_buffer_size = FLAGS_db_write_buffer_size;
|
|
|
|
options_.write_buffer_size = FLAGS_write_buffer_size;
|
|
|
|
options_.max_write_buffer_number = FLAGS_max_write_buffer_number;
|
|
|
|
options_.min_write_buffer_number_to_merge =
|
|
|
|
FLAGS_min_write_buffer_number_to_merge;
|
|
|
|
options_.max_write_buffer_number_to_maintain =
|
|
|
|
FLAGS_max_write_buffer_number_to_maintain;
|
|
|
|
options_.max_write_buffer_size_to_maintain =
|
|
|
|
FLAGS_max_write_buffer_size_to_maintain;
|
|
|
|
options_.memtable_prefix_bloom_size_ratio =
|
|
|
|
FLAGS_memtable_prefix_bloom_size_ratio;
|
|
|
|
options_.memtable_whole_key_filtering = FLAGS_memtable_whole_key_filtering;
|
|
|
|
options_.max_background_compactions = FLAGS_max_background_compactions;
|
|
|
|
options_.max_background_flushes = FLAGS_max_background_flushes;
|
|
|
|
options_.compaction_style =
|
2020-02-20 21:07:53 +01:00
|
|
|
static_cast<ROCKSDB_NAMESPACE::CompactionStyle>(FLAGS_compaction_style);
|
2019-12-09 08:49:32 +01:00
|
|
|
if (FLAGS_prefix_size >= 0) {
|
|
|
|
options_.prefix_extractor.reset(
|
|
|
|
NewFixedPrefixTransform(FLAGS_prefix_size));
|
|
|
|
}
|
|
|
|
options_.max_open_files = FLAGS_open_files;
|
|
|
|
options_.statistics = dbstats;
|
2019-12-21 01:13:19 +01:00
|
|
|
options_.env = db_stress_env;
|
2019-12-09 08:49:32 +01:00
|
|
|
options_.use_fsync = FLAGS_use_fsync;
|
|
|
|
options_.compaction_readahead_size = FLAGS_compaction_readahead_size;
|
|
|
|
options_.allow_mmap_reads = FLAGS_mmap_read;
|
|
|
|
options_.allow_mmap_writes = FLAGS_mmap_write;
|
|
|
|
options_.use_direct_reads = FLAGS_use_direct_reads;
|
|
|
|
options_.use_direct_io_for_flush_and_compaction =
|
|
|
|
FLAGS_use_direct_io_for_flush_and_compaction;
|
|
|
|
options_.recycle_log_file_num =
|
|
|
|
static_cast<size_t>(FLAGS_recycle_log_file_num);
|
|
|
|
options_.target_file_size_base = FLAGS_target_file_size_base;
|
|
|
|
options_.target_file_size_multiplier = FLAGS_target_file_size_multiplier;
|
|
|
|
options_.max_bytes_for_level_base = FLAGS_max_bytes_for_level_base;
|
|
|
|
options_.max_bytes_for_level_multiplier =
|
|
|
|
FLAGS_max_bytes_for_level_multiplier;
|
|
|
|
options_.level0_stop_writes_trigger = FLAGS_level0_stop_writes_trigger;
|
|
|
|
options_.level0_slowdown_writes_trigger =
|
|
|
|
FLAGS_level0_slowdown_writes_trigger;
|
|
|
|
options_.level0_file_num_compaction_trigger =
|
|
|
|
FLAGS_level0_file_num_compaction_trigger;
|
2019-12-21 01:13:19 +01:00
|
|
|
options_.compression = compression_type_e;
|
|
|
|
options_.bottommost_compression = bottommost_compression_type_e;
|
2019-12-09 08:49:32 +01:00
|
|
|
options_.compression_opts.max_dict_bytes = FLAGS_compression_max_dict_bytes;
|
|
|
|
options_.compression_opts.zstd_max_train_bytes =
|
|
|
|
FLAGS_compression_zstd_max_train_bytes;
|
2020-04-30 19:46:54 +02:00
|
|
|
options_.compression_opts.parallel_threads =
|
|
|
|
FLAGS_compression_parallel_threads;
|
Limit buffering for collecting samples for compression dictionary (#7970)
Summary:
For dictionary compression, we need to collect some representative samples of the data to be compressed, which we use to either generate or train (when `CompressionOptions::zstd_max_train_bytes > 0`) a dictionary. Previously, the strategy was to buffer all the data blocks during flush, and up to the target file size during compaction. That strategy allowed us to randomly pick samples from as wide a range as possible that'd be guaranteed to land in a single output file.
However, some users try to make huge files in memory-constrained environments, where this strategy can cause OOM. This PR introduces an option, `CompressionOptions::max_dict_buffer_bytes`, that limits how much data blocks are buffered before we switch to unbuffered mode (which means creating the per-SST dictionary, writing out the buffered data, and compressing/writing new blocks as soon as they are built). It is not strict as we currently buffer more than just data blocks -- also keys are buffered. But it does make a step towards giving users predictable memory usage.
Related changes include:
- Changed sampling for dictionary compression to select unique data blocks when there is limited availability of data blocks
- Made use of `BlockBuilder::SwapAndReset()` to save an allocation+memcpy when buffering data blocks for building a dictionary
- Changed `ParseBoolean()` to accept an input containing characters after the boolean. This is necessary since, with this PR, a value for `CompressionOptions::enabled` is no longer necessarily the final component in the `CompressionOptions` string.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7970
Test Plan:
- updated `CompressionOptions` unit tests to verify limit is respected (to the extent expected in the current implementation) in various scenarios of flush/compaction to bottommost/non-bottommost level
- looked at jemalloc heap profiles right before and after switching to unbuffered mode during flush/compaction. Verified memory usage in buffering is proportional to the limit set.
Reviewed By: pdillinger
Differential Revision: D26467994
Pulled By: ajkr
fbshipit-source-id: 3da4ef9fba59974e4ef40e40c01611002c861465
2021-02-19 23:06:59 +01:00
|
|
|
options_.compression_opts.max_dict_buffer_bytes =
|
|
|
|
FLAGS_compression_max_dict_buffer_bytes;
|
2019-12-09 08:49:32 +01:00
|
|
|
options_.create_if_missing = true;
|
|
|
|
options_.max_manifest_file_size = FLAGS_max_manifest_file_size;
|
|
|
|
options_.inplace_update_support = FLAGS_in_place_update;
|
|
|
|
options_.max_subcompactions = static_cast<uint32_t>(FLAGS_subcompactions);
|
|
|
|
options_.allow_concurrent_memtable_write =
|
|
|
|
FLAGS_allow_concurrent_memtable_write;
|
2021-08-11 03:07:48 +02:00
|
|
|
options_.experimental_mempurge_threshold =
|
|
|
|
FLAGS_experimental_mempurge_threshold;
|
2019-12-09 08:49:32 +01:00
|
|
|
options_.periodic_compaction_seconds = FLAGS_periodic_compaction_seconds;
|
|
|
|
options_.ttl = FLAGS_compaction_ttl;
|
|
|
|
options_.enable_pipelined_write = FLAGS_enable_pipelined_write;
|
|
|
|
options_.enable_write_thread_adaptive_yield =
|
|
|
|
FLAGS_enable_write_thread_adaptive_yield;
|
|
|
|
options_.compaction_options_universal.size_ratio =
|
|
|
|
FLAGS_universal_size_ratio;
|
|
|
|
options_.compaction_options_universal.min_merge_width =
|
|
|
|
FLAGS_universal_min_merge_width;
|
|
|
|
options_.compaction_options_universal.max_merge_width =
|
|
|
|
FLAGS_universal_max_merge_width;
|
|
|
|
options_.compaction_options_universal.max_size_amplification_percent =
|
|
|
|
FLAGS_universal_max_size_amplification_percent;
|
|
|
|
options_.atomic_flush = FLAGS_atomic_flush;
|
2019-12-17 00:24:26 +01:00
|
|
|
options_.avoid_unnecessary_blocking_io =
|
|
|
|
FLAGS_avoid_unnecessary_blocking_io;
|
|
|
|
options_.write_dbid_to_manifest = FLAGS_write_dbid_to_manifest;
|
2020-04-16 21:09:18 +02:00
|
|
|
options_.avoid_flush_during_recovery = FLAGS_avoid_flush_during_recovery;
|
2019-12-17 00:24:26 +01:00
|
|
|
options_.max_write_batch_group_size_bytes =
|
|
|
|
FLAGS_max_write_batch_group_size_bytes;
|
|
|
|
options_.level_compaction_dynamic_level_bytes =
|
|
|
|
FLAGS_level_compaction_dynamic_level_bytes;
|
2020-09-04 08:49:27 +02:00
|
|
|
options_.file_checksum_gen_factory =
|
|
|
|
GetFileChecksumImpl(FLAGS_file_checksum_impl);
|
2020-11-09 17:42:41 +01:00
|
|
|
options_.track_and_verify_wals_in_manifest = true;
|
2021-02-02 20:39:20 +01:00
|
|
|
|
|
|
|
// Integrated BlobDB
|
|
|
|
options_.enable_blob_files = FLAGS_enable_blob_files;
|
|
|
|
options_.min_blob_size = FLAGS_min_blob_size;
|
|
|
|
options_.blob_file_size = FLAGS_blob_file_size;
|
|
|
|
options_.blob_compression_type =
|
|
|
|
StringToCompressionType(FLAGS_blob_compression_type.c_str());
|
|
|
|
options_.enable_blob_garbage_collection =
|
|
|
|
FLAGS_enable_blob_garbage_collection;
|
|
|
|
options_.blob_garbage_collection_age_cutoff =
|
|
|
|
FLAGS_blob_garbage_collection_age_cutoff;
|
Make it possible to force the garbage collection of the oldest blob files (#8994)
Summary:
The current BlobDB garbage collection logic works by relocating the valid
blobs from the oldest blob files as they are encountered during compaction,
and cleaning up blob files once they contain nothing but garbage. However,
with sufficiently skewed workloads, it is theoretically possible to end up in a
situation when few or no compactions get scheduled for the SST files that contain
references to the oldest blob files, which can lead to increased space amp due
to the lack of GC.
In order to efficiently handle such workloads, the patch adds a new BlobDB
configuration option called `blob_garbage_collection_force_threshold`,
which signals to BlobDB to schedule targeted compactions for the SST files
that keep alive the oldest batch of blob files if the overall ratio of garbage in
the given blob files meets the threshold *and* all the given blob files are
eligible for GC based on `blob_garbage_collection_age_cutoff`. (For example,
if the new option is set to 0.9, targeted compactions will get scheduled if the
sum of garbage bytes meets or exceeds 90% of the sum of total bytes in the
oldest blob files, assuming all affected blob files are below the age-based cutoff.)
The net result of these targeted compactions is that the valid blobs in the oldest
blob files are relocated and the oldest blob files themselves cleaned up (since
*all* SST files that rely on them get compacted away).
These targeted compactions are similar to periodic compactions in the sense
that they force certain SST files that otherwise would not get picked up to undergo
compaction and also in the sense that instead of merging files from multiple levels,
they target a single file. (Note: such compactions might still include neighboring files
from the same level due to the need of having a "clean cut" boundary but they never
include any files from any other level.)
This functionality is currently only supported with the leveled compaction style
and is inactive by default (since the default value is set to 1.0, i.e. 100%).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8994
Test Plan: Ran `make check` and tested using `db_bench` and the stress/crash tests.
Reviewed By: riversand963
Differential Revision: D31489850
Pulled By: ltamasi
fbshipit-source-id: 44057d511726a0e2a03c5d9313d7511b3f0c4eab
2021-10-12 03:00:44 +02:00
|
|
|
options_.blob_garbage_collection_force_threshold =
|
|
|
|
FLAGS_blob_garbage_collection_force_threshold;
|
2021-11-20 02:52:42 +01:00
|
|
|
options_.blob_compaction_readahead_size =
|
|
|
|
FLAGS_blob_compaction_readahead_size;
|
2019-12-09 08:49:32 +01:00
|
|
|
} else {
|
|
|
|
#ifdef ROCKSDB_LITE
|
|
|
|
fprintf(stderr, "--options_file not supported in lite mode\n");
|
|
|
|
exit(1);
|
|
|
|
#else
|
|
|
|
DBOptions db_options;
|
|
|
|
std::vector<ColumnFamilyDescriptor> cf_descriptors;
|
2019-12-21 01:13:19 +01:00
|
|
|
Status s = LoadOptionsFromFile(FLAGS_options_file, db_stress_env,
|
|
|
|
&db_options, &cf_descriptors);
|
|
|
|
db_options.env = new DbStressEnvWrapper(db_stress_env);
|
2019-12-09 08:49:32 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "Unable to load options file %s --- %s\n",
|
|
|
|
FLAGS_options_file.c_str(), s.ToString().c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
options_ = Options(db_options, cf_descriptors[0].options);
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FLAGS_rate_limiter_bytes_per_sec > 0) {
|
|
|
|
options_.rate_limiter.reset(NewGenericRateLimiter(
|
|
|
|
FLAGS_rate_limiter_bytes_per_sec, 1000 /* refill_period_us */,
|
|
|
|
10 /* fairness */,
|
|
|
|
FLAGS_rate_limit_bg_reads ? RateLimiter::Mode::kReadsOnly
|
|
|
|
: RateLimiter::Mode::kWritesOnly));
|
|
|
|
if (FLAGS_rate_limit_bg_reads) {
|
|
|
|
options_.new_table_reader_for_compaction_inputs = true;
|
|
|
|
}
|
|
|
|
}
|
2020-02-26 01:43:33 +01:00
|
|
|
if (FLAGS_sst_file_manager_bytes_per_sec > 0 ||
|
|
|
|
FLAGS_sst_file_manager_bytes_per_truncate > 0) {
|
|
|
|
Status status;
|
|
|
|
options_.sst_file_manager.reset(NewSstFileManager(
|
|
|
|
db_stress_env, options_.info_log, "" /* trash_dir */,
|
|
|
|
static_cast<int64_t>(FLAGS_sst_file_manager_bytes_per_sec),
|
|
|
|
true /* delete_existing_trash */, &status,
|
|
|
|
0.25 /* max_trash_db_ratio */,
|
|
|
|
FLAGS_sst_file_manager_bytes_per_truncate));
|
|
|
|
if (!status.ok()) {
|
|
|
|
fprintf(stderr, "SstFileManager creation failed: %s\n",
|
|
|
|
status.ToString().c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
|
|
|
|
if (FLAGS_prefix_size == 0 && FLAGS_rep_factory == kHashSkipList) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"prefeix_size cannot be zero if memtablerep == prefix_hash\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (FLAGS_prefix_size != 0 && FLAGS_rep_factory != kHashSkipList) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"WARNING: prefix_size is non-zero but "
|
|
|
|
"memtablerep != prefix_hash\n");
|
|
|
|
}
|
|
|
|
switch (FLAGS_rep_factory) {
|
|
|
|
case kSkipList:
|
|
|
|
// no need to do anything
|
|
|
|
break;
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
case kHashSkipList:
|
|
|
|
options_.memtable_factory.reset(NewHashSkipListRepFactory(10000));
|
|
|
|
break;
|
|
|
|
case kVectorRep:
|
|
|
|
options_.memtable_factory.reset(new VectorRepFactory());
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
default:
|
|
|
|
fprintf(stderr,
|
|
|
|
"RocksdbLite only supports skip list mem table. Skip "
|
|
|
|
"--rep_factory\n");
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FLAGS_use_full_merge_v1) {
|
|
|
|
options_.merge_operator = MergeOperators::CreateDeprecatedPutOperator();
|
|
|
|
} else {
|
|
|
|
options_.merge_operator = MergeOperators::CreatePutOperator();
|
|
|
|
}
|
2020-06-18 18:51:14 +02:00
|
|
|
if (FLAGS_enable_compaction_filter) {
|
|
|
|
options_.compaction_filter_factory =
|
|
|
|
std::make_shared<DbStressCompactionFilterFactory>();
|
|
|
|
}
|
2020-08-11 01:16:19 +02:00
|
|
|
options_.table_properties_collector_factories.emplace_back(
|
|
|
|
std::make_shared<DbStressTablePropertiesCollectorFactory>());
|
2019-12-09 08:49:32 +01:00
|
|
|
|
2020-06-13 04:24:11 +02:00
|
|
|
options_.best_efforts_recovery = FLAGS_best_efforts_recovery;
|
2020-09-30 23:39:47 +02:00
|
|
|
options_.paranoid_file_checks = FLAGS_paranoid_file_checks;
|
2021-05-05 21:53:42 +02:00
|
|
|
options_.fail_if_options_file_error = FLAGS_fail_if_options_file_error;
|
2020-06-13 04:24:11 +02:00
|
|
|
|
2021-02-02 20:39:20 +01:00
|
|
|
if ((options_.enable_blob_files || options_.enable_blob_garbage_collection ||
|
|
|
|
FLAGS_allow_setting_blob_options_dynamically) &&
|
2021-06-25 19:44:55 +02:00
|
|
|
FLAGS_best_efforts_recovery) {
|
2021-03-02 02:23:11 +01:00
|
|
|
fprintf(stderr,
|
2021-06-25 19:44:55 +02:00
|
|
|
"Integrated BlobDB is currently incompatible with best-effort "
|
|
|
|
"recovery\n");
|
2021-02-02 20:39:20 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2021-11-20 02:52:42 +01:00
|
|
|
fprintf(stdout,
|
|
|
|
"Integrated BlobDB: blob files enabled %d, min blob size %" PRIu64
|
|
|
|
", blob file size %" PRIu64
|
|
|
|
", blob compression type %s, blob GC enabled %d, cutoff %f, force "
|
|
|
|
"threshold %f, blob compaction readahead size %" PRIu64 "\n",
|
|
|
|
options_.enable_blob_files, options_.min_blob_size,
|
|
|
|
options_.blob_file_size,
|
|
|
|
CompressionTypeToString(options_.blob_compression_type).c_str(),
|
|
|
|
options_.enable_blob_garbage_collection,
|
|
|
|
options_.blob_garbage_collection_age_cutoff,
|
|
|
|
options_.blob_garbage_collection_force_threshold,
|
|
|
|
options_.blob_compaction_readahead_size);
|
2021-02-02 20:39:20 +01:00
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, "DB path: [%s]\n", FLAGS_db.c_str());
|
|
|
|
|
|
|
|
Status s;
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
|
|
|
|
if (FLAGS_user_timestamp_size > 0) {
|
|
|
|
CheckAndSetOptionsForUserTimestamp();
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
if (FLAGS_ttl == -1) {
|
|
|
|
std::vector<std::string> existing_column_families;
|
|
|
|
s = DB::ListColumnFamilies(DBOptions(options_), FLAGS_db,
|
|
|
|
&existing_column_families); // ignore errors
|
|
|
|
if (!s.ok()) {
|
|
|
|
// DB doesn't exist
|
|
|
|
assert(existing_column_families.empty());
|
|
|
|
assert(column_family_names_.empty());
|
|
|
|
column_family_names_.push_back(kDefaultColumnFamilyName);
|
|
|
|
} else if (column_family_names_.empty()) {
|
|
|
|
// this is the first call to the function Open()
|
|
|
|
column_family_names_ = existing_column_families;
|
|
|
|
} else {
|
|
|
|
// this is a reopen. just assert that existing column_family_names are
|
|
|
|
// equivalent to what we remember
|
|
|
|
auto sorted_cfn = column_family_names_;
|
|
|
|
std::sort(sorted_cfn.begin(), sorted_cfn.end());
|
|
|
|
std::sort(existing_column_families.begin(),
|
|
|
|
existing_column_families.end());
|
|
|
|
if (sorted_cfn != existing_column_families) {
|
|
|
|
fprintf(stderr, "Expected column families differ from the existing:\n");
|
2019-12-20 17:46:52 +01:00
|
|
|
fprintf(stderr, "Expected: {");
|
2019-12-09 08:49:32 +01:00
|
|
|
for (auto cf : sorted_cfn) {
|
2019-12-20 17:46:52 +01:00
|
|
|
fprintf(stderr, "%s ", cf.c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
2019-12-20 17:46:52 +01:00
|
|
|
fprintf(stderr, "}\n");
|
|
|
|
fprintf(stderr, "Existing: {");
|
2019-12-09 08:49:32 +01:00
|
|
|
for (auto cf : existing_column_families) {
|
2019-12-20 17:46:52 +01:00
|
|
|
fprintf(stderr, "%s ", cf.c_str());
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
2019-12-20 17:46:52 +01:00
|
|
|
fprintf(stderr, "}\n");
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
|
|
|
assert(sorted_cfn == existing_column_families);
|
|
|
|
}
|
|
|
|
std::vector<ColumnFamilyDescriptor> cf_descriptors;
|
|
|
|
for (auto name : column_family_names_) {
|
|
|
|
if (name != kDefaultColumnFamilyName) {
|
|
|
|
new_column_family_name_ =
|
|
|
|
std::max(new_column_family_name_.load(), std::stoi(name) + 1);
|
|
|
|
}
|
|
|
|
cf_descriptors.emplace_back(name, ColumnFamilyOptions(options_));
|
|
|
|
}
|
|
|
|
while (cf_descriptors.size() < (size_t)FLAGS_column_families) {
|
|
|
|
std::string name = ToString(new_column_family_name_.load());
|
|
|
|
new_column_family_name_++;
|
|
|
|
cf_descriptors.emplace_back(name, ColumnFamilyOptions(options_));
|
|
|
|
column_family_names_.push_back(name);
|
|
|
|
}
|
|
|
|
options_.listeners.clear();
|
Experimental support for SST unique IDs (#8990)
Summary:
* New public header unique_id.h and function GetUniqueIdFromTableProperties
which computes a universally unique identifier based on table properties
of table files from recent RocksDB versions.
* Generation of DB session IDs is refactored so that they are
guaranteed unique in the lifetime of a process running RocksDB.
(SemiStructuredUniqueIdGen, new test included.) Along with file numbers,
this enables SST unique IDs to be guaranteed unique among SSTs generated
in a single process, and "better than random" between processes.
See https://github.com/pdillinger/unique_id
* In addition to public API producing 'external' unique IDs, there is a function
for producing 'internal' unique IDs, with functions for converting between the
two. In short, the external ID is "safe" for things people might do with it, and
the internal ID enables more "power user" features for the future. Specifically,
the external ID goes through a hashing layer so that any subset of bits in the
external ID can be used as a hash of the full ID, while also preserving
uniqueness guarantees in the first 128 bits (bijective both on first 128 bits
and on full 192 bits).
Intended follow-up:
* Use the internal unique IDs in cache keys. (Avoid conflicts with https://github.com/facebook/rocksdb/issues/8912) (The file offset can be XORed into
the third 64-bit value of the unique ID.)
* Publish the external unique IDs in FileStorageInfo (https://github.com/facebook/rocksdb/issues/8968)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8990
Test Plan:
Unit tests added, and checking of unique ids in stress test.
NOTE in stress test we do not generate nearly enough files to thoroughly
stress uniqueness, but the test trims off pieces of the ID to check for
uniqueness so that we can infer (with some assumptions) stronger
properties in the aggregate.
Reviewed By: zhichao-cao, mrambacher
Differential Revision: D31582865
Pulled By: pdillinger
fbshipit-source-id: 1f620c4c86af9abe2a8d177b9ccf2ad2b9f48243
2021-10-19 08:28:28 +02:00
|
|
|
#ifndef ROCKSDB_LITE
|
2019-12-09 08:49:32 +01:00
|
|
|
options_.listeners.emplace_back(
|
|
|
|
new DbStressListener(FLAGS_db, options_.db_paths, cf_descriptors));
|
Experimental support for SST unique IDs (#8990)
Summary:
* New public header unique_id.h and function GetUniqueIdFromTableProperties
which computes a universally unique identifier based on table properties
of table files from recent RocksDB versions.
* Generation of DB session IDs is refactored so that they are
guaranteed unique in the lifetime of a process running RocksDB.
(SemiStructuredUniqueIdGen, new test included.) Along with file numbers,
this enables SST unique IDs to be guaranteed unique among SSTs generated
in a single process, and "better than random" between processes.
See https://github.com/pdillinger/unique_id
* In addition to public API producing 'external' unique IDs, there is a function
for producing 'internal' unique IDs, with functions for converting between the
two. In short, the external ID is "safe" for things people might do with it, and
the internal ID enables more "power user" features for the future. Specifically,
the external ID goes through a hashing layer so that any subset of bits in the
external ID can be used as a hash of the full ID, while also preserving
uniqueness guarantees in the first 128 bits (bijective both on first 128 bits
and on full 192 bits).
Intended follow-up:
* Use the internal unique IDs in cache keys. (Avoid conflicts with https://github.com/facebook/rocksdb/issues/8912) (The file offset can be XORed into
the third 64-bit value of the unique ID.)
* Publish the external unique IDs in FileStorageInfo (https://github.com/facebook/rocksdb/issues/8968)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8990
Test Plan:
Unit tests added, and checking of unique ids in stress test.
NOTE in stress test we do not generate nearly enough files to thoroughly
stress uniqueness, but the test trims off pieces of the ID to check for
uniqueness so that we can infer (with some assumptions) stronger
properties in the aggregate.
Reviewed By: zhichao-cao, mrambacher
Differential Revision: D31582865
Pulled By: pdillinger
fbshipit-source-id: 1f620c4c86af9abe2a8d177b9ccf2ad2b9f48243
2021-10-19 08:28:28 +02:00
|
|
|
#endif // !ROCKSDB_LITE
|
2019-12-09 08:49:32 +01:00
|
|
|
options_.create_missing_column_families = true;
|
|
|
|
if (!FLAGS_use_txn) {
|
2021-04-28 19:57:11 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// Determine whether we need to ingest file metadata write failures
|
|
|
|
// during DB reopen. If it does, enable it.
|
|
|
|
// Only ingest metadata error if it is reopening, as initial open
|
|
|
|
// failure doesn't need to be handled.
|
|
|
|
// TODO cover transaction DB is not covered in this fault test too.
|
2021-07-01 01:45:44 +02:00
|
|
|
bool ingest_meta_error = false;
|
|
|
|
bool ingest_write_error = false;
|
2021-07-06 20:04:04 +02:00
|
|
|
bool ingest_read_error = false;
|
2021-07-01 01:45:44 +02:00
|
|
|
if ((FLAGS_open_metadata_write_fault_one_in ||
|
2021-07-06 20:04:04 +02:00
|
|
|
FLAGS_open_write_fault_one_in || FLAGS_open_read_fault_one_in) &&
|
2021-04-28 19:57:11 +02:00
|
|
|
fault_fs_guard
|
|
|
|
->FileExists(FLAGS_db + "/CURRENT", IOOptions(), nullptr)
|
2021-07-01 01:45:44 +02:00
|
|
|
.ok()) {
|
2021-07-22 01:07:18 +02:00
|
|
|
if (!FLAGS_sync) {
|
|
|
|
// When DB Stress is not sync mode, we expect all WAL writes to
|
|
|
|
// WAL is durable. Buffering unsynced writes will cause false
|
|
|
|
// positive in crash tests. Before we figure out a way to
|
|
|
|
// solve it, skip WAL from failure injection.
|
|
|
|
fault_fs_guard->SetSkipDirectWritableTypes({kWalFile});
|
|
|
|
}
|
2021-07-01 01:45:44 +02:00
|
|
|
ingest_meta_error = FLAGS_open_metadata_write_fault_one_in;
|
|
|
|
ingest_write_error = FLAGS_open_write_fault_one_in;
|
2021-07-06 20:04:04 +02:00
|
|
|
ingest_read_error = FLAGS_open_read_fault_one_in;
|
2021-07-01 01:45:44 +02:00
|
|
|
if (ingest_meta_error) {
|
|
|
|
fault_fs_guard->EnableMetadataWriteErrorInjection();
|
|
|
|
fault_fs_guard->SetRandomMetadataWriteError(
|
|
|
|
FLAGS_open_metadata_write_fault_one_in);
|
|
|
|
}
|
|
|
|
if (ingest_write_error) {
|
|
|
|
fault_fs_guard->SetFilesystemDirectWritable(false);
|
|
|
|
fault_fs_guard->EnableWriteErrorInjection();
|
|
|
|
fault_fs_guard->SetRandomWriteError(
|
|
|
|
static_cast<uint32_t>(FLAGS_seed), FLAGS_open_write_fault_one_in,
|
|
|
|
IOStatus::IOError("Injected Open Error"),
|
|
|
|
/*inject_for_all_file_types=*/true, /*types=*/{});
|
|
|
|
}
|
2021-07-06 20:04:04 +02:00
|
|
|
if (ingest_read_error) {
|
|
|
|
fault_fs_guard->SetRandomReadError(FLAGS_open_read_fault_one_in);
|
|
|
|
}
|
2021-04-28 19:57:11 +02:00
|
|
|
}
|
|
|
|
while (true) {
|
|
|
|
#endif // NDEBUG
|
2019-12-20 19:25:48 +01:00
|
|
|
#ifndef ROCKSDB_LITE
|
2021-04-28 19:57:11 +02:00
|
|
|
// StackableDB-based BlobDB
|
|
|
|
if (FLAGS_use_blob_db) {
|
|
|
|
blob_db::BlobDBOptions blob_db_options;
|
|
|
|
blob_db_options.min_blob_size = FLAGS_blob_db_min_blob_size;
|
|
|
|
blob_db_options.bytes_per_sync = FLAGS_blob_db_bytes_per_sync;
|
|
|
|
blob_db_options.blob_file_size = FLAGS_blob_db_file_size;
|
|
|
|
blob_db_options.enable_garbage_collection = FLAGS_blob_db_enable_gc;
|
|
|
|
blob_db_options.garbage_collection_cutoff = FLAGS_blob_db_gc_cutoff;
|
|
|
|
|
|
|
|
blob_db::BlobDB* blob_db = nullptr;
|
|
|
|
s = blob_db::BlobDB::Open(options_, blob_db_options, FLAGS_db,
|
|
|
|
cf_descriptors, &column_families_,
|
|
|
|
&blob_db);
|
|
|
|
if (s.ok()) {
|
|
|
|
db_ = blob_db;
|
|
|
|
}
|
|
|
|
} else
|
2019-12-20 19:25:48 +01:00
|
|
|
#endif // !ROCKSDB_LITE
|
2021-04-28 19:57:11 +02:00
|
|
|
{
|
|
|
|
if (db_preload_finished_.load() && FLAGS_read_only) {
|
|
|
|
s = DB::OpenForReadOnly(DBOptions(options_), FLAGS_db,
|
|
|
|
cf_descriptors, &column_families_, &db_);
|
|
|
|
} else {
|
|
|
|
s = DB::Open(DBOptions(options_), FLAGS_db, cf_descriptors,
|
|
|
|
&column_families_, &db_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2021-07-06 20:04:04 +02:00
|
|
|
if (ingest_meta_error || ingest_write_error || ingest_read_error) {
|
2021-07-01 01:45:44 +02:00
|
|
|
fault_fs_guard->SetFilesystemDirectWritable(true);
|
2021-04-28 19:57:11 +02:00
|
|
|
fault_fs_guard->DisableMetadataWriteErrorInjection();
|
2021-07-01 01:45:44 +02:00
|
|
|
fault_fs_guard->DisableWriteErrorInjection();
|
2021-07-17 01:08:14 +02:00
|
|
|
fault_fs_guard->SetSkipDirectWritableTypes({});
|
2021-07-06 20:04:04 +02:00
|
|
|
fault_fs_guard->SetRandomReadError(0);
|
2021-05-06 01:40:45 +02:00
|
|
|
if (s.ok()) {
|
|
|
|
// Ingested errors might happen in background compactions. We
|
|
|
|
// wait for all compactions to finish to make sure DB is in
|
|
|
|
// clean state before executing queries.
|
|
|
|
s = static_cast_with_check<DBImpl>(db_->GetRootDB())
|
|
|
|
->TEST_WaitForCompact(true);
|
|
|
|
if (!s.ok()) {
|
2021-07-20 23:58:19 +02:00
|
|
|
for (auto cf : column_families_) {
|
|
|
|
delete cf;
|
|
|
|
}
|
|
|
|
column_families_.clear();
|
2021-05-06 01:40:45 +02:00
|
|
|
delete db_;
|
2021-07-20 23:58:19 +02:00
|
|
|
db_ = nullptr;
|
2021-05-06 01:40:45 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-28 19:57:11 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
// After failure to opening a DB due to IO error, retry should
|
|
|
|
// successfully open the DB with correct data if no IO error shows
|
|
|
|
// up.
|
|
|
|
ingest_meta_error = false;
|
2021-07-01 01:45:44 +02:00
|
|
|
ingest_write_error = false;
|
2021-07-06 20:04:04 +02:00
|
|
|
ingest_read_error = false;
|
2021-04-28 19:57:11 +02:00
|
|
|
|
|
|
|
Random rand(static_cast<uint32_t>(FLAGS_seed));
|
|
|
|
if (rand.OneIn(2)) {
|
|
|
|
fault_fs_guard->DeleteFilesCreatedAfterLastDirSync(IOOptions(),
|
|
|
|
nullptr);
|
|
|
|
}
|
|
|
|
if (rand.OneIn(3)) {
|
|
|
|
fault_fs_guard->DropUnsyncedFileData();
|
|
|
|
} else if (rand.OneIn(2)) {
|
|
|
|
fault_fs_guard->DropRandomUnsyncedFileData(&rand);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-20 19:25:48 +01:00
|
|
|
}
|
2021-04-28 19:57:11 +02:00
|
|
|
break;
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
2021-04-28 19:57:11 +02:00
|
|
|
#endif // NDEBUG
|
2019-12-09 08:49:32 +01:00
|
|
|
} else {
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
TransactionDBOptions txn_db_options;
|
2019-12-12 19:34:52 +01:00
|
|
|
assert(FLAGS_txn_write_policy <= TxnDBWritePolicy::WRITE_UNPREPARED);
|
|
|
|
txn_db_options.write_policy =
|
|
|
|
static_cast<TxnDBWritePolicy>(FLAGS_txn_write_policy);
|
2019-12-13 19:23:01 +01:00
|
|
|
if (FLAGS_unordered_write) {
|
|
|
|
assert(txn_db_options.write_policy == TxnDBWritePolicy::WRITE_PREPARED);
|
|
|
|
options_.unordered_write = true;
|
|
|
|
options_.two_write_queues = true;
|
|
|
|
txn_db_options.skip_concurrency_control = true;
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
s = TransactionDB::Open(options_, txn_db_options, FLAGS_db,
|
|
|
|
cf_descriptors, &column_families_, &txn_db_);
|
2020-01-08 21:09:18 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "Error in opening the TransactionDB [%s]\n",
|
|
|
|
s.ToString().c_str());
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
2020-01-03 01:13:30 +01:00
|
|
|
assert(s.ok());
|
2019-12-09 08:49:32 +01:00
|
|
|
db_ = txn_db_;
|
|
|
|
// after a crash, rollback to commit recovered transactions
|
|
|
|
std::vector<Transaction*> trans;
|
|
|
|
txn_db_->GetAllPreparedTransactions(&trans);
|
|
|
|
Random rand(static_cast<uint32_t>(FLAGS_seed));
|
|
|
|
for (auto txn : trans) {
|
|
|
|
if (rand.OneIn(2)) {
|
|
|
|
s = txn->Commit();
|
|
|
|
assert(s.ok());
|
|
|
|
} else {
|
|
|
|
s = txn->Rollback();
|
|
|
|
assert(s.ok());
|
|
|
|
}
|
|
|
|
delete txn;
|
|
|
|
}
|
|
|
|
trans.clear();
|
|
|
|
txn_db_->GetAllPreparedTransactions(&trans);
|
|
|
|
assert(trans.size() == 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
assert(!s.ok() || column_families_.size() ==
|
|
|
|
static_cast<size_t>(FLAGS_column_families));
|
|
|
|
|
2021-09-15 23:23:17 +02:00
|
|
|
if (s.ok() && FLAGS_test_secondary) {
|
2019-12-09 08:49:32 +01:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
secondaries_.resize(FLAGS_threads);
|
|
|
|
std::fill(secondaries_.begin(), secondaries_.end(), nullptr);
|
|
|
|
secondary_cfh_lists_.clear();
|
|
|
|
secondary_cfh_lists_.resize(FLAGS_threads);
|
|
|
|
Options tmp_opts;
|
2019-12-20 17:46:52 +01:00
|
|
|
// TODO(yanqin) support max_open_files != -1 for secondary instance.
|
|
|
|
tmp_opts.max_open_files = -1;
|
2019-12-09 08:49:32 +01:00
|
|
|
tmp_opts.statistics = dbstats_secondaries;
|
2019-12-21 01:13:19 +01:00
|
|
|
tmp_opts.env = db_stress_env;
|
2019-12-09 08:49:32 +01:00
|
|
|
for (size_t i = 0; i != static_cast<size_t>(FLAGS_threads); ++i) {
|
|
|
|
const std::string secondary_path =
|
|
|
|
FLAGS_secondaries_base + "/" + std::to_string(i);
|
|
|
|
s = DB::OpenAsSecondary(tmp_opts, FLAGS_db, secondary_path,
|
|
|
|
cf_descriptors, &secondary_cfh_lists_[i],
|
|
|
|
&secondaries_[i]);
|
|
|
|
if (!s.ok()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
fprintf(stderr, "Secondary is not supported in RocksDBLite\n");
|
|
|
|
exit(1);
|
|
|
|
#endif
|
|
|
|
}
|
2021-09-15 23:23:17 +02:00
|
|
|
if (s.ok() && FLAGS_continuous_verification_interval > 0 && !cmp_db_) {
|
2019-12-20 17:46:52 +01:00
|
|
|
Options tmp_opts;
|
|
|
|
// TODO(yanqin) support max_open_files != -1 for secondary instance.
|
|
|
|
tmp_opts.max_open_files = -1;
|
2019-12-21 01:13:19 +01:00
|
|
|
tmp_opts.env = db_stress_env;
|
2019-12-20 17:46:52 +01:00
|
|
|
std::string secondary_path = FLAGS_secondaries_base + "/cmp_database";
|
|
|
|
s = DB::OpenAsSecondary(tmp_opts, FLAGS_db, secondary_path,
|
|
|
|
cf_descriptors, &cmp_cfhs_, &cmp_db_);
|
|
|
|
assert(!s.ok() ||
|
|
|
|
cmp_cfhs_.size() == static_cast<size_t>(FLAGS_column_families));
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
} else {
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
DBWithTTL* db_with_ttl;
|
|
|
|
s = DBWithTTL::Open(options_, FLAGS_db, &db_with_ttl, FLAGS_ttl);
|
|
|
|
db_ = db_with_ttl;
|
2019-12-20 17:46:52 +01:00
|
|
|
if (FLAGS_test_secondary) {
|
2019-12-09 08:49:32 +01:00
|
|
|
secondaries_.resize(FLAGS_threads);
|
|
|
|
std::fill(secondaries_.begin(), secondaries_.end(), nullptr);
|
|
|
|
Options tmp_opts;
|
|
|
|
tmp_opts.env = options_.env;
|
2019-12-20 17:46:52 +01:00
|
|
|
// TODO(yanqin) support max_open_files != -1 for secondary instance.
|
|
|
|
tmp_opts.max_open_files = -1;
|
2019-12-09 08:49:32 +01:00
|
|
|
for (size_t i = 0; i != static_cast<size_t>(FLAGS_threads); ++i) {
|
|
|
|
const std::string secondary_path =
|
|
|
|
FLAGS_secondaries_base + "/" + std::to_string(i);
|
|
|
|
s = DB::OpenAsSecondary(tmp_opts, FLAGS_db, secondary_path,
|
|
|
|
&secondaries_[i]);
|
|
|
|
if (!s.ok()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
fprintf(stderr, "TTL is not supported in RocksDBLite\n");
|
|
|
|
exit(1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "open error: %s\n", s.ToString().c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 05:01:25 +01:00
|
|
|
void StressTest::Reopen(ThreadState* thread) {
|
|
|
|
#ifndef ROCKSDB_LITE
|
2020-01-31 19:26:58 +01:00
|
|
|
// BG jobs in WritePrepared must be canceled first because i) they can access
|
|
|
|
// the db via a callbac ii) they hold on to a snapshot and the upcoming
|
|
|
|
// ::Close would complain about it.
|
|
|
|
const bool write_prepared = FLAGS_use_txn && FLAGS_txn_write_policy != 0;
|
2021-12-14 22:33:16 +01:00
|
|
|
bool bg_canceled __attribute__((unused)) = false;
|
2020-01-31 19:26:58 +01:00
|
|
|
if (write_prepared || thread->rand.OneIn(2)) {
|
|
|
|
const bool wait =
|
|
|
|
write_prepared || static_cast<bool>(thread->rand.OneIn(2));
|
2019-12-17 03:30:48 +01:00
|
|
|
CancelAllBackgroundWork(db_, wait);
|
|
|
|
bg_canceled = wait;
|
2019-12-11 05:01:25 +01:00
|
|
|
}
|
2020-01-31 19:26:58 +01:00
|
|
|
assert(!write_prepared || bg_canceled);
|
2019-12-11 05:01:25 +01:00
|
|
|
#else
|
|
|
|
(void) thread;
|
|
|
|
#endif
|
|
|
|
|
2019-12-09 08:49:32 +01:00
|
|
|
for (auto cf : column_families_) {
|
|
|
|
delete cf;
|
|
|
|
}
|
|
|
|
column_families_.clear();
|
2019-12-11 05:01:25 +01:00
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
2020-01-31 19:26:58 +01:00
|
|
|
if (thread->rand.OneIn(2)) {
|
2019-12-11 05:01:25 +01:00
|
|
|
Status s = db_->Close();
|
2019-12-13 19:23:01 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "Non-ok close status: %s\n", s.ToString().c_str());
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
2019-12-11 05:01:25 +01:00
|
|
|
assert(s.ok());
|
|
|
|
}
|
|
|
|
#endif
|
2019-12-09 08:49:32 +01:00
|
|
|
delete db_;
|
|
|
|
db_ = nullptr;
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
txn_db_ = nullptr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
assert(secondaries_.size() == secondary_cfh_lists_.size());
|
|
|
|
size_t n = secondaries_.size();
|
|
|
|
for (size_t i = 0; i != n; ++i) {
|
|
|
|
for (auto* cf : secondary_cfh_lists_[i]) {
|
|
|
|
delete cf;
|
|
|
|
}
|
|
|
|
secondary_cfh_lists_[i].clear();
|
|
|
|
delete secondaries_[i];
|
|
|
|
}
|
|
|
|
secondaries_.clear();
|
|
|
|
|
|
|
|
num_times_reopened_++;
|
2021-03-15 12:32:24 +01:00
|
|
|
auto now = clock_->NowMicros();
|
2019-12-09 08:49:32 +01:00
|
|
|
fprintf(stdout, "%s Reopening database for the %dth time\n",
|
2021-03-15 12:32:24 +01:00
|
|
|
clock_->TimeToString(now / 1000000).c_str(), num_times_reopened_);
|
2019-12-09 08:49:32 +01:00
|
|
|
Open();
|
2021-12-07 22:40:46 +01:00
|
|
|
|
2022-01-06 01:12:12 +01:00
|
|
|
if ((FLAGS_sync_fault_injection || FLAGS_disable_wal) && IsStateTracked()) {
|
2021-12-07 22:40:46 +01:00
|
|
|
Status s = thread->shared->SaveAtAndAfter(db_);
|
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "Error enabling history tracing: %s\n",
|
|
|
|
s.ToString().c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 08:49:32 +01:00
|
|
|
}
|
Add user-defined timestamps to db_stress (#8061)
Summary:
Add some basic test for user-defined timestamp to db_stress. Currently,
read with timestamp always tries to read using the current timestamp.
Due to the per-key timestamp-sequence ordering constraint, we only add timestamp-
related tests to the `NonBatchedOpsStressTest` since this test serializes accesses
to the same key and uses a file to cross-check data correctness.
The timestamp feature is not supported in a number of components, e.g. Merge, SingleDelete,
DeleteRange, CompactionFilter, Readonly instance, secondary instance, SST file ingestion, transaction,
etc. Therefore, db_stress should exit if user enables both timestamp and these features at the same
time. The (currently) incompatible features can be found in
`CheckAndSetOptionsForUserTimestamp`.
This PR also fixes a bug triggered when timestamp is enabled together with
`index_type=kBinarySearchWithFirstKey`. This bug fix will also be in another separate PR
with more unit tests coverage. Fixing it here because I do not want to exclude the index type
from crash test.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8061
Test Plan: make crash_test_with_ts
Reviewed By: jay-zhuang
Differential Revision: D27056282
Pulled By: riversand963
fbshipit-source-id: c3e00ad1023fdb9ebbdf9601ec18270c5e2925a9
2021-03-23 13:12:04 +01:00
|
|
|
|
|
|
|
void StressTest::CheckAndSetOptionsForUserTimestamp() {
|
|
|
|
assert(FLAGS_user_timestamp_size > 0);
|
|
|
|
const Comparator* const cmp = test::ComparatorWithU64Ts();
|
|
|
|
assert(cmp);
|
|
|
|
if (FLAGS_user_timestamp_size != cmp->timestamp_size()) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Only -user_timestamp_size=%d is supported in stress test.\n",
|
|
|
|
static_cast<int>(cmp->timestamp_size()));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (FLAGS_use_merge || FLAGS_use_full_merge_v1) {
|
|
|
|
fprintf(stderr, "Merge does not support timestamp yet.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (FLAGS_delrangepercent > 0) {
|
|
|
|
fprintf(stderr, "DeleteRange does not support timestamp yet.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (FLAGS_use_txn) {
|
|
|
|
fprintf(stderr, "TransactionDB does not support timestamp yet.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (FLAGS_read_only) {
|
|
|
|
fprintf(stderr, "When opened as read-only, timestamp not supported.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (FLAGS_test_secondary || FLAGS_secondary_catch_up_one_in > 0 ||
|
|
|
|
FLAGS_continuous_verification_interval > 0) {
|
|
|
|
fprintf(stderr, "Secondary instance does not support timestamp.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (FLAGS_checkpoint_one_in > 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"-checkpoint_one_in=%d requires "
|
|
|
|
"DBImplReadOnly, which is not supported with timestamp\n",
|
|
|
|
FLAGS_checkpoint_one_in);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
if (FLAGS_enable_blob_files || FLAGS_use_blob_db) {
|
|
|
|
fprintf(stderr, "BlobDB not supported with timestamp.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
if (FLAGS_enable_compaction_filter) {
|
|
|
|
fprintf(stderr, "CompactionFilter not supported with timestamp.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (FLAGS_test_cf_consistency || FLAGS_test_batches_snapshots) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Due to per-key ts-seq ordering constraint, only the (default) "
|
|
|
|
"non-batched test is supported with timestamp.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (FLAGS_ingest_external_file_one_in > 0) {
|
|
|
|
fprintf(stderr, "Bulk loading may not support timestamp yet.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
options_.comparator = cmp;
|
|
|
|
}
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2019-12-09 08:49:32 +01:00
|
|
|
#endif // GFLAGS
|