diff --git a/tools/db_crashtest.py b/tools/db_crashtest.py index 5c91e76cc..063a3ce9f 100644 --- a/tools/db_crashtest.py +++ b/tools/db_crashtest.py @@ -25,6 +25,8 @@ default_params = { "block_size": 16384, "cache_size": 1048576, "clear_column_family_one_in": 0, + "compact_files_one_in": 1000000, + "compact_range_one_in": 1000000, "delpercent": 5, "destroy_db_initially": 0, "expected_values_path": expected_values_file.name, diff --git a/tools/db_stress.cc b/tools/db_stress.cc index ce83a037d..d363fd7e1 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -382,10 +382,16 @@ DEFINE_bool(use_txn, false, "Use TransactionDB. Currently the default write policy is " "TxnDBWritePolicy::WRITE_PREPARED"); -// Temporarily disable this to allows it to detect new bugs 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."); + "If non-zero, then CompactFiles() will be called once for every N " + "operations on average. 0 indicates CompactFiles() is disabled."); + +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(compact_range_width, 10000, + "The width of the ranges passed to CompactRange()."); DEFINE_int32(acquire_snapshot_one_in, 0, "If non-zero, then acquires a snapshot once every N operations on " @@ -1813,6 +1819,27 @@ class StressTest { auto column_family = column_families_[rand_column_family]; + if (FLAGS_compact_range_one_in > 0 && + thread->rand.Uniform(FLAGS_compact_range_one_in) == 0) { + int64_t end_key_num; + if (port::kMaxInt64 - rand_key < FLAGS_compact_range_width) { + end_key_num = port::kMaxInt64; + } else { + end_key_num = FLAGS_compact_range_width + rand_key; + } + std::string end_key_buf = Key(end_key_num); + Slice end_key(end_key_buf); + + CompactRangeOptions cro; + cro.exclusive_manual_compaction = + static_cast(thread->rand.Next() % 2); + Status status = db_->CompactRange(cro, column_family, &key, &end_key); + if (!status.ok()) { + printf("Unable to perform CompactRange(): %s\n", + status.ToString().c_str()); + } + } + if (FLAGS_acquire_snapshot_one_in > 0 && thread->rand.Uniform(FLAGS_acquire_snapshot_one_in) == 0) { auto snapshot = db_->GetSnapshot();