From 377b8fe43916ff2c4e2ed35cb80548aeb8ba8c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Jos=C3=A9=20Grillo=20Ram=C3=ADrez?= Date: Sat, 5 Sep 2020 15:01:13 -0400 Subject: SERVER-46199 Make the collection CatalogCache support causal consistency This change implements the collection CatalogCache on top of the ReadThroughCache, giving it the ability to support causal consistency. As part of this change, the 'forceRefreshFromThisThread' flag has been removed from the shard's refresh methods. Co-authored-by: Tommaso Tocci Co-authored-by: Pierlauro Sciarelli Co-authored-by: Kaloian Manassiev --- src/mongo/s/commands/cluster_drop_cmd.cpp | 4 +++- src/mongo/s/commands/cluster_merge_chunks_cmd.cpp | 6 ++++-- src/mongo/s/commands/cluster_move_chunk_cmd.cpp | 11 ++++++++--- src/mongo/s/commands/cluster_shard_collection_cmd.cpp | 4 +++- src/mongo/s/commands/cluster_split_cmd.cpp | 6 ++++-- src/mongo/s/commands/flush_router_config_cmd.cpp | 2 +- src/mongo/s/commands/strategy.cpp | 16 ++++------------ 7 files changed, 27 insertions(+), 22 deletions(-) (limited to 'src/mongo/s/commands') diff --git a/src/mongo/s/commands/cluster_drop_cmd.cpp b/src/mongo/s/commands/cluster_drop_cmd.cpp index a69e3292597..f727489ccc0 100644 --- a/src/mongo/s/commands/cluster_drop_cmd.cpp +++ b/src/mongo/s/commands/cluster_drop_cmd.cpp @@ -88,7 +88,9 @@ public: // Invalidate the routing table cache entry for this collection so that we reload it the // next time it is accessed, even if sending the command to the config server fails due // to e.g. a NetworkError. - ON_BLOCK_EXIT([opCtx, nss] { Grid::get(opCtx)->catalogCache()->onEpochChange(nss); }); + ON_BLOCK_EXIT([opCtx, nss] { + Grid::get(opCtx)->catalogCache()->invalidateCollectionEntry_LINEARIZABLE(nss); + }); auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard(); auto cmdResponse = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts( diff --git a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp index b4157bee9d9..531aa1ab41e 100644 --- a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp +++ b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp @@ -174,8 +174,10 @@ public: Shard::RetryPolicy::kNotIdempotent)); uassertStatusOK(response.commandStatus); - Grid::get(opCtx)->catalogCache()->invalidateShardForShardedCollection( - nss, firstChunk.getShardId()); + Grid::get(opCtx) + ->catalogCache() + ->invalidateShardOrEntireCollectionEntryForShardedCollection( + nss, boost::none, firstChunk.getShardId()); CommandHelpers::filterCommandReplyForPassthrough(response.response, &result); return true; diff --git a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp index 01cdb91234e..f6e2d27c80f 100644 --- a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp +++ b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp @@ -198,9 +198,14 @@ public: cmdObj["waitForDelete"].trueValue(), forceJumbo)); - Grid::get(opCtx)->catalogCache()->invalidateShardForShardedCollection(nss, - chunk->getShardId()); - Grid::get(opCtx)->catalogCache()->invalidateShardForShardedCollection(nss, to->getId()); + Grid::get(opCtx) + ->catalogCache() + ->invalidateShardOrEntireCollectionEntryForShardedCollection( + nss, boost::none, chunk->getShardId()); + Grid::get(opCtx) + ->catalogCache() + ->invalidateShardOrEntireCollectionEntryForShardedCollection( + nss, boost::none, to->getId()); result.append("millis", t.millis()); return true; diff --git a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp index d27fd037d30..d4c4d7901ad 100644 --- a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp +++ b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp @@ -105,7 +105,9 @@ public: // Invalidate the routing table cache entry for this collection so that we reload the // collection the next time it's accessed, even if we receive a failure, e.g. NetworkError. - ON_BLOCK_EXIT([opCtx, nss] { Grid::get(opCtx)->catalogCache()->onEpochChange(nss); }); + ON_BLOCK_EXIT([opCtx, nss] { + Grid::get(opCtx)->catalogCache()->invalidateCollectionEntry_LINEARIZABLE(nss); + }); auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard(); auto cmdResponse = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts( diff --git a/src/mongo/s/commands/cluster_split_cmd.cpp b/src/mongo/s/commands/cluster_split_cmd.cpp index 19d33b3f10b..5532fac1daf 100644 --- a/src/mongo/s/commands/cluster_split_cmd.cpp +++ b/src/mongo/s/commands/cluster_split_cmd.cpp @@ -270,8 +270,10 @@ public: ChunkRange(chunk->getMin(), chunk->getMax()), {splitPoint})); - Grid::get(opCtx)->catalogCache()->invalidateShardForShardedCollection(nss, - chunk->getShardId()); + Grid::get(opCtx) + ->catalogCache() + ->invalidateShardOrEntireCollectionEntryForShardedCollection( + nss, boost::none, chunk->getShardId()); return true; } diff --git a/src/mongo/s/commands/flush_router_config_cmd.cpp b/src/mongo/s/commands/flush_router_config_cmd.cpp index bcc61a82a0a..d27b65a2c4d 100644 --- a/src/mongo/s/commands/flush_router_config_cmd.cpp +++ b/src/mongo/s/commands/flush_router_config_cmd.cpp @@ -102,7 +102,7 @@ public: "Routing metadata flushed for collection {namespace}", "Routing metadata flushed for collection", "namespace"_attr = nss); - catalogCache->purgeCollection(nss); + catalogCache->invalidateCollectionEntry_LINEARIZABLE(nss); } } diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index 644c10e6bcb..f83b490d0ef 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -722,16 +722,12 @@ void runCommand(OperationContext* opCtx, auto catalogCache = Grid::get(opCtx)->catalogCache(); if (auto staleInfo = ex.extraInfo()) { catalogCache->invalidateShardOrEntireCollectionEntryForShardedCollection( - opCtx, - staleNs, - staleInfo->getVersionWanted(), - staleInfo->getVersionReceived(), - staleInfo->getShardId()); + staleNs, staleInfo->getVersionWanted(), staleInfo->getShardId()); } else { // If we don't have the stale config info and therefore don't know the shard's // id, we have to force all further targetting requests for the namespace to // block on a refresh. - catalogCache->onEpochChange(staleNs); + catalogCache->invalidateCollectionEntry_LINEARIZABLE(staleNs); } @@ -1301,16 +1297,12 @@ void Strategy::explainFind(OperationContext* opCtx, Grid::get(opCtx) ->catalogCache() ->invalidateShardOrEntireCollectionEntryForShardedCollection( - opCtx, - staleNs, - staleInfo->getVersionWanted(), - staleInfo->getVersionReceived(), - staleInfo->getShardId()); + staleNs, staleInfo->getVersionWanted(), staleInfo->getShardId()); } else { // If we don't have the stale config info and therefore don't know the shard's id, // we have to force all further targetting requests for the namespace to block on // a refresh. - Grid::get(opCtx)->catalogCache()->onEpochChange(staleNs); + Grid::get(opCtx)->catalogCache()->invalidateCollectionEntry_LINEARIZABLE(staleNs); } if (canRetry) { -- cgit v1.2.1