diff options
Diffstat (limited to 'src/mongo/db')
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. |