From a180c5cc3a3e12e5197a85dbc3b556b8c7e8bd12 Mon Sep 17 00:00:00 2001 From: Changyu Bi Date: Tue, 5 Apr 2022 14:56:28 -0700 Subject: [PATCH] Added GetMergeOperands() to stress test (#9804) Summary: db_stress does not yet cover is GetMergeOperands(), added GetMergeOperands() to db_stress. Pull Request resolved: https://github.com/facebook/rocksdb/pull/9804 Test Plan: ```make -j32 db_stress``` ```python3 tools/db_crashtest.py blackbox --simple --interval=30 --duration=2400 --max_key=100000 --write_buffer_size=524288 --target_file_size_base=524288 --max_bytes_for_level_base=2097152 --value_size_mult=33``` Reviewed By: ajkr Differential Revision: D35387137 Pulled By: cbi42 fbshipit-source-id: 8f851ef68b5af4d824128ad55ebe564f7ad6f7e6 --- db_stress_tool/no_batched_ops_stress.cc | 53 ++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/db_stress_tool/no_batched_ops_stress.cc b/db_stress_tool/no_batched_ops_stress.cc index b8b51d81e..c14487da8 100644 --- a/db_stress_tool/no_batched_ops_stress.cc +++ b/db_stress_tool/no_batched_ops_stress.cc @@ -45,8 +45,8 @@ class NonBatchedOpsStressTest : public StressTest { if (thread->shared->HasVerificationFailedYet()) { break; } - if (thread->rand.OneIn(3)) { - // 1/3 chance use iterator to verify this range + if (thread->rand.OneIn(4)) { + // 1/4 chance use iterator to verify this range Slice prefix; std::string seek_key = Key(start); std::unique_ptr iter( @@ -91,8 +91,8 @@ class NonBatchedOpsStressTest : public StressTest { from_db.data(), from_db.length()); } } - } else if (thread->rand.OneIn(2)) { - // 1/3 chance use Get to verify this range + } else if (thread->rand.OneIn(3)) { + // 1/4 chance use Get to verify this range for (auto i = start; i < end; i++) { if (thread->shared->HasVerificationFailedYet()) { break; @@ -108,8 +108,8 @@ class NonBatchedOpsStressTest : public StressTest { from_db.data(), from_db.length()); } } - } else { - // 1/3 chance use MultiGet to verify this range + } else if (thread->rand.OneIn(2)) { + // 1/4 chance use MultiGet to verify this range for (auto i = start; i < end;) { if (thread->shared->HasVerificationFailedYet()) { break; @@ -140,6 +140,47 @@ class NonBatchedOpsStressTest : public StressTest { i += batch_size; } + } else { + // 1/4 chance use GetMergeOperand to verify this range + // Start off with small size that will be increased later if necessary + std::vector values(4); + GetMergeOperandsOptions merge_operands_info; + merge_operands_info.expected_max_number_of_operands = + static_cast(values.size()); + for (auto i = start; i < end; i++) { + if (thread->shared->HasVerificationFailedYet()) { + break; + } + std::string from_db; + std::string keystr = Key(i); + Slice k = keystr; + int number_of_operands = 0; + Status s = db_->GetMergeOperands(options, column_families_[cf], k, + values.data(), &merge_operands_info, + &number_of_operands); + if (s.IsIncomplete()) { + // Need to resize values as there are more than values.size() merge + // operands on this key. Should only happen a few times when we + // encounter a key that had more merge operands than any key seen so + // far + values.resize(number_of_operands); + merge_operands_info.expected_max_number_of_operands = + static_cast(number_of_operands); + s = db_->GetMergeOperands(options, column_families_[cf], k, + values.data(), &merge_operands_info, + &number_of_operands); + } + // Assumed here that GetMergeOperands always sets number_of_operand + if (number_of_operands) { + from_db = values[number_of_operands - 1].ToString(); + } + VerifyValue(static_cast(cf), i, options, shared, from_db, s, + true); + if (from_db.length()) { + PrintKeyValue(static_cast(cf), static_cast(i), + from_db.data(), from_db.length()); + } + } } } }