From 7aa96db7a20b0ca6e58f92e9b308324f25808aff Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Tue, 15 Aug 2017 11:53:00 -0700 Subject: [PATCH] db_stress rolling active window Summary: Support a window of `active_width` keys that rolls through `[0, max_key)` over the duration of the test. Operations only affect keys inside the window. This gives us the ability to detect L0->L0 deletion bug (#2722). Closes https://github.com/facebook/rocksdb/pull/2739 Differential Revision: D5628555 Pulled By: ajkr fbshipit-source-id: 9cb2d8f4ab1a7c73f7797b8e19f7094970ea8749 --- tools/db_stress.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/db_stress.cc b/tools/db_stress.cc index db905f0c8..c7153f2e9 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -93,6 +93,13 @@ DEFINE_int64(max_key, 1 * KB* KB, DEFINE_int32(column_families, 10, "Number of column families"); +DEFINE_int64( + active_width, 0, + "Number of keys in active span of the key-range at any given time. The " + "span begins with its left endpoint at key 0, gradually moves rightwards, " + "and ends with its right endpoint at max_key. If set to 0, active_width " + "will be sanitized to be equal to max_key."); + // TODO(noetzli) Add support for single deletes DEFINE_bool(test_batches_snapshots, false, "If set, the test uses MultiGet(), MultiPut() and MultiDelete()" @@ -1727,7 +1734,11 @@ class StressTest { } #endif // !ROCKSDB_LITE - long rand_key = thread->rand.Next() % max_key; + const double completed_ratio = + static_cast(i) / FLAGS_ops_per_thread; + const int64_t base_key = static_cast( + completed_ratio * (FLAGS_max_key - FLAGS_active_width)); + long rand_key = base_key + thread->rand.Next() % FLAGS_active_width; int rand_column_family = thread->rand.Next() % FLAGS_column_families; std::string keystr = Key(rand_key); Slice key = keystr; @@ -2433,6 +2444,12 @@ int main(int argc, char** argv) { "test_batches_snapshots mode\n"); exit(1); } + if (FLAGS_active_width > FLAGS_max_key) { + fprintf(stderr, "Error: active_width can be at most max_key\n"); + exit(1); + } else if (FLAGS_active_width == 0) { + FLAGS_active_width = FLAGS_max_key; + } // Choose a location for the test database if none given with --db= if (FLAGS_db.empty()) {