diff options
-rw-r--r-- | src/mongo/s/catalog_cache.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp index c74d3b2ac28..9ab97b18bbe 100644 --- a/src/mongo/s/catalog_cache.cpp +++ b/src/mongo/s/catalog_cache.cpp @@ -155,19 +155,25 @@ StatusWith<ChunkManager> CatalogCache::_getCollectionRoutingInfoAt( auto collEntryFuture = _collectionCache.acquireAsync(nss, cacheConsistency); - // If the entry is in the cache return inmediately. - if (collEntryFuture.isReady()) { - setOperationShouldBlockBehindCatalogCacheRefresh(opCtx, false); - return ChunkManager(dbInfo.primaryId(), - dbInfo.databaseVersion(), - collEntryFuture.get(opCtx), - atClusterTime); - } - if (allowLocks) { - return Status{ErrorCodes::StaleShardVersion, "Routing info refresh did not complete"}; + // When allowLocks is true we may be holding a lock, so we don't + // want to block the current thread: if the future is ready let's + // use it, otherwise return an error + + if (collEntryFuture.isReady()) { + setOperationShouldBlockBehindCatalogCacheRefresh(opCtx, false); + return ChunkManager(dbInfo.primaryId(), + dbInfo.databaseVersion(), + collEntryFuture.get(opCtx), + atClusterTime); + } else { + return Status{ErrorCodes::StaleShardVersion, + "Routing info refresh did not complete"}; + } } + // From this point we can guarantee that allowLocks is false + operationBlockedBehindCatalogCacheRefresh(opCtx) = true; size_t acquireTries = 0; |