diff options
author | Sergi Mateo Bellido <sergi.mateo-bellido@mongodb.com> | 2022-12-09 13:02:51 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-12-21 11:14:51 +0000 |
commit | 94da32aecc61c625937350c41fa878cd9f87b950 (patch) | |
tree | 50def5d666ea72f6dd8c2a20ff7304d7583da99c | |
parent | 300f442d681cfebe47addc1756d8220c9864673e (diff) | |
download | mongo-94da32aecc61c625937350c41fa878cd9f87b950.tar.gz |
SERVER-71689 Refresh the catalogCache after dropping a collection
(cherry picked from commit a92c4effc843cde56ddb0903c36ba10e2fbfb283)
3 files changed, 19 insertions, 32 deletions
diff --git a/src/mongo/db/s/drop_collection_coordinator.cpp b/src/mongo/db/s/drop_collection_coordinator.cpp index ca3079e4073..09491c0d5f5 100644 --- a/src/mongo/db/s/drop_collection_coordinator.cpp +++ b/src/mongo/db/s/drop_collection_coordinator.cpp @@ -85,10 +85,22 @@ DropReply DropCollectionCoordinator::dropCollectionLocally(OperationContext* opC } DropReply result; - uassertStatusOK(dropCollection( - opCtx, nss, &result, DropCollectionSystemCollectionMode::kDisallowSystemCollectionDrops)); + try { + uassertStatusOK( + dropCollection(opCtx, + nss, + &result, + DropCollectionSystemCollectionMode::kDisallowSystemCollectionDrops)); + } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) { + // Note that even if the namespace was not found we have to execute the code below! + LOGV2_DEBUG(5280920, + 1, + "Namespace not found while trying to delete local collection", + "namespace"_attr = nss); + } - // Force the refresh of the catalog cache to purge outdated information + // Force the refresh of the catalog cache to purge outdated information. Note also that this + // code is indirectly used to notify to secondary nodes to clear their filtering information. const auto catalog = Grid::get(opCtx)->catalogCache(); uassertStatusOK(catalog->getCollectionRoutingInfoWithRefresh(opCtx, nss)); CatalogCacheLoader::get(opCtx).waitForCollectionFlush(opCtx, nss); diff --git a/src/mongo/db/s/rename_collection_participant_service.cpp b/src/mongo/db/s/rename_collection_participant_service.cpp index 4c2fca846bb..30d5ccec8dc 100644 --- a/src/mongo/db/s/rename_collection_participant_service.cpp +++ b/src/mongo/db/s/rename_collection_participant_service.cpp @@ -59,29 +59,11 @@ const Backoff kExponentialBackoff(Seconds(1), Milliseconds::max()); * Drop the collection locally and clear stale metadata from cache collections. */ void dropCollectionLocally(OperationContext* opCtx, const NamespaceString& nss) { - bool knownNss = [&]() { - try { - DropCollectionCoordinator::dropCollectionLocally(opCtx, nss); - return true; - } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) { - return false; - } - }(); - + DropCollectionCoordinator::dropCollectionLocally(opCtx, nss); LOGV2_DEBUG(5515100, 1, - "Dropped target collection locally on renameCollection participant", - "namespace"_attr = nss, - "collectionExisted"_attr = knownNss); -} - -/* Clear the CollectionShardingRuntime entry for the specified namespace */ -void clearFilteringMetadata(OperationContext* opCtx, 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); + "Dropped target collection locally on renameCollection participant.", + "namespace"_attr = nss); } /* diff --git a/src/mongo/db/s/shardsvr_drop_collection_participant_command.cpp b/src/mongo/db/s/shardsvr_drop_collection_participant_command.cpp index 6af52ad1b78..fb64448964e 100644 --- a/src/mongo/db/s/shardsvr_drop_collection_participant_command.cpp +++ b/src/mongo/db/s/shardsvr_drop_collection_participant_command.cpp @@ -77,14 +77,7 @@ public: opCtx->setAlwaysInterruptAtStepDownOrUp(); - try { - DropCollectionCoordinator::dropCollectionLocally(opCtx, ns()); - } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) { - LOGV2_DEBUG(5280920, - 1, - "Namespace not found while trying to delete local collection", - "namespace"_attr = ns()); - } + DropCollectionCoordinator::dropCollectionLocally(opCtx, ns()); // The txnParticipant will only be missing when the command was sent from a coordinator // running an old 5.0.0 binary that didn't attach a sessionId & txnNumber. |