From 135ee6a3fcdfab12ab357a29ab358d14974caf04 Mon Sep 17 00:00:00 2001 From: Aaron Gao Date: Thu, 25 May 2017 10:41:00 -0700 Subject: [PATCH] fix tsan crash data race Summary: rand_ has data race risk TEST_TMPDIR=\/dev\/shm\/rocksdb OPT=-g COMPILE_WITH_TSAN=1 CRASH_TEST_KILL_ODD=1887 make J=1 crash_test Closes https://github.com/facebook/rocksdb/pull/2368 Differential Revision: D5127424 Pulled By: lightmark fbshipit-source-id: b7f4d1430a5769b57da9f99037106749264b2ced --- tools/db_stress.cc | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/tools/db_stress.cc b/tools/db_stress.cc index 37a93043a..44ff1bbda 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -937,27 +937,23 @@ struct ThreadState { class DbStressListener : public EventListener { public: - DbStressListener( - const std::string& db_name, - const std::vector& db_paths) : - db_name_(db_name), - db_paths_(db_paths), - rand_(301) {} + DbStressListener(const std::string& db_name, + const std::vector& db_paths) + : db_name_(db_name), db_paths_(db_paths) {} virtual ~DbStressListener() {} #ifndef ROCKSDB_LITE - virtual void OnFlushCompleted( - DB* db, const FlushJobInfo& info) override { + virtual void OnFlushCompleted(DB* db, const FlushJobInfo& info) override { assert(db); assert(db->GetName() == db_name_); assert(IsValidColumnFamilyName(info.cf_name)); VerifyFilePath(info.file_path); // pretending doing some work here std::this_thread::sleep_for( - std::chrono::microseconds(rand_.Uniform(5000))); + std::chrono::microseconds(Random::GetTLSInstance()->Uniform(5000))); } - virtual void OnCompactionCompleted( - DB *db, const CompactionJobInfo& ci) override { + virtual void OnCompactionCompleted(DB* db, + const CompactionJobInfo& ci) override { assert(db); assert(db->GetName() == db_name_); assert(IsValidColumnFamilyName(ci.cf_name)); @@ -970,11 +966,10 @@ class DbStressListener : public EventListener { } // pretending doing some work here std::this_thread::sleep_for( - std::chrono::microseconds(rand_.Uniform(5000))); + std::chrono::microseconds(Random::GetTLSInstance()->Uniform(5000))); } - virtual void OnTableFileCreated( - const TableFileCreationInfo& info) override { + virtual void OnTableFileCreated(const TableFileCreationInfo& info) override { assert(info.db_name == db_name_); assert(IsValidColumnFamilyName(info.cf_name)); VerifyFilePath(info.file_path); @@ -1043,7 +1038,6 @@ class DbStressListener : public EventListener { private: std::string db_name_; std::vector db_paths_; - Random rand_; }; } // namespace