Fix DBWriteTest::ReturnSequenceNumberMultiThreaded data race

Summary:
rocksdb::Random is not thread-safe. Have one Random for each thread instead.
Closes https://github.com/facebook/rocksdb/pull/2400

Differential Revision: D5173919

Pulled By: yiwu-arbug

fbshipit-source-id: 1a99c7b877f3893eb22355af49e321bcad4e53e6
This commit is contained in:
Yi Wu 2017-06-02 11:41:29 -07:00 committed by Facebook Github Bot
parent 215076ef06
commit f68d88be51

View file

@ -39,7 +39,6 @@ TEST_P(DBWriteTest, ReturnSeuqneceNumber) {
TEST_P(DBWriteTest, ReturnSeuqneceNumberMultiThreaded) { TEST_P(DBWriteTest, ReturnSeuqneceNumberMultiThreaded) {
constexpr size_t kThreads = 16; constexpr size_t kThreads = 16;
constexpr size_t kNumKeys = 1000; constexpr size_t kNumKeys = 1000;
Random rnd(4422);
Open(); Open();
ASSERT_EQ(0, dbfull()->GetLatestSequenceNumber()); ASSERT_EQ(0, dbfull()->GetLatestSequenceNumber());
// Check each sequence is used once and only once. // Check each sequence is used once and only once.
@ -48,6 +47,7 @@ TEST_P(DBWriteTest, ReturnSeuqneceNumberMultiThreaded) {
flags[i].clear(); flags[i].clear();
} }
auto writer = [&](size_t id) { auto writer = [&](size_t id) {
Random rnd(4422 + id);
for (size_t k = 0; k < kNumKeys; k++) { for (size_t k = 0; k < kNumKeys; k++) {
WriteBatch batch; WriteBatch batch;
batch.Put("key" + ToString(id) + "-" + ToString(k), batch.Put("key" + ToString(id) + "-" + ToString(k),