From a263002a361fccd3a53f0a7df38b0065af405c56 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Mon, 28 Sep 2015 12:06:43 -0700 Subject: [PATCH] Fixed a tsan warning in db_stress.cc Summary: Fixed the following tsan warning in db_stress.cc WARNING: ThreadSanitizer: data race (pid=3163194) Read of size 8 at 0x7fd1797cb518 by thread T32: #0 VerifyDb tools/db_stress.cc:1731 (db_stress+0x000000040674) #1 rocksdb::StressTest::ThreadBody(void*) tools/db_stress.cc:1191 (db_stress+0x0000000625a9) #2 StartThreadWrapper util/env_posix.cc:1648 (db_stress+0x00000028bbbd) Previous write of size 8 at 0x7fd1797cb518 by thread T31: #0 VerifyDb tools/db_stress.cc:1726 (db_stress+0x00000004072a) #1 rocksdb::StressTest::ThreadBody(void*) tools/db_stress.cc:1191 (db_stress+0x0000000625a9) #2 StartThreadWrapper util/env_posix.cc:1648 (db_stress+0x00000028bbbd) The cause is that in VerifyDb(), the static local const variable long max_key can be read and written at the same time. This patch fixed it by making it non-static. Test Plan: db_stress Reviewers: igor, sdong, IslamAbdelRahman, anthony Reviewed By: anthony Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D47703 --- tools/db_stress.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/db_stress.cc b/tools/db_stress.cc index 5b2e4584e..634045dfb 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -1723,10 +1723,10 @@ class StressTest { void VerifyDb(ThreadState* thread) const { ReadOptions options(FLAGS_verify_checksum, true); auto shared = thread->shared; - static const long max_key = shared->GetMaxKey(); - static const long keys_per_thread = max_key / shared->GetNumThreads(); - long start = keys_per_thread * thread->tid; - long end = start + keys_per_thread; + const int64_t max_key = shared->GetMaxKey(); + const int64_t keys_per_thread = max_key / shared->GetNumThreads(); + int64_t start = keys_per_thread * thread->tid; + int64_t end = start + keys_per_thread; if (thread->tid == shared->GetNumThreads() - 1) { end = max_key; }