summaryrefslogtreecommitdiff
path: root/src/mongo/s/catalog_cache.cpp
diff options
context:
space:
mode:
authorTommaso Tocci <tommaso.tocci@mongodb.com>2020-07-30 19:09:49 +0200
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-04 11:11:02 +0000
commit1f0fbdcc0da395e1afc0554e398c5a4c83c72539 (patch)
treed41f5867f17607074b5dd5e059ec4dc51e912f11 /src/mongo/s/catalog_cache.cpp
parent2fc36d0b12d1c44893a5f3c1fe0ac8fb0125a071 (diff)
downloadmongo-1f0fbdcc0da395e1afc0554e398c5a4c83c72539.tar.gz
SERVER-49976 Cleanup database cache on shard removal
Diffstat (limited to 'src/mongo/s/catalog_cache.cpp')
-rw-r--r--src/mongo/s/catalog_cache.cpp38
1 files changed, 8 insertions, 30 deletions
diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp
index acad122d913..7e2cfb9501b 100644
--- a/src/mongo/s/catalog_cache.cpp
+++ b/src/mongo/s/catalog_cache.cpp
@@ -162,23 +162,6 @@ StatusWith<CachedDatabaseInfo> CatalogCache::getDatabase(OperationContext* opCtx
return {ErrorCodes::NamespaceNotFound,
str::stream() << "database " << dbName << " not found"};
}
- const auto primaryShardExists =
- Grid::get(opCtx)->shardRegistry()->getShard(opCtx, dbEntry->getPrimary()).isOK();
-
- if (!primaryShardExists) {
- LOGV2_FOR_CATALOG_REFRESH(
- 4947103,
- 2,
- "Invalidating cached database entry because its primary shard hasn't been found",
- "db"_attr = dbName);
- _databaseCache.invalidate(dbName.toString());
- dbEntry = _databaseCache.acquire(opCtx, dbName.toString());
- if (!dbEntry) {
- return {ErrorCodes::NamespaceNotFound,
- str::stream() << "database " << dbName << " not found"};
- }
- }
-
const auto primaryShard = uassertStatusOKWithContext(
Grid::get(opCtx)->shardRegistry()->getShard(opCtx, dbEntry->getPrimary()),
str::stream() << "could not find the primary shard for database " << dbName);
@@ -436,24 +419,19 @@ void CatalogCache::invalidateShardForShardedCollection(const NamespaceString& ns
}
void CatalogCache::invalidateEntriesThatReferenceShard(const ShardId& shardId) {
- stdx::lock_guard<Latch> lg(_mutex);
+ LOGV2_DEBUG(4997600,
+ 1,
+ "Invalidating databases and collections referencing a specific shard",
+ "shardId"_attr = shardId);
- LOGV2(22643,
- "Starting to invalidate collections with data on shard {shardId}",
- "Starting to invalidate collections referencing a specific shard",
- "shardId"_attr = shardId);
+ _databaseCache.invalidateCachedValueIf(
+ [&](const DatabaseType& dbt) { return dbt.getPrimary() == shardId; });
+
+ stdx::lock_guard<Latch> lg(_mutex);
// Invalidate collections which contain data on this shard.
for (const auto& [db, collInfoMap] : _collectionsByDb) {
for (const auto& [collNs, collRoutingInfoEntry] : collInfoMap) {
-
- LOGV2_DEBUG(22646,
- 3,
- "Checking if collection {namespace} has data on shard {shardId}",
- "Checking if collection has data on specific shard",
- "namespace"_attr = collNs,
- "shardId"_attr = shardId);
-
if (!collRoutingInfoEntry->needsRefresh && collRoutingInfoEntry->routingInfo) {
// The set of shards on which this collection contains chunks.
std::set<ShardId> shardsOwningDataForCollection;