From 8c252046334837cdd75d3d8edb1ee313d76ab333 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Mon, 17 Sep 2018 12:23:38 -0700 Subject: [PATCH] Support manual flush in stress/crash tests (#4368) Summary: - Made stress test call `Flush()` periodically according to `--flush_one_in` flag. - Enabled by default in crash test. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4368 Differential Revision: D9838593 Pulled By: ajkr fbshipit-source-id: fe5a6e49b36e5ea752acc3aa8be364f8ef34d9cc --- tools/db_crashtest.py | 1 + tools/db_stress.cc | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/db_crashtest.py b/tools/db_crashtest.py index d6ae40c28..7384d3d85 100644 --- a/tools/db_crashtest.py +++ b/tools/db_crashtest.py @@ -32,6 +32,7 @@ default_params = { "destroy_db_initially": 0, "enable_pipelined_write": lambda: random.randint(0, 1), "expected_values_path": expected_values_file.name, + "flush_one_in": 1000000, "max_background_compactions": 20, "max_bytes_for_level_base": 10485760, "max_key": 100000000, diff --git a/tools/db_stress.cc b/tools/db_stress.cc index 1041f235e..f012771b8 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -412,6 +412,10 @@ DEFINE_int32(compact_range_one_in, 0, "If non-zero, then CompactRange() will be called once for every N " "operations on average. 0 indicates CompactRange() is disabled."); +DEFINE_int32(flush_one_in, 0, + "If non-zero, then Flush() will be called once for every N ops " + "on average. 0 indicates calls to Flush() are disabled."); + DEFINE_int32(compact_range_width, 10000, "The width of the ranges passed to CompactRange()."); @@ -1943,8 +1947,8 @@ class StressTest { db_->CompactFiles(CompactionOptions(), random_cf, input_files, static_cast(output_level)); if (!s.ok()) { - printf("Unable to perform CompactFiles(): %s\n", - s.ToString().c_str()); + fprintf(stdout, "Unable to perform CompactFiles(): %s\n", + s.ToString().c_str()); thread->stats.AddNumCompactFilesFailed(1); } else { thread->stats.AddNumCompactFilesSucceed(1); @@ -1966,6 +1970,15 @@ class StressTest { auto column_family = column_families_[rand_column_family]; + if (FLAGS_flush_one_in > 0 && + thread->rand.Uniform(FLAGS_flush_one_in) == 0) { + FlushOptions flush_opts; + Status status = db_->Flush(flush_opts, column_family); + if (!status.ok()) { + fprintf(stdout, "Unable to perform Flush(): %s\n", status.ToString().c_str()); + } + } + if (FLAGS_compact_range_one_in > 0 && thread->rand.Uniform(FLAGS_compact_range_one_in) == 0) { int64_t end_key_num;