2019-12-09 07:49:32 +00: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-07-09 21:33:42 +00:00
|
|
|
#include "file/file_util.h"
|
2019-12-09 07:49:32 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2019-12-09 07:49:32 +00:00
|
|
|
class CfConsistencyStressTest : public StressTest {
|
|
|
|
public:
|
|
|
|
CfConsistencyStressTest() : batch_id_(0) {}
|
|
|
|
|
2019-12-20 16:46:52 +00:00
|
|
|
~CfConsistencyStressTest() override {}
|
2019-12-09 07:49:32 +00:00
|
|
|
|
2021-12-07 21:40:46 +00:00
|
|
|
bool IsStateTracked() const override { return false; }
|
|
|
|
|
2019-12-09 22:36:10 +00:00
|
|
|
Status TestPut(ThreadState* thread, WriteOptions& write_opts,
|
|
|
|
const ReadOptions& /* read_opts */,
|
|
|
|
const std::vector<int>& rand_column_families,
|
2022-09-15 22:55:37 +00:00
|
|
|
const std::vector<int64_t>& rand_keys,
|
|
|
|
char (&value)[100]) override {
|
Add the PutEntity API to the stress/crash tests (#10760)
Summary:
The patch adds the `PutEntity` API to the non-batched, batched, and
CF consistency stress tests. Namely, when the new `db_stress` command
line parameter `use_put_entity_one_in` is greater than zero, one in
N writes on average is performed using `PutEntity` rather than `Put`.
The wide-column entity written has the generated value in its default
column; in addition, it contains up to three additional columns where
the original generated value is divided up between the column name and the
column value (with the column name containing the first k characters of
the generated value, and the column value containing the rest). Whether
`PutEntity` is used (and if so, how many columns the entity has) is completely
determined by the "value base" used to generate the value (that is, there is
no randomness involved). Assuming the same `use_put_entity_one_in` setting
is used across `db_stress` invocations, this enables us to reconstruct and
validate the entity during subsequent `db_stress` runs.
Note that `PutEntity` is currently incompatible with `Merge`, transactions, and
user-defined timestamps; these combinations are currently disabled/disallowed.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/10760
Test Plan: Ran some batched, non-batched, and CF consistency stress tests using the script.
Reviewed By: riversand963
Differential Revision: D39939032
Pulled By: ltamasi
fbshipit-source-id: eafdf124e95993fb7d73158e3b006d11819f7fa9
2022-09-30 18:11:07 +00:00
|
|
|
assert(!rand_column_families.empty());
|
|
|
|
assert(!rand_keys.empty());
|
|
|
|
|
|
|
|
const std::string k = Key(rand_keys[0]);
|
|
|
|
|
|
|
|
const uint32_t value_base = batch_id_.fetch_add(1);
|
|
|
|
const size_t sz = GenerateValue(value_base, value, sizeof(value));
|
|
|
|
const Slice v(value, sz);
|
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
WriteBatch batch;
|
Add the PutEntity API to the stress/crash tests (#10760)
Summary:
The patch adds the `PutEntity` API to the non-batched, batched, and
CF consistency stress tests. Namely, when the new `db_stress` command
line parameter `use_put_entity_one_in` is greater than zero, one in
N writes on average is performed using `PutEntity` rather than `Put`.
The wide-column entity written has the generated value in its default
column; in addition, it contains up to three additional columns where
the original generated value is divided up between the column name and the
column value (with the column name containing the first k characters of
the generated value, and the column value containing the rest). Whether
`PutEntity` is used (and if so, how many columns the entity has) is completely
determined by the "value base" used to generate the value (that is, there is
no randomness involved). Assuming the same `use_put_entity_one_in` setting
is used across `db_stress` invocations, this enables us to reconstruct and
validate the entity during subsequent `db_stress` runs.
Note that `PutEntity` is currently incompatible with `Merge`, transactions, and
user-defined timestamps; these combinations are currently disabled/disallowed.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/10760
Test Plan: Ran some batched, non-batched, and CF consistency stress tests using the script.
Reviewed By: riversand963
Differential Revision: D39939032
Pulled By: ltamasi
fbshipit-source-id: eafdf124e95993fb7d73158e3b006d11819f7fa9
2022-09-30 18:11:07 +00:00
|
|
|
|
|
|
|
const bool use_put_entity = !FLAGS_use_merge &&
|
|
|
|
FLAGS_use_put_entity_one_in > 0 &&
|
|
|
|
(value_base % FLAGS_use_put_entity_one_in) == 0;
|
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
for (auto cf : rand_column_families) {
|
Add the PutEntity API to the stress/crash tests (#10760)
Summary:
The patch adds the `PutEntity` API to the non-batched, batched, and
CF consistency stress tests. Namely, when the new `db_stress` command
line parameter `use_put_entity_one_in` is greater than zero, one in
N writes on average is performed using `PutEntity` rather than `Put`.
The wide-column entity written has the generated value in its default
column; in addition, it contains up to three additional columns where
the original generated value is divided up between the column name and the
column value (with the column name containing the first k characters of
the generated value, and the column value containing the rest). Whether
`PutEntity` is used (and if so, how many columns the entity has) is completely
determined by the "value base" used to generate the value (that is, there is
no randomness involved). Assuming the same `use_put_entity_one_in` setting
is used across `db_stress` invocations, this enables us to reconstruct and
validate the entity during subsequent `db_stress` runs.
Note that `PutEntity` is currently incompatible with `Merge`, transactions, and
user-defined timestamps; these combinations are currently disabled/disallowed.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/10760
Test Plan: Ran some batched, non-batched, and CF consistency stress tests using the script.
Reviewed By: riversand963
Differential Revision: D39939032
Pulled By: ltamasi
fbshipit-source-id: eafdf124e95993fb7d73158e3b006d11819f7fa9
2022-09-30 18:11:07 +00:00
|
|
|
ColumnFamilyHandle* const cfh = column_families_[cf];
|
|
|
|
assert(cfh);
|
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
if (FLAGS_use_merge) {
|
Add the PutEntity API to the stress/crash tests (#10760)
Summary:
The patch adds the `PutEntity` API to the non-batched, batched, and
CF consistency stress tests. Namely, when the new `db_stress` command
line parameter `use_put_entity_one_in` is greater than zero, one in
N writes on average is performed using `PutEntity` rather than `Put`.
The wide-column entity written has the generated value in its default
column; in addition, it contains up to three additional columns where
the original generated value is divided up between the column name and the
column value (with the column name containing the first k characters of
the generated value, and the column value containing the rest). Whether
`PutEntity` is used (and if so, how many columns the entity has) is completely
determined by the "value base" used to generate the value (that is, there is
no randomness involved). Assuming the same `use_put_entity_one_in` setting
is used across `db_stress` invocations, this enables us to reconstruct and
validate the entity during subsequent `db_stress` runs.
Note that `PutEntity` is currently incompatible with `Merge`, transactions, and
user-defined timestamps; these combinations are currently disabled/disallowed.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/10760
Test Plan: Ran some batched, non-batched, and CF consistency stress tests using the script.
Reviewed By: riversand963
Differential Revision: D39939032
Pulled By: ltamasi
fbshipit-source-id: eafdf124e95993fb7d73158e3b006d11819f7fa9
2022-09-30 18:11:07 +00:00
|
|
|
batch.Merge(cfh, k, v);
|
|
|
|
} else if (use_put_entity) {
|
|
|
|
batch.PutEntity(cfh, k, GenerateWideColumns(value_base, v));
|
|
|
|
} else {
|
|
|
|
batch.Put(cfh, k, v);
|
2019-12-09 07:49:32 +00:00
|
|
|
}
|
|
|
|
}
|
Add the PutEntity API to the stress/crash tests (#10760)
Summary:
The patch adds the `PutEntity` API to the non-batched, batched, and
CF consistency stress tests. Namely, when the new `db_stress` command
line parameter `use_put_entity_one_in` is greater than zero, one in
N writes on average is performed using `PutEntity` rather than `Put`.
The wide-column entity written has the generated value in its default
column; in addition, it contains up to three additional columns where
the original generated value is divided up between the column name and the
column value (with the column name containing the first k characters of
the generated value, and the column value containing the rest). Whether
`PutEntity` is used (and if so, how many columns the entity has) is completely
determined by the "value base" used to generate the value (that is, there is
no randomness involved). Assuming the same `use_put_entity_one_in` setting
is used across `db_stress` invocations, this enables us to reconstruct and
validate the entity during subsequent `db_stress` runs.
Note that `PutEntity` is currently incompatible with `Merge`, transactions, and
user-defined timestamps; these combinations are currently disabled/disallowed.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/10760
Test Plan: Ran some batched, non-batched, and CF consistency stress tests using the script.
Reviewed By: riversand963
Differential Revision: D39939032
Pulled By: ltamasi
fbshipit-source-id: eafdf124e95993fb7d73158e3b006d11819f7fa9
2022-09-30 18:11:07 +00:00
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
Status s = db_->Write(write_opts, &batch);
|
Add the PutEntity API to the stress/crash tests (#10760)
Summary:
The patch adds the `PutEntity` API to the non-batched, batched, and
CF consistency stress tests. Namely, when the new `db_stress` command
line parameter `use_put_entity_one_in` is greater than zero, one in
N writes on average is performed using `PutEntity` rather than `Put`.
The wide-column entity written has the generated value in its default
column; in addition, it contains up to three additional columns where
the original generated value is divided up between the column name and the
column value (with the column name containing the first k characters of
the generated value, and the column value containing the rest). Whether
`PutEntity` is used (and if so, how many columns the entity has) is completely
determined by the "value base" used to generate the value (that is, there is
no randomness involved). Assuming the same `use_put_entity_one_in` setting
is used across `db_stress` invocations, this enables us to reconstruct and
validate the entity during subsequent `db_stress` runs.
Note that `PutEntity` is currently incompatible with `Merge`, transactions, and
user-defined timestamps; these combinations are currently disabled/disallowed.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/10760
Test Plan: Ran some batched, non-batched, and CF consistency stress tests using the script.
Reviewed By: riversand963
Differential Revision: D39939032
Pulled By: ltamasi
fbshipit-source-id: eafdf124e95993fb7d73158e3b006d11819f7fa9
2022-09-30 18:11:07 +00:00
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "multi put or merge error: %s\n", s.ToString().c_str());
|
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
} else {
|
|
|
|
auto num = static_cast<long>(rand_column_families.size());
|
|
|
|
thread->stats.AddBytesForWrites(num, (sz + 1) * num);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-12-09 22:36:10 +00:00
|
|
|
Status TestDelete(ThreadState* thread, WriteOptions& write_opts,
|
|
|
|
const std::vector<int>& rand_column_families,
|
2022-09-15 22:55:37 +00:00
|
|
|
const std::vector<int64_t>& rand_keys) override {
|
2019-12-09 07:49:32 +00:00
|
|
|
std::string key_str = Key(rand_keys[0]);
|
|
|
|
Slice key = key_str;
|
|
|
|
WriteBatch batch;
|
|
|
|
for (auto cf : rand_column_families) {
|
|
|
|
ColumnFamilyHandle* cfh = column_families_[cf];
|
|
|
|
batch.Delete(cfh, key);
|
|
|
|
}
|
|
|
|
Status s = db_->Write(write_opts, &batch);
|
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "multidel error: %s\n", s.ToString().c_str());
|
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
} else {
|
|
|
|
thread->stats.AddDeletes(static_cast<long>(rand_column_families.size()));
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-12-09 22:36:10 +00:00
|
|
|
Status TestDeleteRange(ThreadState* thread, WriteOptions& write_opts,
|
|
|
|
const std::vector<int>& rand_column_families,
|
2022-09-15 22:55:37 +00:00
|
|
|
const std::vector<int64_t>& rand_keys) override {
|
2019-12-09 07:49:32 +00:00
|
|
|
int64_t rand_key = rand_keys[0];
|
|
|
|
auto shared = thread->shared;
|
|
|
|
int64_t max_key = shared->GetMaxKey();
|
|
|
|
if (rand_key > max_key - FLAGS_range_deletion_width) {
|
|
|
|
rand_key =
|
|
|
|
thread->rand.Next() % (max_key - FLAGS_range_deletion_width + 1);
|
|
|
|
}
|
|
|
|
std::string key_str = Key(rand_key);
|
|
|
|
Slice key = key_str;
|
|
|
|
std::string end_key_str = Key(rand_key + FLAGS_range_deletion_width);
|
|
|
|
Slice end_key = end_key_str;
|
|
|
|
WriteBatch batch;
|
|
|
|
for (auto cf : rand_column_families) {
|
|
|
|
ColumnFamilyHandle* cfh = column_families_[rand_column_families[cf]];
|
|
|
|
batch.DeleteRange(cfh, key, end_key);
|
|
|
|
}
|
|
|
|
Status s = db_->Write(write_opts, &batch);
|
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "multi del range error: %s\n", s.ToString().c_str());
|
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
} else {
|
|
|
|
thread->stats.AddRangeDeletions(
|
|
|
|
static_cast<long>(rand_column_families.size()));
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-12-09 22:36:10 +00:00
|
|
|
void TestIngestExternalFile(
|
2019-12-09 07:49:32 +00:00
|
|
|
ThreadState* /* thread */,
|
|
|
|
const std::vector<int>& /* rand_column_families */,
|
2022-09-15 22:55:37 +00:00
|
|
|
const std::vector<int64_t>& /* rand_keys */) override {
|
2019-12-09 07:49:32 +00:00
|
|
|
assert(false);
|
|
|
|
fprintf(stderr,
|
|
|
|
"CfConsistencyStressTest does not support TestIngestExternalFile "
|
|
|
|
"because it's not possible to verify the result\n");
|
|
|
|
std::terminate();
|
|
|
|
}
|
|
|
|
|
2019-12-09 22:36:10 +00:00
|
|
|
Status TestGet(ThreadState* thread, const ReadOptions& readoptions,
|
|
|
|
const std::vector<int>& rand_column_families,
|
|
|
|
const std::vector<int64_t>& rand_keys) override {
|
2019-12-09 07:49:32 +00:00
|
|
|
std::string key_str = Key(rand_keys[0]);
|
|
|
|
Slice key = key_str;
|
|
|
|
Status s;
|
|
|
|
bool is_consistent = true;
|
|
|
|
|
|
|
|
if (thread->rand.OneIn(2)) {
|
|
|
|
// 1/2 chance, does a random read from random CF
|
|
|
|
auto cfh =
|
|
|
|
column_families_[rand_column_families[thread->rand.Next() %
|
|
|
|
rand_column_families.size()]];
|
|
|
|
std::string from_db;
|
|
|
|
s = db_->Get(readoptions, cfh, key, &from_db);
|
|
|
|
} else {
|
|
|
|
// 1/2 chance, comparing one key is the same across all CFs
|
|
|
|
const Snapshot* snapshot = db_->GetSnapshot();
|
|
|
|
ReadOptions readoptionscopy = readoptions;
|
|
|
|
readoptionscopy.snapshot = snapshot;
|
|
|
|
|
|
|
|
std::string value0;
|
|
|
|
s = db_->Get(readoptionscopy, column_families_[rand_column_families[0]],
|
|
|
|
key, &value0);
|
|
|
|
if (s.ok() || s.IsNotFound()) {
|
|
|
|
bool found = s.ok();
|
|
|
|
for (size_t i = 1; i < rand_column_families.size(); i++) {
|
|
|
|
std::string value1;
|
|
|
|
s = db_->Get(readoptionscopy,
|
|
|
|
column_families_[rand_column_families[i]], key, &value1);
|
|
|
|
if (!s.ok() && !s.IsNotFound()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!found && s.ok()) {
|
|
|
|
fprintf(stderr, "Get() return different results with key %s\n",
|
|
|
|
Slice(key_str).ToString(true).c_str());
|
|
|
|
fprintf(stderr, "CF %s is not found\n",
|
|
|
|
column_family_names_[0].c_str());
|
|
|
|
fprintf(stderr, "CF %s returns value %s\n",
|
|
|
|
column_family_names_[i].c_str(),
|
|
|
|
Slice(value1).ToString(true).c_str());
|
|
|
|
is_consistent = false;
|
|
|
|
} else if (found && s.IsNotFound()) {
|
|
|
|
fprintf(stderr, "Get() return different results with key %s\n",
|
|
|
|
Slice(key_str).ToString(true).c_str());
|
|
|
|
fprintf(stderr, "CF %s returns value %s\n",
|
|
|
|
column_family_names_[0].c_str(),
|
|
|
|
Slice(value0).ToString(true).c_str());
|
|
|
|
fprintf(stderr, "CF %s is not found\n",
|
|
|
|
column_family_names_[i].c_str());
|
|
|
|
is_consistent = false;
|
|
|
|
} else if (s.ok() && value0 != value1) {
|
|
|
|
fprintf(stderr, "Get() return different results with key %s\n",
|
|
|
|
Slice(key_str).ToString(true).c_str());
|
|
|
|
fprintf(stderr, "CF %s returns value %s\n",
|
|
|
|
column_family_names_[0].c_str(),
|
|
|
|
Slice(value0).ToString(true).c_str());
|
|
|
|
fprintf(stderr, "CF %s returns value %s\n",
|
|
|
|
column_family_names_[i].c_str(),
|
|
|
|
Slice(value1).ToString(true).c_str());
|
|
|
|
is_consistent = false;
|
|
|
|
}
|
|
|
|
if (!is_consistent) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
db_->ReleaseSnapshot(snapshot);
|
|
|
|
}
|
|
|
|
if (!is_consistent) {
|
2020-01-03 00:43:55 +00:00
|
|
|
fprintf(stderr, "TestGet error: is_consistent is false\n");
|
2019-12-09 07:49:32 +00:00
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
// Fail fast to preserve the DB state.
|
|
|
|
thread->shared->SetVerificationFailure();
|
|
|
|
} else if (s.ok()) {
|
|
|
|
thread->stats.AddGets(1, 1);
|
|
|
|
} else if (s.IsNotFound()) {
|
|
|
|
thread->stats.AddGets(1, 0);
|
|
|
|
} else {
|
2020-01-03 00:43:55 +00:00
|
|
|
fprintf(stderr, "TestGet error: %s\n", s.ToString().c_str());
|
2019-12-09 07:49:32 +00:00
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-12-09 22:36:10 +00:00
|
|
|
std::vector<Status> TestMultiGet(
|
2019-12-09 07:49:32 +00:00
|
|
|
ThreadState* thread, const ReadOptions& read_opts,
|
|
|
|
const std::vector<int>& rand_column_families,
|
2019-12-09 22:36:10 +00:00
|
|
|
const std::vector<int64_t>& rand_keys) override {
|
2019-12-09 07:49:32 +00:00
|
|
|
size_t num_keys = rand_keys.size();
|
|
|
|
std::vector<std::string> key_str;
|
|
|
|
std::vector<Slice> keys;
|
|
|
|
keys.reserve(num_keys);
|
|
|
|
key_str.reserve(num_keys);
|
|
|
|
std::vector<PinnableSlice> values(num_keys);
|
|
|
|
std::vector<Status> statuses(num_keys);
|
|
|
|
ColumnFamilyHandle* cfh = column_families_[rand_column_families[0]];
|
2022-06-17 23:40:47 +00:00
|
|
|
ReadOptions readoptionscopy = read_opts;
|
|
|
|
readoptionscopy.rate_limiter_priority =
|
|
|
|
FLAGS_rate_limit_user_ops ? Env::IO_USER : Env::IO_TOTAL;
|
2019-12-09 07:49:32 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < num_keys; ++i) {
|
|
|
|
key_str.emplace_back(Key(rand_keys[i]));
|
|
|
|
keys.emplace_back(key_str.back());
|
|
|
|
}
|
2022-06-17 23:40:47 +00:00
|
|
|
db_->MultiGet(readoptionscopy, cfh, num_keys, keys.data(), values.data(),
|
2019-12-09 07:49:32 +00:00
|
|
|
statuses.data());
|
|
|
|
for (auto s : statuses) {
|
|
|
|
if (s.ok()) {
|
|
|
|
// found case
|
|
|
|
thread->stats.AddGets(1, 1);
|
|
|
|
} else if (s.IsNotFound()) {
|
|
|
|
// not found case
|
|
|
|
thread->stats.AddGets(1, 0);
|
|
|
|
} else {
|
|
|
|
// errors case
|
2020-01-03 00:43:55 +00:00
|
|
|
fprintf(stderr, "MultiGet error: %s\n", s.ToString().c_str());
|
2019-12-09 07:49:32 +00:00
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return statuses;
|
|
|
|
}
|
|
|
|
|
2019-12-09 22:36:10 +00:00
|
|
|
Status TestPrefixScan(ThreadState* thread, const ReadOptions& readoptions,
|
|
|
|
const std::vector<int>& rand_column_families,
|
|
|
|
const std::vector<int64_t>& rand_keys) override {
|
2019-12-09 07:49:32 +00:00
|
|
|
size_t prefix_to_use =
|
|
|
|
(FLAGS_prefix_size < 0) ? 7 : static_cast<size_t>(FLAGS_prefix_size);
|
|
|
|
|
|
|
|
std::string key_str = Key(rand_keys[0]);
|
|
|
|
Slice key = key_str;
|
|
|
|
Slice prefix = Slice(key.data(), prefix_to_use);
|
|
|
|
|
|
|
|
std::string upper_bound;
|
|
|
|
Slice ub_slice;
|
|
|
|
ReadOptions ro_copy = readoptions;
|
2020-01-10 05:25:40 +00:00
|
|
|
// Get the next prefix first and then see if we want to set upper bound.
|
|
|
|
// We'll use the next prefix in an assertion later on
|
|
|
|
if (GetNextPrefix(prefix, &upper_bound) && thread->rand.OneIn(2)) {
|
2019-12-09 07:49:32 +00:00
|
|
|
ub_slice = Slice(upper_bound);
|
|
|
|
ro_copy.iterate_upper_bound = &ub_slice;
|
|
|
|
}
|
|
|
|
auto cfh =
|
|
|
|
column_families_[rand_column_families[thread->rand.Next() %
|
|
|
|
rand_column_families.size()]];
|
|
|
|
Iterator* iter = db_->NewIterator(ro_copy, cfh);
|
2020-01-10 05:25:40 +00:00
|
|
|
unsigned long count = 0;
|
2019-12-09 07:49:32 +00:00
|
|
|
for (iter->Seek(prefix); iter->Valid() && iter->key().starts_with(prefix);
|
|
|
|
iter->Next()) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
assert(prefix_to_use == 0 ||
|
2020-01-10 05:25:40 +00:00
|
|
|
count <= GetPrefixKeyCount(prefix.ToString(), upper_bound));
|
2019-12-09 07:49:32 +00:00
|
|
|
Status s = iter->status();
|
|
|
|
if (s.ok()) {
|
|
|
|
thread->stats.AddPrefixes(1, count);
|
|
|
|
} else {
|
2020-01-03 00:43:55 +00:00
|
|
|
fprintf(stderr, "TestPrefixScan error: %s\n", s.ToString().c_str());
|
2019-12-09 07:49:32 +00:00
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
}
|
|
|
|
delete iter;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-12-09 22:36:10 +00:00
|
|
|
ColumnFamilyHandle* GetControlCfh(ThreadState* thread,
|
|
|
|
int /*column_family_id*/
|
|
|
|
) override {
|
2019-12-09 07:49:32 +00:00
|
|
|
// All column families should contain the same data. Randomly pick one.
|
|
|
|
return column_families_[thread->rand.Next() % column_families_.size()];
|
|
|
|
}
|
|
|
|
|
2019-12-09 22:36:10 +00:00
|
|
|
void VerifyDb(ThreadState* thread) const override {
|
2022-02-17 07:17:03 +00:00
|
|
|
// This `ReadOptions` is for validation purposes. Ignore
|
|
|
|
// `FLAGS_rate_limit_user_ops` to avoid slowing any validation.
|
2019-12-09 07:49:32 +00:00
|
|
|
ReadOptions options(FLAGS_verify_checksum, true);
|
|
|
|
// We must set total_order_seek to true because we are doing a SeekToFirst
|
|
|
|
// on a column family whose memtables may support (by default) prefix-based
|
|
|
|
// iterator. In this case, NewIterator with options.total_order_seek being
|
|
|
|
// false returns a prefix-based iterator. Calling SeekToFirst using this
|
|
|
|
// iterator causes the iterator to become invalid. That means we cannot
|
|
|
|
// iterate the memtable using this iterator any more, although the memtable
|
|
|
|
// contains the most up-to-date key-values.
|
|
|
|
options.total_order_seek = true;
|
2019-12-20 16:46:52 +00:00
|
|
|
const auto ss_deleter = [this](const Snapshot* ss) {
|
|
|
|
db_->ReleaseSnapshot(ss);
|
|
|
|
};
|
|
|
|
std::unique_ptr<const Snapshot, decltype(ss_deleter)> snapshot_guard(
|
|
|
|
db_->GetSnapshot(), ss_deleter);
|
|
|
|
options.snapshot = snapshot_guard.get();
|
2019-12-09 07:49:32 +00:00
|
|
|
assert(thread != nullptr);
|
|
|
|
auto shared = thread->shared;
|
|
|
|
std::vector<std::unique_ptr<Iterator>> iters(column_families_.size());
|
|
|
|
for (size_t i = 0; i != column_families_.size(); ++i) {
|
|
|
|
iters[i].reset(db_->NewIterator(options, column_families_[i]));
|
|
|
|
}
|
|
|
|
for (auto& iter : iters) {
|
|
|
|
iter->SeekToFirst();
|
|
|
|
}
|
|
|
|
size_t num = column_families_.size();
|
|
|
|
assert(num == iters.size());
|
|
|
|
std::vector<Status> statuses(num, Status::OK());
|
|
|
|
do {
|
|
|
|
if (shared->HasVerificationFailedYet()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
size_t valid_cnt = 0;
|
|
|
|
size_t idx = 0;
|
|
|
|
for (auto& iter : iters) {
|
|
|
|
if (iter->Valid()) {
|
|
|
|
++valid_cnt;
|
|
|
|
} else {
|
|
|
|
statuses[idx] = iter->status();
|
|
|
|
}
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
if (valid_cnt == 0) {
|
|
|
|
Status status;
|
|
|
|
for (size_t i = 0; i != num; ++i) {
|
|
|
|
const auto& s = statuses[i];
|
|
|
|
if (!s.ok()) {
|
|
|
|
status = s;
|
|
|
|
fprintf(stderr, "Iterator on cf %s has error: %s\n",
|
|
|
|
column_families_[i]->GetName().c_str(),
|
|
|
|
s.ToString().c_str());
|
|
|
|
shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else if (valid_cnt != iters.size()) {
|
|
|
|
shared->SetVerificationFailure();
|
|
|
|
for (size_t i = 0; i != num; ++i) {
|
|
|
|
if (!iters[i]->Valid()) {
|
|
|
|
if (statuses[i].ok()) {
|
|
|
|
fprintf(stderr, "Finished scanning cf %s\n",
|
|
|
|
column_families_[i]->GetName().c_str());
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Iterator on cf %s has error: %s\n",
|
|
|
|
column_families_[i]->GetName().c_str(),
|
|
|
|
statuses[i].ToString().c_str());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "cf %s has remaining data to scan\n",
|
|
|
|
column_families_[i]->GetName().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (shared->HasVerificationFailedYet()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// If the program reaches here, then all column families' iterators are
|
|
|
|
// still valid.
|
|
|
|
if (shared->PrintingVerificationResults()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Slice key;
|
|
|
|
Slice value;
|
|
|
|
int num_mismatched_cfs = 0;
|
|
|
|
for (size_t i = 0; i != num; ++i) {
|
|
|
|
if (i == 0) {
|
|
|
|
key = iters[i]->key();
|
|
|
|
value = iters[i]->value();
|
|
|
|
} else {
|
|
|
|
int cmp = key.compare(iters[i]->key());
|
|
|
|
if (cmp != 0) {
|
|
|
|
++num_mismatched_cfs;
|
|
|
|
if (1 == num_mismatched_cfs) {
|
|
|
|
fprintf(stderr, "Verification failed\n");
|
|
|
|
fprintf(stderr, "Latest Sequence Number: %" PRIu64 "\n",
|
|
|
|
db_->GetLatestSequenceNumber());
|
|
|
|
fprintf(stderr, "[%s] %s => %s\n",
|
|
|
|
column_families_[0]->GetName().c_str(),
|
|
|
|
key.ToString(true /* hex */).c_str(),
|
|
|
|
value.ToString(true /* hex */).c_str());
|
|
|
|
}
|
|
|
|
fprintf(stderr, "[%s] %s => %s\n",
|
|
|
|
column_families_[i]->GetName().c_str(),
|
|
|
|
iters[i]->key().ToString(true /* hex */).c_str(),
|
|
|
|
iters[i]->value().ToString(true /* hex */).c_str());
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
Slice begin_key;
|
|
|
|
Slice end_key;
|
|
|
|
if (cmp < 0) {
|
|
|
|
begin_key = key;
|
|
|
|
end_key = iters[i]->key();
|
|
|
|
} else {
|
|
|
|
begin_key = iters[i]->key();
|
|
|
|
end_key = key;
|
|
|
|
}
|
|
|
|
std::vector<KeyVersion> versions;
|
|
|
|
const size_t kMaxNumIKeys = 8;
|
|
|
|
const auto print_key_versions = [&](ColumnFamilyHandle* cfh) {
|
|
|
|
Status s = GetAllKeyVersions(db_, cfh, begin_key, end_key,
|
|
|
|
kMaxNumIKeys, &versions);
|
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "%s\n", s.ToString().c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(nullptr != cfh);
|
|
|
|
fprintf(stderr,
|
|
|
|
"Internal keys in CF '%s', [%s, %s] (max %" ROCKSDB_PRIszt
|
|
|
|
")\n",
|
|
|
|
cfh->GetName().c_str(),
|
|
|
|
begin_key.ToString(true /* hex */).c_str(),
|
|
|
|
end_key.ToString(true /* hex */).c_str(), kMaxNumIKeys);
|
|
|
|
for (const KeyVersion& kv : versions) {
|
|
|
|
fprintf(stderr, " key %s seq %" PRIu64 " type %d\n",
|
|
|
|
Slice(kv.user_key).ToString(true).c_str(), kv.sequence,
|
|
|
|
kv.type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (1 == num_mismatched_cfs) {
|
|
|
|
print_key_versions(column_families_[0]);
|
|
|
|
}
|
|
|
|
print_key_versions(column_families_[i]);
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
shared->SetVerificationFailure();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
shared->FinishPrintingVerificationResults();
|
|
|
|
for (auto& iter : iters) {
|
|
|
|
iter->Next();
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2019-12-20 16:46:52 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
void ContinuouslyVerifyDb(ThreadState* thread) const override {
|
|
|
|
assert(thread);
|
|
|
|
Status status;
|
|
|
|
|
|
|
|
DB* db_ptr = cmp_db_ ? cmp_db_ : db_;
|
|
|
|
const auto& cfhs = cmp_db_ ? cmp_cfhs_ : column_families_;
|
2022-06-08 04:07:47 +00:00
|
|
|
|
|
|
|
// Take a snapshot to preserve the state of primary db.
|
|
|
|
ManagedSnapshot snapshot_guard(db_);
|
|
|
|
|
2019-12-20 16:46:52 +00:00
|
|
|
SharedState* shared = thread->shared;
|
|
|
|
assert(shared);
|
2022-06-08 04:07:47 +00:00
|
|
|
|
|
|
|
if (cmp_db_) {
|
|
|
|
status = cmp_db_->TryCatchUpWithPrimary();
|
|
|
|
if (!status.ok()) {
|
|
|
|
fprintf(stderr, "TryCatchUpWithPrimary: %s\n",
|
|
|
|
status.ToString().c_str());
|
|
|
|
shared->SetShouldStopTest();
|
|
|
|
assert(false);
|
|
|
|
return;
|
|
|
|
}
|
2019-12-20 16:46:52 +00:00
|
|
|
}
|
2022-06-08 04:07:47 +00:00
|
|
|
|
2019-12-20 16:46:52 +00:00
|
|
|
const auto checksum_column_family = [](Iterator* iter,
|
|
|
|
uint32_t* checksum) -> Status {
|
|
|
|
assert(nullptr != checksum);
|
|
|
|
uint32_t ret = 0;
|
|
|
|
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
|
|
|
ret = crc32c::Extend(ret, iter->key().data(), iter->key().size());
|
|
|
|
ret = crc32c::Extend(ret, iter->value().data(), iter->value().size());
|
|
|
|
}
|
|
|
|
*checksum = ret;
|
|
|
|
return iter->status();
|
|
|
|
};
|
2022-02-17 07:17:03 +00:00
|
|
|
// This `ReadOptions` is for validation purposes. Ignore
|
|
|
|
// `FLAGS_rate_limit_user_ops` to avoid slowing any validation.
|
2022-06-08 04:07:47 +00:00
|
|
|
ReadOptions ropts(FLAGS_verify_checksum, true);
|
2019-12-20 16:46:52 +00:00
|
|
|
ropts.total_order_seek = true;
|
2022-06-08 04:07:47 +00:00
|
|
|
if (nullptr == cmp_db_) {
|
|
|
|
ropts.snapshot = snapshot_guard.snapshot();
|
|
|
|
}
|
2019-12-20 16:46:52 +00:00
|
|
|
uint32_t crc = 0;
|
|
|
|
{
|
|
|
|
// Compute crc for all key-values of default column family.
|
|
|
|
std::unique_ptr<Iterator> it(db_ptr->NewIterator(ropts));
|
|
|
|
status = checksum_column_family(it.get(), &crc);
|
2022-06-08 04:07:47 +00:00
|
|
|
if (!status.ok()) {
|
|
|
|
fprintf(stderr, "Computing checksum of default cf: %s\n",
|
|
|
|
status.ToString().c_str());
|
|
|
|
assert(false);
|
|
|
|
}
|
2019-12-20 16:46:52 +00:00
|
|
|
}
|
2022-06-08 04:07:47 +00:00
|
|
|
// Since we currently intentionally disallow reading from the secondary
|
|
|
|
// instance with snapshot, we cannot achieve cross-cf consistency if WAL is
|
|
|
|
// enabled because there is no guarantee that secondary instance replays
|
|
|
|
// the primary's WAL to a consistent point where all cfs have the same
|
|
|
|
// data.
|
|
|
|
if (status.ok() && FLAGS_disable_wal) {
|
|
|
|
uint32_t tmp_crc = 0;
|
2019-12-20 16:46:52 +00:00
|
|
|
for (ColumnFamilyHandle* cfh : cfhs) {
|
|
|
|
if (cfh == db_ptr->DefaultColumnFamily()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
std::unique_ptr<Iterator> it(db_ptr->NewIterator(ropts, cfh));
|
|
|
|
status = checksum_column_family(it.get(), &tmp_crc);
|
|
|
|
if (!status.ok() || tmp_crc != crc) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-06-08 04:07:47 +00:00
|
|
|
if (!status.ok()) {
|
|
|
|
fprintf(stderr, "status: %s\n", status.ToString().c_str());
|
|
|
|
shared->SetShouldStopTest();
|
|
|
|
assert(false);
|
|
|
|
} else if (tmp_crc != crc) {
|
|
|
|
fprintf(stderr, "tmp_crc=%" PRIu32 " crc=%" PRIu32 "\n", tmp_crc, crc);
|
|
|
|
shared->SetShouldStopTest();
|
|
|
|
assert(false);
|
|
|
|
}
|
2019-12-20 16:46:52 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-08 04:07:47 +00:00
|
|
|
#else // ROCKSDB_LITE
|
|
|
|
void ContinuouslyVerifyDb(ThreadState* /*thread*/) const override {}
|
2019-12-20 16:46:52 +00:00
|
|
|
#endif // !ROCKSDB_LITE
|
|
|
|
|
2019-12-09 22:36:10 +00:00
|
|
|
std::vector<int> GenerateColumnFamilies(
|
|
|
|
const int /* num_column_families */,
|
|
|
|
int /* rand_column_family */) const override {
|
2019-12-09 07:49:32 +00:00
|
|
|
std::vector<int> ret;
|
|
|
|
int num = static_cast<int>(column_families_.size());
|
|
|
|
int k = 0;
|
|
|
|
std::generate_n(back_inserter(ret), num, [&k]() -> int { return k++; });
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
Add the PutEntity API to the stress/crash tests (#10760)
Summary:
The patch adds the `PutEntity` API to the non-batched, batched, and
CF consistency stress tests. Namely, when the new `db_stress` command
line parameter `use_put_entity_one_in` is greater than zero, one in
N writes on average is performed using `PutEntity` rather than `Put`.
The wide-column entity written has the generated value in its default
column; in addition, it contains up to three additional columns where
the original generated value is divided up between the column name and the
column value (with the column name containing the first k characters of
the generated value, and the column value containing the rest). Whether
`PutEntity` is used (and if so, how many columns the entity has) is completely
determined by the "value base" used to generate the value (that is, there is
no randomness involved). Assuming the same `use_put_entity_one_in` setting
is used across `db_stress` invocations, this enables us to reconstruct and
validate the entity during subsequent `db_stress` runs.
Note that `PutEntity` is currently incompatible with `Merge`, transactions, and
user-defined timestamps; these combinations are currently disabled/disallowed.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/10760
Test Plan: Ran some batched, non-batched, and CF consistency stress tests using the script.
Reviewed By: riversand963
Differential Revision: D39939032
Pulled By: ltamasi
fbshipit-source-id: eafdf124e95993fb7d73158e3b006d11819f7fa9
2022-09-30 18:11:07 +00:00
|
|
|
std::atomic<uint32_t> batch_id_;
|
2019-12-09 07:49:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
StressTest* CreateCfConsistencyStressTest() {
|
|
|
|
return new CfConsistencyStressTest();
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2019-12-09 07:49:32 +00:00
|
|
|
#endif // GFLAGS
|