summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorAntonio Fuschetto <antonio.fuschetto@mongodb.com>2021-08-26 13:44:39 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-08-26 14:09:30 +0000
commit789c686a8c6d5d05f501406d54c611bca1266e6e (patch)
treef3d7cbbee20a4be03d07dff286649188c68f0639 /src/mongo/db/s
parentd4fda802de82a9420d5c45d0560ba17a1c6f5d62 (diff)
downloadmongo-789c686a8c6d5d05f501406d54c611bca1266e6e.tar.gz
SERVER-58362 Refactor SSCCL's functions purging cached collection metadata
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/shard_server_catalog_cache_loader.cpp61
1 files changed, 21 insertions, 40 deletions
diff --git a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
index 16dc1fd545a..07f713c866c 100644
--- a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
+++ b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
@@ -69,40 +69,6 @@ MONGO_FAIL_POINT_DEFINE(hangCollectionFlush);
AtomicWord<unsigned long long> taskIdGenerator{0};
-void dropChunksIfEpochChanged(OperationContext* opCtx,
- const NamespaceString& nss,
- const CollectionAndChangedChunks& collAndChunks,
- const ChunkVersion& maxLoaderVersion) {
- if (collAndChunks.epoch != maxLoaderVersion.epoch() &&
- maxLoaderVersion != ChunkVersion::UNSHARDED()) {
- // If the collection has a new epoch, delete all existing chunks in the persisted routing
- // table cache.
-
- // TODO (SERVER-58361): Reduce the access to local collections.
- const auto statusWithCollectionEntry = readShardCollectionsEntry(opCtx, nss);
- if (statusWithCollectionEntry.getStatus() == ErrorCodes::NamespaceNotFound) {
- return;
- }
- uassertStatusOKWithContext(
- statusWithCollectionEntry,
- str::stream() << "Failed to read persisted collection entry for '" << nss.ns() << "'.");
- const auto& collectionEntry = statusWithCollectionEntry.getValue();
-
- dropChunks(opCtx, nss, collectionEntry.getUuid(), collectionEntry.getSupportingLongName());
-
- if (MONGO_unlikely(hangPersistCollectionAndChangedChunksAfterDropChunks.shouldFail())) {
- LOGV2(22093, "Hit hangPersistCollectionAndChangedChunksAfterDropChunks failpoint");
- hangPersistCollectionAndChangedChunksAfterDropChunks.pauseWhileSet(opCtx);
- }
-
- LOGV2(3463203,
- "Dropped chunks cache due to epoch change",
- "collectionNamespace"_attr = nss,
- "collectionEpoch"_attr = collAndChunks.epoch,
- "maxLoaderVersionEpoch"_attr = maxLoaderVersion.epoch());
- }
-}
-
/**
* Takes a CollectionAndChangedChunks object and persists the changes to the shard's metadata
* collections.
@@ -113,14 +79,29 @@ Status persistCollectionAndChangedChunks(OperationContext* opCtx,
const NamespaceString& nss,
const CollectionAndChangedChunks& collAndChunks,
const ChunkVersion& maxLoaderVersion) {
- // If the collection has a new epoch, delete all existing chunks in the persisted cache.
- try {
- dropChunksIfEpochChanged(opCtx, nss, collAndChunks, maxLoaderVersion);
- } catch (const DBException& ex) {
- return ex.toStatus();
+ // If the collection's epoch has changed, delete the collections entry and drop all chunks from
+ // the persisted cache.
+ if (maxLoaderVersion != ChunkVersion::UNSHARDED() &&
+ maxLoaderVersion.epoch() != collAndChunks.epoch) {
+ auto status = dropChunksAndDeleteCollectionsEntry(opCtx, nss);
+
+ if (MONGO_unlikely(hangPersistCollectionAndChangedChunksAfterDropChunks.shouldFail())) {
+ LOGV2(22093, "Hit hangPersistCollectionAndChangedChunksAfterDropChunks failpoint");
+ hangPersistCollectionAndChangedChunksAfterDropChunks.pauseWhileSet(opCtx);
+ }
+
+ if (!status.isOK()) {
+ return status;
+ }
+
+ LOGV2(5836200,
+ "Dropped collection and chunks cache due to epoch change",
+ "namespace"_attr = nss,
+ "currentEpoch"_attr = collAndChunks.epoch,
+ "previousEpoch"_attr = maxLoaderVersion.epoch());
}
- // Update the collections collection entry for 'nss' in case there are any new updates.
+ // Set the collection entry.
ShardCollectionType update(nss,
collAndChunks.epoch,
collAndChunks.creationTime,