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 08:40:43 +0000 |
commit | fed81c016c212a7a644266f478734a1f9450adb8 (patch) | |
tree | 80e22c18e0858b97c77cfb0cfd47ef89e9745af5 /src/mongo/db/s | |
parent | 70bbc40c52b10395d0c54d63e4f7c35abadd8756 (diff) | |
download | mongo-fed81c016c212a7a644266f478734a1f9450adb8.tar.gz |
SERVER-71689 Refresh the catalogCache after dropping a collection
(cherry picked from commit a92c4effc843cde56ddb0903c36ba10e2fbfb283)
Diffstat (limited to 'src/mongo/db/s')
3 files changed, 34 insertions, 42 deletions
diff --git a/src/mongo/db/s/drop_collection_coordinator.cpp b/src/mongo/db/s/drop_collection_coordinator.cpp index 76b86dfeec8..11c6fe8d601 100644 --- a/src/mongo/db/s/drop_collection_coordinator.cpp +++ b/src/mongo/db/s/drop_collection_coordinator.cpp @@ -44,6 +44,24 @@ #include "mongo/s/request_types/sharded_ddl_commands_gen.h" namespace mongo { +namespace { + +void dropCollectionHonouringFromMigrateFlag(OperationContext* opCtx, + const NamespaceString& nss, + bool fromMigrate) { + if (fromMigrate) { + mongo::sharding_ddl_util::ensureCollectionDroppedNoChangeEvent(opCtx, nss); + } else { + DropReply unused; + uassertStatusOK( + dropCollection(opCtx, + nss, + &unused, + DropCollectionSystemCollectionMode::kDisallowSystemCollectionDrops)); + } +} + +} // namespace DropCollectionCoordinator::DropCollectionCoordinator(ShardingDDLCoordinatorService* service, const BSONObj& initialState) @@ -87,17 +105,18 @@ void DropCollectionCoordinator::dropCollectionLocally(OperationContext* opCtx, csr->clearFilteringMetadataForDroppedCollection(opCtx); } - DropReply unused; - if (fromMigrate) - mongo::sharding_ddl_util::ensureCollectionDroppedNoChangeEvent(opCtx, nss); - else - uassertStatusOK( - dropCollection(opCtx, - nss, - &unused, - DropCollectionSystemCollectionMode::kDisallowSystemCollectionDrops)); + try { + dropCollectionHonouringFromMigrateFlag(opCtx, nss, fromMigrate); + } 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 a7f27d01bb9..fd456ccf9fd 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, false /* fromMigrate */); - return true; - } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) { - return false; - } - }(); - + DropCollectionCoordinator::dropCollectionLocally(opCtx, nss, false /* fromMigrate */); 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 950f2d296d7..dbfd5d1a3ef 100644 --- a/src/mongo/db/s/shardsvr_drop_collection_participant_command.cpp +++ b/src/mongo/db/s/shardsvr_drop_collection_participant_command.cpp @@ -75,17 +75,8 @@ public: opCtx->setAlwaysInterruptAtStepDownOrUp(); - try { - bool fromMigrate = - request().getFromMigrate() ? request().getFromMigrate().value() : false; - - DropCollectionCoordinator::dropCollectionLocally(opCtx, ns(), fromMigrate); - } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) { - LOGV2_DEBUG(5280920, - 1, - "Namespace not found while trying to delete local collection", - "namespace"_attr = ns()); - } + bool fromMigrate = request().getFromMigrate().value_or(false); + DropCollectionCoordinator::dropCollectionLocally(opCtx, ns(), fromMigrate); // 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. |