diff options
author | Antonio Fuschetto <antonio.fuschetto@mongodb.com> | 2021-06-28 10:00:04 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-30 20:45:29 +0000 |
commit | 11804e1aa48e88ebd65a11eb81f069ebae23ef7b (patch) | |
tree | ae23267384991fa5578727c01ea3569ab1ee8a9c /src/mongo/db | |
parent | 8659dd3dc2b906d10d9cd5fdb213f7169ec71678 (diff) | |
download | mongo-11804e1aa48e88ebd65a11eb81f069ebae23ef7b.tar.gz |
SERVER-58115 Outdated information can remain in the catalog cache after a collection is renamed
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/s/rename_collection_participant_service.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/mongo/db/s/rename_collection_participant_service.cpp b/src/mongo/db/s/rename_collection_participant_service.cpp index 5ffd0090a48..9e89cf7a98a 100644 --- a/src/mongo/db/s/rename_collection_participant_service.cpp +++ b/src/mongo/db/s/rename_collection_participant_service.cpp @@ -94,15 +94,6 @@ void renameOrDropTarget(OperationContext* opCtx, } } - { - // Clear CollectionShardingRuntime entry for the toNss collection. - UninterruptibleLockGuard noInterrupt(opCtx->lockState()); - Lock::DBLock dbLock(opCtx, toNss.db(), MODE_IX); - Lock::CollectionLock collLock(opCtx, toNss, MODE_IX); - auto* csr = CollectionShardingRuntime::get(opCtx, toNss); - csr->clearFilteringMetadata(opCtx); - } - try { validateAndRunRenameCollection(opCtx, fromNss, toNss, options); } catch (ExceptionFor<ErrorCodes::NamespaceNotFound>&) { @@ -296,6 +287,27 @@ SemiFuture<void> RenameParticipantInstance::run( auto opCtxHolder = cc().makeOperationContext(); auto* opCtx = opCtxHolder.get(); + // Clear the CollectionShardingRuntime entry + auto clearFilteringMetadata = [&](const NamespaceString& nss) { + UninterruptibleLockGuard noInterrupt(opCtx->lockState()); + Lock::DBLock dbLock(opCtx, nss.db(), MODE_IX); + Lock::CollectionLock collLock(opCtx, nss, MODE_IX); + auto* csr = CollectionShardingRuntime::get(opCtx, nss); + csr->clearFilteringMetadata(opCtx); + }; + clearFilteringMetadata(fromNss()); + clearFilteringMetadata(toNss()); + + // Force the refresh of the catalog cache for both source and destination + // collections to purge outdated information + const auto catalog = Grid::get(opCtx)->catalogCache(); + uassertStatusOK(catalog->getCollectionRoutingInfoWithRefresh(opCtx, fromNss())); + uassertStatusOK(catalog->getCollectionRoutingInfoWithRefresh(opCtx, toNss())); + CatalogCacheLoader::get(opCtx).waitForCollectionFlush(opCtx, fromNss()); + CatalogCacheLoader::get(opCtx).waitForCollectionFlush(opCtx, toNss()); + repl::ReplClientInfo::forClient(opCtx->getClient()) + .setLastOpToSystemLastOpTime(opCtx); + // Release source/target critical sections const auto reason = BSON("command" @@ -307,9 +319,6 @@ SemiFuture<void> RenameParticipantInstance::run( service->releaseRecoverableCriticalSection( opCtx, toNss(), reason, ShardingCatalogClient::kMajorityWriteConcern); - Grid::get(opCtx)->catalogCache()->invalidateCollectionEntry_LINEARIZABLE(fromNss()); - Grid::get(opCtx)->catalogCache()->invalidateCollectionEntry_LINEARIZABLE(toNss()); - LOGV2(5515107, "CRUD unblocked", "fromNs"_attr = fromNss(), "toNs"_attr = toNss()); })) .onCompletion([this, anchor = shared_from_this()](const Status& status) { |