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-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2019-12-09 07:49:32 +00:00
|
|
|
class BatchedOpsStressTest : public StressTest {
|
|
|
|
public:
|
|
|
|
BatchedOpsStressTest() {}
|
|
|
|
virtual ~BatchedOpsStressTest() {}
|
|
|
|
|
2021-12-07 21:40:46 +00:00
|
|
|
bool IsStateTracked() const override { return false; }
|
|
|
|
|
2022-10-26 00:51:20 +00:00
|
|
|
// Given a key K and value V, this puts ("0"+K, V+"0"), ("1"+K, V+"1"), ...,
|
|
|
|
// ("9"+K, V+"9") in DB atomically i.e in a single batch.
|
2019-12-09 07:49:32 +00:00
|
|
|
// Also refer BatchedOpsStressTest::TestGet
|
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());
|
|
|
|
|
2022-10-26 00:51:20 +00:00
|
|
|
const std::string key_body = Key(rand_keys[0]);
|
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 uint32_t value_base =
|
2019-12-09 07:49:32 +00:00
|
|
|
thread->rand.Next() % thread->shared->UNKNOWN_SENTINEL;
|
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 size_t sz = GenerateValue(value_base, value, sizeof(value));
|
2022-10-26 00:51:20 +00:00
|
|
|
const std::string value_body = Slice(value, sz).ToString();
|
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
|
|
|
|
2021-09-12 22:33:15 +00:00
|
|
|
WriteBatch batch(0 /* reserved_bytes */, 0 /* max_bytes */,
|
Revise APIs related to user-defined timestamp (#8946)
Summary:
ajkr reminded me that we have a rule of not including per-kv related data in `WriteOptions`.
Namely, `WriteOptions` should not include information about "what-to-write", but should just
include information about "how-to-write".
According to this rule, `WriteOptions::timestamp` (experimental) is clearly a violation. Therefore,
this PR removes `WriteOptions::timestamp` for compliance.
After the removal, we need to pass timestamp info via another set of APIs. This PR proposes a set
of overloaded functions `Put(write_opts, key, value, ts)`, `Delete(write_opts, key, ts)`, and
`SingleDelete(write_opts, key, ts)`. Planned to add `Write(write_opts, batch, ts)`, but its complexity
made me reconsider doing it in another PR (maybe).
For better checking and returning error early, we also add a new set of APIs to `WriteBatch` that take
extra `timestamp` information when writing to `WriteBatch`es.
These set of APIs in `WriteBatchWithIndex` are currently not supported, and are on our TODO list.
Removed `WriteBatch::AssignTimestamps()` and renamed `WriteBatch::AssignTimestamp()` to
`WriteBatch::UpdateTimestamps()` since this method require that all keys have space for timestamps
allocated already and multiple timestamps can be updated.
The constructor of `WriteBatch` now takes a fourth argument `default_cf_ts_sz` which is the timestamp
size of the default column family. This will be used to allocate space when calling APIs that do not
specify a column family handle.
Also, updated `DB::Get()`, `DB::MultiGet()`, `DB::NewIterator()`, `DB::NewIterators()` methods, replacing
some assertions about timestamp to returning Status code.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8946
Test Plan:
make check
./db_bench -benchmarks=fillseq,fillrandom,readrandom,readseq,deleterandom -user_timestamp_size=8
./db_stress --user_timestamp_size=8 -nooverwritepercent=0 -test_secondary=0 -secondary_catch_up_one_in=0 -continuous_verification_interval=0
Make sure there is no perf regression by running the following
```
./db_bench_opt -db=/dev/shm/rocksdb -use_existing_db=0 -level0_stop_writes_trigger=256 -level0_slowdown_writes_trigger=256 -level0_file_num_compaction_trigger=256 -disable_wal=1 -duration=10 -benchmarks=fillrandom
```
Before this PR
```
DB path: [/dev/shm/rocksdb]
fillrandom : 1.831 micros/op 546235 ops/sec; 60.4 MB/s
```
After this PR
```
DB path: [/dev/shm/rocksdb]
fillrandom : 1.820 micros/op 549404 ops/sec; 60.8 MB/s
```
Reviewed By: ltamasi
Differential Revision: D33721359
Pulled By: riversand963
fbshipit-source-id: c131561534272c120ffb80711d42748d21badf09
2022-02-02 06:17:46 +00:00
|
|
|
FLAGS_batch_protection_bytes_per_key,
|
|
|
|
FLAGS_user_timestamp_size);
|
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_[rand_column_families[0]];
|
|
|
|
assert(cfh);
|
|
|
|
|
|
|
|
for (int i = 9; i >= 0; --i) {
|
2022-10-26 00:51:20 +00:00
|
|
|
const std::string num = std::to_string(i);
|
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
|
|
|
|
2022-10-26 00:51:20 +00:00
|
|
|
// Note: the digit in num is prepended to the key; however, it is appended
|
|
|
|
// to the value because we want the "value base" to be encoded uniformly
|
|
|
|
// at the beginning of the value for all types of stress tests (e.g.
|
|
|
|
// batched, non-batched, CF consistency).
|
|
|
|
const std::string k = num + key_body;
|
|
|
|
const std::string v = value_body + num;
|
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 (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 (FLAGS_use_put_entity_one_in > 0 &&
|
|
|
|
(value_base % FLAGS_use_put_entity_one_in) == 0) {
|
|
|
|
batch.PutEntity(cfh, k, GenerateWideColumns(value_base, v));
|
2019-12-09 07:49:32 +00:00
|
|
|
} else {
|
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.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
|
|
|
const Status s = db_->Write(write_opts, &batch);
|
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "multiput error: %s\n", s.ToString().c_str());
|
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
} else {
|
|
|
|
// we did 10 writes each of size sz + 1
|
|
|
|
thread->stats.AddBytesForWrites(10, (sz + 1) * 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:51:20 +00:00
|
|
|
// Given a key K, this deletes ("0"+K), ("1"+K), ..., ("9"+K)
|
2019-12-09 07:49:32 +00:00
|
|
|
// in DB atomically i.e in a single batch. Also refer MultiGet.
|
2019-12-09 22:36:10 +00:00
|
|
|
Status TestDelete(ThreadState* thread, WriteOptions& writeoptions,
|
|
|
|
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 keys[10] = {"9", "7", "5", "3", "1", "8", "6", "4", "2", "0"};
|
|
|
|
|
2021-09-12 22:33:15 +00:00
|
|
|
WriteBatch batch(0 /* reserved_bytes */, 0 /* max_bytes */,
|
Revise APIs related to user-defined timestamp (#8946)
Summary:
ajkr reminded me that we have a rule of not including per-kv related data in `WriteOptions`.
Namely, `WriteOptions` should not include information about "what-to-write", but should just
include information about "how-to-write".
According to this rule, `WriteOptions::timestamp` (experimental) is clearly a violation. Therefore,
this PR removes `WriteOptions::timestamp` for compliance.
After the removal, we need to pass timestamp info via another set of APIs. This PR proposes a set
of overloaded functions `Put(write_opts, key, value, ts)`, `Delete(write_opts, key, ts)`, and
`SingleDelete(write_opts, key, ts)`. Planned to add `Write(write_opts, batch, ts)`, but its complexity
made me reconsider doing it in another PR (maybe).
For better checking and returning error early, we also add a new set of APIs to `WriteBatch` that take
extra `timestamp` information when writing to `WriteBatch`es.
These set of APIs in `WriteBatchWithIndex` are currently not supported, and are on our TODO list.
Removed `WriteBatch::AssignTimestamps()` and renamed `WriteBatch::AssignTimestamp()` to
`WriteBatch::UpdateTimestamps()` since this method require that all keys have space for timestamps
allocated already and multiple timestamps can be updated.
The constructor of `WriteBatch` now takes a fourth argument `default_cf_ts_sz` which is the timestamp
size of the default column family. This will be used to allocate space when calling APIs that do not
specify a column family handle.
Also, updated `DB::Get()`, `DB::MultiGet()`, `DB::NewIterator()`, `DB::NewIterators()` methods, replacing
some assertions about timestamp to returning Status code.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8946
Test Plan:
make check
./db_bench -benchmarks=fillseq,fillrandom,readrandom,readseq,deleterandom -user_timestamp_size=8
./db_stress --user_timestamp_size=8 -nooverwritepercent=0 -test_secondary=0 -secondary_catch_up_one_in=0 -continuous_verification_interval=0
Make sure there is no perf regression by running the following
```
./db_bench_opt -db=/dev/shm/rocksdb -use_existing_db=0 -level0_stop_writes_trigger=256 -level0_slowdown_writes_trigger=256 -level0_file_num_compaction_trigger=256 -disable_wal=1 -duration=10 -benchmarks=fillrandom
```
Before this PR
```
DB path: [/dev/shm/rocksdb]
fillrandom : 1.831 micros/op 546235 ops/sec; 60.4 MB/s
```
After this PR
```
DB path: [/dev/shm/rocksdb]
fillrandom : 1.820 micros/op 549404 ops/sec; 60.8 MB/s
```
Reviewed By: ltamasi
Differential Revision: D33721359
Pulled By: riversand963
fbshipit-source-id: c131561534272c120ffb80711d42748d21badf09
2022-02-02 06:17:46 +00:00
|
|
|
FLAGS_batch_protection_bytes_per_key,
|
|
|
|
FLAGS_user_timestamp_size);
|
2019-12-09 07:49:32 +00:00
|
|
|
Status s;
|
|
|
|
auto cfh = column_families_[rand_column_families[0]];
|
|
|
|
std::string key_str = Key(rand_keys[0]);
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
keys[i] += key_str;
|
|
|
|
batch.Delete(cfh, keys[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
s = db_->Write(writeoptions, &batch);
|
|
|
|
if (!s.ok()) {
|
|
|
|
fprintf(stderr, "multidelete error: %s\n", s.ToString().c_str());
|
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
} else {
|
|
|
|
thread->stats.AddDeletes(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
assert(false);
|
|
|
|
return Status::NotSupported(
|
|
|
|
"BatchedOpsStressTest does not support "
|
|
|
|
"TestDeleteRange");
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
"BatchedOpsStressTest does not support "
|
|
|
|
"TestIngestExternalFile\n");
|
|
|
|
std::terminate();
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:51:20 +00:00
|
|
|
// Given a key K, this gets values for "0"+K, "1"+K, ..., "9"+K
|
2019-12-09 07:49:32 +00:00
|
|
|
// in the same snapshot, and verifies that all the values are of the form
|
2022-10-26 00:51:20 +00:00
|
|
|
// V+"0", V+"1", ..., V+"9".
|
2019-12-09 07:49:32 +00:00
|
|
|
// ASSUMES that BatchedOpsStressTest::TestPut was used to put (K, V) into
|
|
|
|
// the DB.
|
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 keys[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
|
|
|
|
Slice key_slices[10];
|
|
|
|
std::string values[10];
|
|
|
|
ReadOptions readoptionscopy = readoptions;
|
|
|
|
readoptionscopy.snapshot = db_->GetSnapshot();
|
|
|
|
std::string key_str = Key(rand_keys[0]);
|
|
|
|
Slice key = key_str;
|
|
|
|
auto cfh = column_families_[rand_column_families[0]];
|
|
|
|
std::string from_db;
|
|
|
|
Status s;
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
keys[i] += key.ToString();
|
|
|
|
key_slices[i] = keys[i];
|
|
|
|
s = db_->Get(readoptionscopy, cfh, key_slices[i], &from_db);
|
|
|
|
if (!s.ok() && !s.IsNotFound()) {
|
|
|
|
fprintf(stderr, "get error: %s\n", s.ToString().c_str());
|
|
|
|
values[i] = "";
|
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
// we continue after error rather than exiting so that we can
|
|
|
|
// find more errors if any
|
|
|
|
} else if (s.IsNotFound()) {
|
|
|
|
values[i] = "";
|
|
|
|
thread->stats.AddGets(1, 0);
|
|
|
|
} else {
|
|
|
|
values[i] = from_db;
|
|
|
|
|
2022-10-26 00:51:20 +00:00
|
|
|
assert(!keys[i].empty());
|
|
|
|
assert(!values[i].empty());
|
|
|
|
|
|
|
|
const char expected = keys[i].front();
|
|
|
|
const char actual = values[i].back();
|
|
|
|
|
|
|
|
if (expected != actual) {
|
|
|
|
fprintf(stderr, "get error expected = %c actual = %c\n", expected,
|
|
|
|
actual);
|
2019-12-09 07:49:32 +00:00
|
|
|
}
|
2022-10-26 00:51:20 +00:00
|
|
|
|
|
|
|
values[i].pop_back(); // get rid of the differing character
|
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
thread->stats.AddGets(1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
db_->ReleaseSnapshot(readoptionscopy.snapshot);
|
|
|
|
|
|
|
|
// Now that we retrieved all values, check that they all match
|
|
|
|
for (int i = 1; i < 10; i++) {
|
|
|
|
if (values[i] != values[0]) {
|
2022-10-26 00:51:20 +00:00
|
|
|
fprintf(stderr, "get error: inconsistent values for key %s: %s, %s\n",
|
2019-12-09 07:49:32 +00:00
|
|
|
key.ToString(true).c_str(), StringToHex(values[0]).c_str(),
|
|
|
|
StringToHex(values[i]).c_str());
|
|
|
|
// we continue after error rather than exiting so that we can
|
|
|
|
// find more errors if any
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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& readoptions,
|
|
|
|
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<Status> ret_status(num_keys);
|
2022-10-25 21:29:41 +00:00
|
|
|
std::array<std::string, 10> keys = {
|
|
|
|
{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}};
|
2019-12-09 07:49:32 +00:00
|
|
|
size_t num_prefixes = keys.size();
|
|
|
|
for (size_t rand_key = 0; rand_key < num_keys; ++rand_key) {
|
|
|
|
std::vector<Slice> key_slices;
|
|
|
|
std::vector<PinnableSlice> values(num_prefixes);
|
|
|
|
std::vector<Status> statuses(num_prefixes);
|
|
|
|
ReadOptions readoptionscopy = readoptions;
|
|
|
|
readoptionscopy.snapshot = db_->GetSnapshot();
|
2022-06-17 23:40:47 +00:00
|
|
|
readoptionscopy.rate_limiter_priority =
|
|
|
|
FLAGS_rate_limit_user_ops ? Env::IO_USER : Env::IO_TOTAL;
|
2019-12-09 07:49:32 +00:00
|
|
|
std::vector<std::string> key_str;
|
|
|
|
key_str.reserve(num_prefixes);
|
|
|
|
key_slices.reserve(num_prefixes);
|
|
|
|
std::string from_db;
|
|
|
|
ColumnFamilyHandle* cfh = column_families_[rand_column_families[0]];
|
|
|
|
|
|
|
|
for (size_t key = 0; key < num_prefixes; ++key) {
|
|
|
|
key_str.emplace_back(keys[key] + Key(rand_keys[rand_key]));
|
|
|
|
key_slices.emplace_back(key_str.back());
|
|
|
|
}
|
|
|
|
db_->MultiGet(readoptionscopy, cfh, num_prefixes, key_slices.data(),
|
|
|
|
values.data(), statuses.data());
|
|
|
|
for (size_t i = 0; i < num_prefixes; i++) {
|
|
|
|
Status s = statuses[i];
|
|
|
|
if (!s.ok() && !s.IsNotFound()) {
|
2022-10-26 00:51:20 +00:00
|
|
|
fprintf(stderr, "multiget error: %s\n", s.ToString().c_str());
|
2019-12-09 07:49:32 +00:00
|
|
|
thread->stats.AddErrors(1);
|
|
|
|
ret_status[rand_key] = s;
|
|
|
|
// we continue after error rather than exiting so that we can
|
|
|
|
// find more errors if any
|
|
|
|
} else if (s.IsNotFound()) {
|
|
|
|
thread->stats.AddGets(1, 0);
|
|
|
|
ret_status[rand_key] = s;
|
|
|
|
} else {
|
2022-10-26 00:51:20 +00:00
|
|
|
assert(!keys[i].empty());
|
|
|
|
assert(!values[i].empty());
|
|
|
|
|
|
|
|
const char expected = keys[i][0];
|
|
|
|
const char actual = values[i][values[i].size() - 1];
|
|
|
|
|
|
|
|
if (expected != actual) {
|
|
|
|
fprintf(stderr, "multiget error expected = %c actual = %c\n",
|
|
|
|
expected, actual);
|
2019-12-09 07:49:32 +00:00
|
|
|
}
|
2022-10-26 00:51:20 +00:00
|
|
|
|
|
|
|
values[i].remove_suffix(1); // get rid of the differing character
|
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
thread->stats.AddGets(1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
db_->ReleaseSnapshot(readoptionscopy.snapshot);
|
|
|
|
|
|
|
|
// Now that we retrieved all values, check that they all match
|
|
|
|
for (size_t i = 1; i < num_prefixes; i++) {
|
|
|
|
if (values[i] != values[0]) {
|
2022-10-26 00:51:20 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"multiget error: inconsistent values for key %s: %s, %s\n",
|
2021-12-21 07:28:40 +00:00
|
|
|
StringToHex(key_str[i]).c_str(),
|
|
|
|
StringToHex(values[0].ToString()).c_str(),
|
2019-12-09 07:49:32 +00:00
|
|
|
StringToHex(values[i].ToString()).c_str());
|
|
|
|
// we continue after error rather than exiting so that we can
|
|
|
|
// find more errors if any
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret_status;
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:51:20 +00:00
|
|
|
// Given a key, this does prefix scans for "0"+P, "1"+P, ..., "9"+P
|
2019-12-09 07:49:32 +00:00
|
|
|
// in the same snapshot where P is the first FLAGS_prefix_size - 1 bytes
|
|
|
|
// of the key. Each of these 10 scans returns a series of values;
|
|
|
|
// each series should be the same length, and it is verified for each
|
2022-10-26 00:51:20 +00:00
|
|
|
// index i that all the i'th values are of the form V+"0", V+"1", ..., V+"9".
|
2019-12-09 07:49:32 +00:00
|
|
|
// ASSUMES that MultiPut was used to put (K, V)
|
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 {
|
2022-10-07 18:17:57 +00:00
|
|
|
assert(!rand_column_families.empty());
|
|
|
|
assert(!rand_keys.empty());
|
|
|
|
|
|
|
|
const std::string key = Key(rand_keys[0]);
|
|
|
|
|
|
|
|
assert(FLAGS_prefix_size > 0);
|
|
|
|
const size_t prefix_to_use = static_cast<size_t>(FLAGS_prefix_size);
|
|
|
|
|
|
|
|
constexpr size_t num_prefixes = 10;
|
|
|
|
|
|
|
|
std::array<std::string, num_prefixes> prefixes;
|
|
|
|
std::array<Slice, num_prefixes> prefix_slices;
|
|
|
|
std::array<ReadOptions, num_prefixes> ro_copies;
|
|
|
|
std::array<std::string, num_prefixes> upper_bounds;
|
|
|
|
std::array<Slice, num_prefixes> ub_slices;
|
|
|
|
std::array<std::unique_ptr<Iterator>, num_prefixes> iters;
|
|
|
|
|
|
|
|
const Snapshot* const snapshot = db_->GetSnapshot();
|
|
|
|
|
|
|
|
ColumnFamilyHandle* const cfh = column_families_[rand_column_families[0]];
|
|
|
|
assert(cfh);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < num_prefixes; ++i) {
|
|
|
|
prefixes[i] = std::to_string(i) + key;
|
|
|
|
prefix_slices[i] = Slice(prefixes[i].data(), prefix_to_use);
|
|
|
|
|
|
|
|
ro_copies[i] = readoptions;
|
|
|
|
ro_copies[i].snapshot = snapshot;
|
2019-12-09 07:49:32 +00:00
|
|
|
if (thread->rand.OneIn(2) &&
|
|
|
|
GetNextPrefix(prefix_slices[i], &(upper_bounds[i]))) {
|
|
|
|
// For half of the time, set the upper bound to the next prefix
|
2022-10-07 18:17:57 +00:00
|
|
|
ub_slices[i] = upper_bounds[i];
|
|
|
|
ro_copies[i].iterate_upper_bound = &(ub_slices[i]);
|
2019-12-09 07:49:32 +00:00
|
|
|
}
|
2022-10-07 18:17:57 +00:00
|
|
|
|
|
|
|
iters[i].reset(db_->NewIterator(ro_copies[i], cfh));
|
2019-12-09 07:49:32 +00:00
|
|
|
iters[i]->Seek(prefix_slices[i]);
|
|
|
|
}
|
|
|
|
|
2022-10-07 18:17:57 +00:00
|
|
|
uint64_t count = 0;
|
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
while (iters[0]->Valid() && iters[0]->key().starts_with(prefix_slices[0])) {
|
2022-10-07 18:17:57 +00:00
|
|
|
++count;
|
|
|
|
|
|
|
|
std::array<std::string, num_prefixes> values;
|
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
// get list of all values for this iteration
|
2022-10-07 18:17:57 +00:00
|
|
|
for (size_t i = 0; i < num_prefixes; ++i) {
|
2019-12-09 07:49:32 +00:00
|
|
|
// no iterator should finish before the first one
|
|
|
|
assert(iters[i]->Valid() &&
|
|
|
|
iters[i]->key().starts_with(prefix_slices[i]));
|
|
|
|
values[i] = iters[i]->value().ToString();
|
|
|
|
|
2022-10-26 00:51:20 +00:00
|
|
|
// make sure the last character of the value is the expected digit
|
|
|
|
assert(!prefixes[i].empty());
|
|
|
|
assert(!values[i].empty());
|
|
|
|
|
|
|
|
const char expected = prefixes[i].front();
|
|
|
|
const char actual = values[i].back();
|
2019-12-09 07:49:32 +00:00
|
|
|
|
2022-10-26 00:51:20 +00:00
|
|
|
if (expected != actual) {
|
|
|
|
fprintf(stderr, "prefix scan error expected = %c actual = %c\n",
|
|
|
|
expected, actual);
|
2019-12-09 07:49:32 +00:00
|
|
|
}
|
2022-10-07 18:17:57 +00:00
|
|
|
|
2022-10-26 00:51:20 +00:00
|
|
|
values[i].pop_back(); // get rid of the differing character
|
2022-10-07 18:17:57 +00:00
|
|
|
|
|
|
|
// make sure all values are equivalent
|
2019-12-09 07:49:32 +00:00
|
|
|
if (values[i] != values[0]) {
|
|
|
|
fprintf(stderr,
|
2022-10-26 00:51:20 +00:00
|
|
|
"prefix scan error : %" ROCKSDB_PRIszt
|
2022-10-07 18:17:57 +00:00
|
|
|
", inconsistent values for prefix %s: %s, %s\n",
|
|
|
|
i, prefix_slices[i].ToString(/* hex */ true).c_str(),
|
|
|
|
StringToHex(values[0]).c_str(),
|
2019-12-09 07:49:32 +00:00
|
|
|
StringToHex(values[i]).c_str());
|
|
|
|
// we continue after error rather than exiting so that we can
|
|
|
|
// find more errors if any
|
|
|
|
}
|
2022-10-07 18:17:57 +00:00
|
|
|
|
|
|
|
// make sure value() and columns() are consistent
|
|
|
|
const WideColumns expected_columns = GenerateExpectedWideColumns(
|
2022-10-26 00:51:20 +00:00
|
|
|
GetValueBase(iters[i]->value()), iters[i]->value());
|
2022-10-07 18:17:57 +00:00
|
|
|
if (iters[i]->columns() != expected_columns) {
|
|
|
|
fprintf(stderr,
|
2022-10-26 00:51:20 +00:00
|
|
|
"prefix scan error : %" ROCKSDB_PRIszt
|
2022-10-07 18:17:57 +00:00
|
|
|
", value and columns inconsistent for prefix %s: %s\n",
|
|
|
|
i, prefix_slices[i].ToString(/* hex */ true).c_str(),
|
|
|
|
DebugString(iters[i]->value(), iters[i]->columns(),
|
|
|
|
expected_columns)
|
|
|
|
.c_str());
|
|
|
|
}
|
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
iters[i]->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup iterators and snapshot
|
2022-10-07 18:17:57 +00:00
|
|
|
for (size_t i = 0; i < num_prefixes; ++i) {
|
2019-12-09 07:49:32 +00:00
|
|
|
// if the first iterator finished, they should have all finished
|
|
|
|
assert(!iters[i]->Valid() ||
|
|
|
|
!iters[i]->key().starts_with(prefix_slices[i]));
|
|
|
|
assert(iters[i]->status().ok());
|
|
|
|
}
|
2022-10-07 18:17:57 +00:00
|
|
|
|
2019-12-09 07:49:32 +00:00
|
|
|
db_->ReleaseSnapshot(snapshot);
|
|
|
|
|
2022-10-07 18:17:57 +00:00
|
|
|
thread->stats.AddPrefixes(1, count);
|
2019-12-09 07:49:32 +00:00
|
|
|
|
2022-10-07 18:17:57 +00:00
|
|
|
return Status::OK();
|
2019-12-09 07:49:32 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 22:36:10 +00:00
|
|
|
void VerifyDb(ThreadState* /* thread */) const override {}
|
2022-06-08 04:07:47 +00:00
|
|
|
|
|
|
|
void ContinuouslyVerifyDb(ThreadState* /* thread */) const override {}
|
2019-12-09 07:49:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
StressTest* CreateBatchedOpsStressTest() { return new BatchedOpsStressTest(); }
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2019-12-09 07:49:32 +00:00
|
|
|
#endif // GFLAGS
|