From 42189612c3b6ce6557337b8e1b78dbfb47485764 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Fri, 23 Jan 2015 18:04:39 -0800 Subject: [PATCH] Fix data race #2 Summary: We should not be calling InternalStats methods outside of the mutex. Test Plan: COMPILE_WITH_TSAN=1 m db_test && ROCKSDB_TESTS=CompactionTrigger ./db_test failing before the diff, works now Reviewers: yhchiang, rven, sdong Reviewed By: sdong Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D32127 --- db/db_impl.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 34c3077fd..350dcde16 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -2908,11 +2908,15 @@ Status DBImpl::Write(const WriteOptions& write_options, WriteBatch* my_batch) { if (!write_options.disableWAL) { RecordTick(stats_, WRITE_WITH_WAL); - default_cf_internal_stats_->AddDBStats(InternalStats::WRITE_WITH_WAL, 1); } WriteContext context; mutex_.Lock(); + + if (!write_options.disableWAL) { + default_cf_internal_stats_->AddDBStats(InternalStats::WRITE_WITH_WAL, 1); + } + Status status = write_thread_.EnterWriteThread(&w, expiration_time); assert(status.ok() || status.IsTimedOut()); if (status.IsTimedOut()) {