From b2584577fa66ccb16c3b67a0347188d2474660ce Mon Sep 17 00:00:00 2001 From: Maysam Yabandeh Date: Mon, 10 Jun 2019 16:46:04 -0700 Subject: [PATCH] Remove global locks from FlushScheduler (#5372) Summary: FlushScheduler's methods are instrumented with debug-time locks to check the scheduler state against a simple container definition. Since https://github.com/facebook/rocksdb/pull/2286 the scope of such locks are widened to the entire methods' body. The result is that the concurrency tested during testing (in debug mode) is stricter than the concurrency level manifested at runtime (in release mode). The patch reverts this change to reduce the scope of such locks. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5372 Differential Revision: D15545831 Pulled By: maysamyabandeh fbshipit-source-id: 01d69191afb1dd807d4bdc990fc74813ae7b5426 --- db/flush_scheduler.cc | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/db/flush_scheduler.cc b/db/flush_scheduler.cc index 8735a6b369..9c6c04efe3 100644 --- a/db/flush_scheduler.cc +++ b/db/flush_scheduler.cc @@ -13,9 +13,11 @@ namespace rocksdb { void FlushScheduler::ScheduleFlush(ColumnFamilyData* cfd) { #ifndef NDEBUG - std::lock_guard lock(checking_mutex_); - assert(checking_set_.count(cfd) == 0); - checking_set_.insert(cfd); + { + std::lock_guard lock(checking_mutex_); + assert(checking_set_.count(cfd) == 0); + checking_set_.insert(cfd); + } #endif // NDEBUG cfd->Ref(); // Suppress false positive clang analyzer warnings. @@ -32,9 +34,6 @@ void FlushScheduler::ScheduleFlush(ColumnFamilyData* cfd) { } ColumnFamilyData* FlushScheduler::TakeNextColumnFamily() { -#ifndef NDEBUG - std::lock_guard lock(checking_mutex_); -#endif // NDEBUG while (true) { if (head_.load(std::memory_order_relaxed) == nullptr) { return nullptr; @@ -47,9 +46,12 @@ ColumnFamilyData* FlushScheduler::TakeNextColumnFamily() { delete node; #ifndef NDEBUG - auto iter = checking_set_.find(cfd); - assert(iter != checking_set_.end()); - checking_set_.erase(iter); + { + std::lock_guard lock(checking_mutex_); + auto iter = checking_set_.find(cfd); + assert(iter != checking_set_.end()); + checking_set_.erase(iter); + } #endif // NDEBUG if (!cfd->IsDropped()) { @@ -65,12 +67,12 @@ ColumnFamilyData* FlushScheduler::TakeNextColumnFamily() { } bool FlushScheduler::Empty() { -#ifndef NDEBUG - std::lock_guard lock(checking_mutex_); -#endif // NDEBUG auto rv = head_.load(std::memory_order_relaxed) == nullptr; #ifndef NDEBUG - assert(rv == checking_set_.empty()); + std::lock_guard lock(checking_mutex_); + // Empty is allowed to be called concurrnetly with ScheduleFlush. It would + // only miss the recent schedules. + assert((rv == checking_set_.empty()) || rv); #endif // NDEBUG return rv; }