diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-04-20 15:30:50 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2018-04-20 15:30:50 -0400 |
commit | 7b1ac75a303433b18377493a8378fecad8446d59 (patch) | |
tree | 659f374f73d7cfae4e282466ae68733c75546fea | |
parent | 9b3ef563a5567c1d1106eb20deca7dc27dae5859 (diff) | |
download | mongo-7b1ac75a303433b18377493a8378fecad8446d59.tar.gz |
SERVER-34586 Avoid possible double mutex acquisition in ShardServerCatalogCacheLoader
-rw-r--r-- | src/mongo/db/s/shard_server_catalog_cache_loader.cpp | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp index 72a6694c64e..7943d6b8265 100644 --- a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp +++ b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp @@ -899,24 +899,23 @@ Status ShardServerCatalogCacheLoader::_ensureMajorityPrimaryAndScheduleCollAndCh } stdx::lock_guard<stdx::mutex> lock(_mutex); - const bool wasEmpty = _collAndChunkTaskLists[nss].empty(); _collAndChunkTaskLists[nss].addTask(std::move(task)); + if (!wasEmpty) { + return Status::OK(); + } - if (wasEmpty) { - Status status = _threadPool.schedule([this, nss]() { _runCollAndChunksTasks(nss); }); - if (!status.isOK()) { - log() << "Cache loader failed to schedule persisted metadata update" - << " task for namespace '" << nss << "' due to '" << redact(status) - << "'. Clearing task list so that scheduling" - << " will be attempted by the next caller to refresh this namespace."; - stdx::lock_guard<stdx::mutex> lock(_mutex); - _collAndChunkTaskLists.erase(nss); - } - return status; + Status status = _threadPool.schedule([this, nss]() { _runCollAndChunksTasks(nss); }); + if (!status.isOK()) { + log() << "Cache loader failed to schedule persisted metadata update" + << " task for namespace '" << nss << "' due to '" << redact(status) + << "'. Clearing task list so that scheduling" + << " will be attempted by the next caller to refresh this namespace."; + + _collAndChunkTaskLists.erase(nss); } - return Status::OK(); + return status; } Status ShardServerCatalogCacheLoader::_ensureMajorityPrimaryAndScheduleDbTask( @@ -929,25 +928,24 @@ Status ShardServerCatalogCacheLoader::_ensureMajorityPrimaryAndScheduleDbTask( } stdx::lock_guard<stdx::mutex> lock(_mutex); - const bool wasEmpty = _dbTaskLists[dbName.toString()].empty(); _dbTaskLists[dbName.toString()].addTask(std::move(task)); + if (!wasEmpty) { + return Status::OK(); + } - if (wasEmpty) { - Status status = _threadPool.schedule( - [ this, name = dbName.toString() ]() { _runDbTasks(StringData(name)); }); - if (!status.isOK()) { - log() << "Cache loader failed to schedule persisted metadata update" - << " task for db '" << dbName.toString() << "' due to '" << redact(status) - << "'. Clearing task list so that scheduling" - << " will be attempted by the next caller to refresh this namespace."; - stdx::lock_guard<stdx::mutex> lock(_mutex); - _dbTaskLists.erase(dbName.toString()); - } - return status; + Status status = + _threadPool.schedule([ this, name = dbName.toString() ]() { _runDbTasks(name); }); + if (!status.isOK()) { + log() << "Cache loader failed to schedule persisted metadata update" + << " task for db '" << dbName << "' due to '" << redact(status) + << "'. Clearing task list so that scheduling" + << " will be attempted by the next caller to refresh this namespace."; + + _dbTaskLists.erase(dbName.toString()); } - return Status::OK(); + return status; } void ShardServerCatalogCacheLoader::_runCollAndChunksTasks(const NamespaceString& nss) { |