From 04d3ac4e63cb3776193cb741b48deecadad37de7 Mon Sep 17 00:00:00 2001 From: Maysam Yabandeh Date: Fri, 8 Mar 2019 09:34:55 -0800 Subject: [PATCH] Fix tsan compliant on AddPreparedBeforeMax (#5052) Summary: Add a mutex to the test to synchronize before accessing the shared txn object. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5052 Differential Revision: D14386861 Pulled By: maysamyabandeh fbshipit-source-id: 5b32e209840b210c35af53848dc77f489a76c95a --- .../transactions/write_prepared_transaction_test.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utilities/transactions/write_prepared_transaction_test.cc b/utilities/transactions/write_prepared_transaction_test.cc index f84514ec1..1de25adda 100644 --- a/utilities/transactions/write_prepared_transaction_test.cc +++ b/utilities/transactions/write_prepared_transaction_test.cc @@ -2960,6 +2960,7 @@ TEST_P(WritePreparedTransactionTest, AddPreparedBeforeMax) { Transaction* txn = db->BeginTransaction(WriteOptions(), TransactionOptions()); ASSERT_OK(txn->SetName("xid")); ASSERT_OK(txn->Put(Slice("key0"), uncommitted_value)); + port::Mutex txn_mutex_; // t1) Insert prepared entry, t2) commit other entires to advance max // evicted sec and finish checking the existing prepared entires, t1) @@ -2971,7 +2972,11 @@ TEST_P(WritePreparedTransactionTest, AddPreparedBeforeMax) { }); SyncPoint::GetInstance()->EnableProcessing(); - rocksdb::port::Thread write_thread([&]() { ASSERT_OK(txn->Prepare()); }); + rocksdb::port::Thread write_thread([&]() { + txn_mutex_.Lock(); + ASSERT_OK(txn->Prepare()); + txn_mutex_.Unlock(); + }); rocksdb::port::Thread read_thread([&]() { TEST_SYNC_POINT("AddPreparedBeforeMax::read_thread:start"); @@ -2987,7 +2992,9 @@ TEST_P(WritePreparedTransactionTest, AddPreparedBeforeMax) { auto snap = db->GetSnapshot(); ASSERT_LT(wp_db->max_evicted_seq_, snap->GetSequenceNumber()); // This is the scenario that we test for + txn_mutex_.Lock(); ASSERT_GT(wp_db->max_evicted_seq_, txn->GetId()); + txn_mutex_.Unlock(); roptions.snapshot = snap; auto s = db->Get(roptions, db->DefaultColumnFamily(), "key0", &value); ASSERT_TRUE(s.IsNotFound());