From 4e8321bfeae8541fb5d827dfcb089e39078841bc Mon Sep 17 00:00:00 2001 From: Mark Callaghan Date: Fri, 17 Jan 2014 16:38:54 -0800 Subject: [PATCH] Boost access before mutex is unlocked Summary: This moves the use of versions_ to before the mutex is unlocked to avoid a possible race. Task ID: # Blame Rev: Test Plan: make check Revert Plan: Database Impact: Memcache Impact: Other Notes: EImportant: - begin *PUBLIC* platform impact section - Bugzilla: # - end platform impact - Reviewers: haobo, dhruba Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D15279 --- db/db_impl.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index a16f4479e..43f21505b 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -3200,15 +3200,15 @@ Status DBImpl::MakeRoomForWrite(bool force, // individual write by 0-1ms to reduce latency variance. Also, // this delay hands over some CPU to the compaction thread in // case it is sharing the same core as the writer. + uint64_t slowdown = + SlowdownAmount(versions_->current()->NumLevelFiles(0), + options_.level0_slowdown_writes_trigger, + options_.level0_stop_writes_trigger); mutex_.Unlock(); uint64_t delayed; { StopWatch sw(env_, options_.statistics.get(), STALL_L0_SLOWDOWN_COUNT); - env_->SleepForMicroseconds( - SlowdownAmount(versions_->current()->NumLevelFiles(0), - options_.level0_slowdown_writes_trigger, - options_.level0_stop_writes_trigger) - ); + env_->SleepForMicroseconds(slowdown); delayed = sw.ElapsedMicros(); } RecordTick(options_.statistics.get(), STALL_L0_SLOWDOWN_MICROS, delayed);