diff options
author | Amirsaman Memaripour <amirsaman.memaripour@mongodb.com> | 2020-05-07 19:23:18 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-12 20:38:48 +0000 |
commit | 79e004404e09c74d402d0b6d4604a48f1e2ca88d (patch) | |
tree | bc530e37b898cf10cd02b24cbc1d12887938b760 /src/mongo/db/keys_collection_manager.cpp | |
parent | 02ceb3f342d4295aef49b3b1d5479930496186f0 (diff) | |
download | mongo-79e004404e09c74d402d0b6d4604a48f1e2ca88d.tar.gz |
SERVER-48013 Use atomics to reduce contention in hasSeenKeys()
This commit simplifies the concurrency control in KeysCollectionManager and removes the
unnecessary invocation of shouldGossipLogicalTime() in appendRequiredFieldsToResponse().
Diffstat (limited to 'src/mongo/db/keys_collection_manager.cpp')
-rw-r--r-- | src/mongo/db/keys_collection_manager.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/mongo/db/keys_collection_manager.cpp b/src/mongo/db/keys_collection_manager.cpp index 87f02b68e64..8b40033705f 100644 --- a/src/mongo/db/keys_collection_manager.cpp +++ b/src/mongo/db/keys_collection_manager.cpp @@ -223,6 +223,8 @@ void KeysCollectionManager::PeriodicRunner::_doPeriodicRefresh(ServiceContext* s Milliseconds refreshInterval) { ThreadClient tc(threadName, service); + ON_BLOCK_EXIT([this]() mutable { _hasSeenKeys.store(false); }); + while (true) { unsigned errorCount = 0; @@ -251,10 +253,7 @@ void KeysCollectionManager::PeriodicRunner::_doPeriodicRefresh(ServiceContext* s const auto& latestKey = latestKeyStatusWith.getValue(); auto currentTime = LogicalClock::get(service)->getClusterTime(); - { - stdx::unique_lock<Latch> lock(_mutex); - _hasSeenKeys = true; - } + _hasSeenKeys.store(true); nextWakeup = howMuchSleepNeedFor(currentTime, latestKey.getExpiresAt(), refreshInterval); @@ -345,16 +344,14 @@ void KeysCollectionManager::PeriodicRunner::stop() { } _inShutdown = true; - _hasSeenKeys = false; _refreshNeededCV.notify_all(); } _backgroundThread.join(); } -bool KeysCollectionManager::PeriodicRunner::hasSeenKeys() { - stdx::lock_guard<Latch> lock(_mutex); - return _hasSeenKeys; +bool KeysCollectionManager::PeriodicRunner::hasSeenKeys() const noexcept { + return _hasSeenKeys.load(); } } // namespace mongo |