summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergi Mateo Bellido <sergi.mateo-bellido@mongodb.com>2020-10-15 17:04:19 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-10-16 14:14:31 +0000
commitb6a04c494f73ca267547dcd79541c0977651037f (patch)
treee719d183850a6c03d3acc2aaef1479077e76c7a3
parent19bef363124a342208b7ba6cdb558285427e78e0 (diff)
downloadmongo-b6a04c494f73ca267547dcd79541c0977651037f.tar.gz
SERVER-51614 The catalog cache should always refresh the routine information few times if it is inconsistent
-rw-r--r--src/mongo/s/catalog_cache.cpp26
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;