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
This commit is contained in:
Aaron Gao 2017-05-25 10:41:00 -07:00 committed by Facebook Github Bot
parent a99fb9928f
commit 135ee6a3fc
1 changed files with 9 additions and 15 deletions

View File

@ -937,27 +937,23 @@ struct ThreadState {
class DbStressListener : public EventListener {
public:
DbStressListener(
const std::string& db_name,
const std::vector<DbPath>& db_paths) :
db_name_(db_name),
db_paths_(db_paths),
rand_(301) {}
DbStressListener(const std::string& db_name,
const std::vector<DbPath>& 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<DbPath> db_paths_;
Random rand_;
};
} // namespace