@ -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 + + ) ) ;
}
}
} ;
} ;