summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/rename_collection_participant_service.cpp
diff options
context:
space:
mode:
authorPaolo Polato <paolo.polato@mongodb.com>2023-03-13 15:04:27 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-03-13 17:53:34 +0000
commit02790b2165b60769dbeb39be413b3a9f030425bf (patch)
tree6d531a4be629a96b80c324c12f66c747d9c7f0c1 /src/mongo/db/s/rename_collection_participant_service.cpp
parent7be6f10766d6e04674ad59b396a14f183bee2c78 (diff)
downloadmongo-02790b2165b60769dbeb39be413b3a9f030425bf.tar.gz
SERVER-71365 Emit a single visible op entry version when the sharded renameCollection is committed
Diffstat (limited to 'src/mongo/db/s/rename_collection_participant_service.cpp')
-rw-r--r--src/mongo/db/s/rename_collection_participant_service.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/mongo/db/s/rename_collection_participant_service.cpp b/src/mongo/db/s/rename_collection_participant_service.cpp
index 6553656e5b3..7dbb4553a6d 100644
--- a/src/mongo/db/s/rename_collection_participant_service.cpp
+++ b/src/mongo/db/s/rename_collection_participant_service.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/s/range_deletion_util.h"
#include "mongo/db/s/sharding_ddl_util.h"
#include "mongo/db/s/sharding_recovery_service.h"
+#include "mongo/db/s/sharding_state.h"
#include "mongo/logv2/log.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
#include "mongo/s/grid.h"
@@ -55,8 +56,10 @@ 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) {
- DropCollectionCoordinator::dropCollectionLocally(opCtx, nss, false /* fromMigrate */);
+void dropCollectionLocally(OperationContext* opCtx,
+ const NamespaceString& nss,
+ bool markFromMigrate) {
+ DropCollectionCoordinator::dropCollectionLocally(opCtx, nss, markFromMigrate);
LOGV2_DEBUG(5515100,
1,
"Dropped target collection locally on renameCollection participant.",
@@ -109,7 +112,7 @@ void renameOrDropTarget(OperationContext* opCtx,
1,
"Source namespace not found while trying to rename collection on participant",
"namespace"_attr = fromNss);
- dropCollectionLocally(opCtx, toNss);
+ dropCollectionLocally(opCtx, toNss, options.markFromMigrate);
deleteRangeDeletionTasksForRename(opCtx, fromNss, toNss);
}
}
@@ -330,9 +333,22 @@ SemiFuture<void> RenameParticipantInstance::_runImpl(
auto* opCtx = opCtxHolder.get();
_doc.getForwardableOpMetadata().setOn(opCtx);
+ // TODO SERVER-74719 replace with a query to config.system.sharding_ddl_coordinators
+ const auto primaryShardId =
+ Grid::get(opCtx)
+ ->catalogClient()
+ ->getDatabase(opCtx,
+ fromNss().dbName().db(),
+ repl::ReadConcernLevel::kMajorityReadConcern)
+ .getPrimary();
+ const auto thisShardId = ShardingState::get(opCtx)->shardId();
+
RenameCollectionOptions options;
options.dropTarget = _doc.getDropTarget();
options.stayTemp = _doc.getStayTemp();
+ // Use the "markFromMigrate" option so that change streams capturing events about
+ // fromNss/toNss won't receive duplicate drop notifications.
+ options.markFromMigrate = (thisShardId != primaryShardId);
renameOrDropTarget(
opCtx, fromNss(), toNss(), options, _doc.getSourceUUID(), _doc.getTargetUUID());