mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-25 22:44:05 +00:00
db_stress support long-held snapshots
Summary: Add options to `db_stress` (correctness testing tool) to randomly acquire snapshot and release it after some period of time. It's useful for correctness testing of #3009, as well as other parts of compaction that behave differently depending on which snapshots are held. Closes https://github.com/facebook/rocksdb/pull/3038 Differential Revision: D6086501 Pulled By: ajkr fbshipit-source-id: 3ec0d8666c78ac507f1f808887c4ff759ba9b865
This commit is contained in:
parent
f8b5bb2fd8
commit
d75793d6b4
|
@ -17,6 +17,7 @@ import argparse
|
|||
# simple_default_params < blackbox|whitebox_simple_default_params < args
|
||||
|
||||
default_params = {
|
||||
"acquire_snapshot_one_in": 10000,
|
||||
"block_size": 16384,
|
||||
"cache_size": 1048576,
|
||||
"use_clock_cache": "false",
|
||||
|
@ -37,6 +38,7 @@ default_params = {
|
|||
"progress_reports": 0,
|
||||
"readpercent": 45,
|
||||
"reopen": 20,
|
||||
"snapshot_hold_ops": 100000,
|
||||
"sync": 0,
|
||||
"target_file_size_base": 2097152,
|
||||
"target_file_size_multiplier": 2,
|
||||
|
|
|
@ -355,6 +355,14 @@ DEFINE_int32(compact_files_one_in, 0,
|
|||
"If non-zero, then CompactFiles() will be called one for every N "
|
||||
"operations IN AVERAGE. 0 indicates CompactFiles() is disabled.");
|
||||
|
||||
DEFINE_int32(acquire_snapshot_one_in, 0,
|
||||
"If non-zero, then acquires a snapshot once every N operations on "
|
||||
"average.");
|
||||
|
||||
DEFINE_uint64(snapshot_hold_ops, 0,
|
||||
"If non-zero, then releases snapshots N operations after they're "
|
||||
"acquired.");
|
||||
|
||||
static bool ValidateInt32Percent(const char* flagname, int32_t value) {
|
||||
if (value < 0 || value>100) {
|
||||
fprintf(stderr, "Invalid value for --%s: %d, 0<= pct <=100 \n",
|
||||
|
@ -1649,6 +1657,7 @@ class StressTest {
|
|||
const int delRangeBound = delBound + (int)FLAGS_delrangepercent;
|
||||
|
||||
thread->stats.Start();
|
||||
std::queue<std::pair<uint64_t, const Snapshot*> > snapshot_queue;
|
||||
for (uint64_t i = 0; i < FLAGS_ops_per_thread; i++) {
|
||||
if (thread->shared->HasVerificationFailedYet()) {
|
||||
break;
|
||||
|
@ -1768,6 +1777,16 @@ class StressTest {
|
|||
}
|
||||
}
|
||||
#endif // !ROCKSDB_LITE
|
||||
if (FLAGS_acquire_snapshot_one_in > 0 &&
|
||||
thread->rand.Uniform(FLAGS_acquire_snapshot_one_in) == 0) {
|
||||
snapshot_queue.emplace(
|
||||
std::min(FLAGS_ops_per_thread - 1, i + FLAGS_snapshot_hold_ops),
|
||||
db_->GetSnapshot());
|
||||
}
|
||||
if (!snapshot_queue.empty() && i == snapshot_queue.front().first) {
|
||||
db_->ReleaseSnapshot(snapshot_queue.front().second);
|
||||
snapshot_queue.pop();
|
||||
}
|
||||
|
||||
const double completed_ratio =
|
||||
static_cast<double>(i) / FLAGS_ops_per_thread;
|
||||
|
|
Loading…
Reference in a new issue