summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/rename_collection_participant_service.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/s/rename_collection_participant_service.cpp')
-rw-r--r--src/mongo/db/s/rename_collection_participant_service.cpp58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/mongo/db/s/rename_collection_participant_service.cpp b/src/mongo/db/s/rename_collection_participant_service.cpp
index e99c16dff44..92341d1035f 100644
--- a/src/mongo/db/s/rename_collection_participant_service.cpp
+++ b/src/mongo/db/s/rename_collection_participant_service.cpp
@@ -34,6 +34,7 @@
#include "mongo/base/checked_cast.h"
#include "mongo/db/catalog/collection_catalog.h"
#include "mongo/db/catalog/rename_collection.h"
+#include "mongo/db/catalog_raii.h"
#include "mongo/db/persistent_task_store.h"
#include "mongo/db/s/collection_sharding_runtime.h"
#include "mongo/db/s/database_sharding_state.h"
@@ -43,6 +44,7 @@
#include "mongo/db/s/recoverable_critical_section_service.h"
#include "mongo/db/s/rename_collection_participant_service.h"
#include "mongo/db/s/shard_metadata_util.h"
+#include "mongo/db/s/sharding_ddl_util.h"
#include "mongo/logv2/log.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
#include "mongo/s/grid.h"
@@ -58,29 +60,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, 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);
}
/*
@@ -133,6 +117,16 @@ void renameOrDropTarget(OperationContext* opCtx,
deleteRangeDeletionTasksForRename(opCtx, fromNss, toNss);
}
}
+
+void clearFilteringMetadataOnNss(OperationContext* opCtx, const NamespaceString& nss) {
+ // Set the placement version to UNKNOWN to force a future operation to refresh the metadata
+ // TODO (SERVER-71444): Fix to be interruptible or document exception.
+ UninterruptibleLockGuard noInterrupt(opCtx->lockState()); // NOLINT.
+ AutoGetCollection autoColl(opCtx, nss, MODE_IX);
+ auto* csr = CollectionShardingRuntime::get(opCtx, nss);
+ csr->clearFilteringMetadata(opCtx);
+}
+
} // namespace
RenameCollectionParticipantService* RenameCollectionParticipantService::getService(
@@ -307,9 +301,7 @@ SemiFuture<void> RenameParticipantInstance::_runImpl(
// Acquire source/target critical sections
const auto reason =
- BSON("command"
- << "rename"
- << "from" << fromNss().toString() << "to" << toNss().toString());
+ sharding_ddl_util::getCriticalSectionReasonForRename(fromNss(), toNss());
auto service = RecoverableCriticalSectionService::get(opCtx);
service->acquireRecoverableCriticalSectionBlockWrites(
opCtx, fromNss(), reason, ShardingCatalogClient::kLocalWriteConcern);
@@ -324,8 +316,19 @@ SemiFuture<void> RenameParticipantInstance::_runImpl(
// recovered the next time is accessed) and to safely create new range deletion
// tasks (the submission will serialize on the renamed collection's metadata
// refresh).
- clearFilteringMetadata(opCtx, fromNss());
- clearFilteringMetadata(opCtx, toNss());
+ {
+ Lock::DBLock dbLock(opCtx, fromNss().db(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, fromNss(), MODE_IX);
+ auto* csr = CollectionShardingRuntime::get(opCtx, fromNss());
+ csr->clearFilteringMetadataForDroppedCollection(opCtx);
+ }
+
+ {
+ Lock::DBLock dbLock(opCtx, toNss().db(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, toNss(), MODE_IX);
+ auto* csr = CollectionShardingRuntime::get(opCtx, toNss());
+ csr->clearFilteringMetadata(opCtx);
+ }
snapshotRangeDeletionsForRename(opCtx, fromNss(), toNss());
}))
@@ -377,6 +380,9 @@ SemiFuture<void> RenameParticipantInstance::_runImpl(
auto opCtxHolder = cc().makeOperationContext();
auto* opCtx = opCtxHolder.get();
+ clearFilteringMetadataOnNss(opCtx, fromNss());
+ clearFilteringMetadataOnNss(opCtx, toNss());
+
// Release source/target critical sections
const auto reason =
BSON("command"