From b6a04c494f73ca267547dcd79541c0977651037f Mon Sep 17 00:00:00 2001 From: Sergi Mateo Bellido Date: Thu, 15 Oct 2020 17:04:19 +0000 Subject: SERVER-51614 The catalog cache should always refresh the routine information few times if it is inconsistent --- src/mongo/s/catalog_cache.cpp | 26 ++++++++++++++++---------- 1 file 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 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; -- cgit v1.2.1