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
main
Aaron Gao 8 years ago committed by Facebook Github Bot
parent a99fb9928f
commit 135ee6a3fc
  1. 24
      tools/db_stress.cc

@ -937,27 +937,23 @@ struct ThreadState {
class DbStressListener : public EventListener { class DbStressListener : public EventListener {
public: public:
DbStressListener( DbStressListener(const std::string& db_name,
const std::string& db_name, const std::vector<DbPath>& db_paths)
const std::vector<DbPath>& db_paths) : : db_name_(db_name), db_paths_(db_paths) {}
db_name_(db_name),
db_paths_(db_paths),
rand_(301) {}
virtual ~DbStressListener() {} virtual ~DbStressListener() {}
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
virtual void OnFlushCompleted( virtual void OnFlushCompleted(DB* db, const FlushJobInfo& info) override {
DB* db, const FlushJobInfo& info) override {
assert(db); assert(db);
assert(db->GetName() == db_name_); assert(db->GetName() == db_name_);
assert(IsValidColumnFamilyName(info.cf_name)); assert(IsValidColumnFamilyName(info.cf_name));
VerifyFilePath(info.file_path); VerifyFilePath(info.file_path);
// pretending doing some work here // pretending doing some work here
std::this_thread::sleep_for( std::this_thread::sleep_for(
std::chrono::microseconds(rand_.Uniform(5000))); std::chrono::microseconds(Random::GetTLSInstance()->Uniform(5000)));
} }
virtual void OnCompactionCompleted( virtual void OnCompactionCompleted(DB* db,
DB *db, const CompactionJobInfo& ci) override { const CompactionJobInfo& ci) override {
assert(db); assert(db);
assert(db->GetName() == db_name_); assert(db->GetName() == db_name_);
assert(IsValidColumnFamilyName(ci.cf_name)); assert(IsValidColumnFamilyName(ci.cf_name));
@ -970,11 +966,10 @@ class DbStressListener : public EventListener {
} }
// pretending doing some work here // pretending doing some work here
std::this_thread::sleep_for( std::this_thread::sleep_for(
std::chrono::microseconds(rand_.Uniform(5000))); std::chrono::microseconds(Random::GetTLSInstance()->Uniform(5000)));
} }
virtual void OnTableFileCreated( virtual void OnTableFileCreated(const TableFileCreationInfo& info) override {
const TableFileCreationInfo& info) override {
assert(info.db_name == db_name_); assert(info.db_name == db_name_);
assert(IsValidColumnFamilyName(info.cf_name)); assert(IsValidColumnFamilyName(info.cf_name));
VerifyFilePath(info.file_path); VerifyFilePath(info.file_path);
@ -1043,7 +1038,6 @@ class DbStressListener : public EventListener {
private: private:
std::string db_name_; std::string db_name_;
std::vector<DbPath> db_paths_; std::vector<DbPath> db_paths_;
Random rand_;
}; };
} // namespace } // namespace

Loading…
Cancel
Save