Change random seed for txn stress tests on each run (#5004)

Summary:
Currently the transaction stress tests use thread id as the seed. Since the thread ids are likely to be the same across multiple runs, the seed is thus going to be the same. The patch includes time in calculating the seed to help covering a very different part of state space in each run of the stress tests. To be able to reproduce the bug in case the stress tests failed, it also prints out the time that was used to calculate the seed value.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5004

Differential Revision: D14144356

Pulled By: maysamyabandeh

fbshipit-source-id: 728ed522f550fc8b4f5f9f373259c05fe9a54556
main
Maysam Yabandeh 6 years ago committed by Facebook Github Bot
parent 0f4244fe00
commit cf98df34c1
  1. 36
      utilities/transactions/transaction_test.cc

@ -4996,23 +4996,19 @@ TEST_P(TransactionStressTest, ExpiredTransactionDataRace1) {
namespace { namespace {
// cmt_delay_ms is the delay between prepare and commit // cmt_delay_ms is the delay between prepare and commit
// first_id is the id of the first transaction // first_id is the id of the first transaction
Status TransactionStressTestInserter(TransactionDB* db, Status TransactionStressTestInserter(
const size_t num_transactions, TransactionDB* db, const size_t num_transactions, const size_t num_sets,
const size_t num_sets, const size_t num_keys_per_set, Random64* rand,
const size_t num_keys_per_set, const uint64_t cmt_delay_ms = 0, const uint64_t first_id = 0) {
const uint64_t cmt_delay_ms = 0,
const uint64_t first_id = 0) {
size_t seed = std::hash<std::thread::id>()(std::this_thread::get_id());
Random64 _rand(seed);
WriteOptions write_options; WriteOptions write_options;
ReadOptions read_options; ReadOptions read_options;
TransactionOptions txn_options; TransactionOptions txn_options;
// Inside the inserter we might also retake the snapshot. We do both since two // Inside the inserter we might also retake the snapshot. We do both since two
// separte functions are engaged for each. // separte functions are engaged for each.
txn_options.set_snapshot = _rand.OneIn(2); txn_options.set_snapshot = rand->OneIn(2);
RandomTransactionInserter inserter( RandomTransactionInserter inserter(
&_rand, write_options, read_options, num_keys_per_set, rand, write_options, read_options, num_keys_per_set,
static_cast<uint16_t>(num_sets), cmt_delay_ms, first_id); static_cast<uint16_t>(num_sets), cmt_delay_ms, first_id);
for (size_t t = 0; t < num_transactions; t++) { for (size_t t = 0; t < num_transactions; t++) {
@ -5055,15 +5051,19 @@ TEST_P(MySQLStyleTransactionTest, TransactionStressTest) {
std::vector<port::Thread> threads; std::vector<port::Thread> threads;
std::atomic<uint32_t> finished = {0}; std::atomic<uint32_t> finished = {0};
bool TAKE_SNAPSHOT = true; bool TAKE_SNAPSHOT = true;
uint64_t time_seed = env->NowMicros();
printf("time_seed is %" PRIu64 "\n", time_seed); // would help to reproduce
std::function<void()> call_inserter = [&] { std::function<void()> call_inserter = [&] {
size_t thd_seed = std::hash<std::thread::id>()(std::this_thread::get_id());
Random64 rand(time_seed * thd_seed);
ASSERT_OK(TransactionStressTestInserter(db, num_transactions_per_thread, ASSERT_OK(TransactionStressTestInserter(db, num_transactions_per_thread,
num_sets, num_keys_per_set)); num_sets, num_keys_per_set, &rand));
finished++; finished++;
}; };
std::function<void()> call_checker = [&] { std::function<void()> call_checker = [&] {
size_t seed = std::hash<std::thread::id>()(std::this_thread::get_id()); size_t thd_seed = std::hash<std::thread::id>()(std::this_thread::get_id());
Random64 rand(seed); Random64 rand(time_seed * thd_seed);
// Verify that data is consistent // Verify that data is consistent
while (finished < num_workers) { while (finished < num_workers) {
Status s = RandomTransactionInserter::Verify( Status s = RandomTransactionInserter::Verify(
@ -5072,8 +5072,8 @@ TEST_P(MySQLStyleTransactionTest, TransactionStressTest) {
} }
}; };
std::function<void()> call_slow_checker = [&] { std::function<void()> call_slow_checker = [&] {
size_t seed = std::hash<std::thread::id>()(std::this_thread::get_id()); size_t thd_seed = std::hash<std::thread::id>()(std::this_thread::get_id());
Random64 rand(seed); Random64 rand(time_seed * thd_seed);
// Verify that data is consistent // Verify that data is consistent
while (finished < num_workers) { while (finished < num_workers) {
uint64_t delay_ms = rand.Uniform(100) + 1; uint64_t delay_ms = rand.Uniform(100) + 1;
@ -5083,14 +5083,14 @@ TEST_P(MySQLStyleTransactionTest, TransactionStressTest) {
} }
}; };
std::function<void()> call_slow_inserter = [&] { std::function<void()> call_slow_inserter = [&] {
size_t seed = std::hash<std::thread::id>()(std::this_thread::get_id()); size_t thd_seed = std::hash<std::thread::id>()(std::this_thread::get_id());
Random64 rand(seed); Random64 rand(time_seed * thd_seed);
uint64_t id = 0; uint64_t id = 0;
// Verify that data is consistent // Verify that data is consistent
while (finished < num_workers) { while (finished < num_workers) {
uint64_t delay_ms = rand.Uniform(500) + 1; uint64_t delay_ms = rand.Uniform(500) + 1;
ASSERT_OK(TransactionStressTestInserter(db, 1, num_sets, num_keys_per_set, ASSERT_OK(TransactionStressTestInserter(db, 1, num_sets, num_keys_per_set,
delay_ms, id++)); &rand, delay_ms, id++));
} }
}; };

Loading…
Cancel
Save