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.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/mongo/db/s/rename_collection_participant_service.cpp b/src/mongo/db/s/rename_collection_participant_service.cpp
index 4d9efb66056..51256975393 100644
--- a/src/mongo/db/s/rename_collection_participant_service.cpp
+++ b/src/mongo/db/s/rename_collection_participant_service.cpp
@@ -201,12 +201,23 @@ void RenameParticipantInstance::_enterPhase(Phase newPhase) {
PersistentTaskStore<StateDoc> store(NamespaceString::kShardingRenameParticipantsNamespace);
if (_doc.getPhase() == Phase::kUnset) {
- store.add(opCtx.get(), newDoc, WriteConcerns::kMajorityWriteConcernShardingTimeout);
+ try {
+ store.add(opCtx.get(), newDoc, WriteConcerns::kMajorityWriteConcernNoTimeout);
+ } catch (const ExceptionFor<ErrorCodes::DuplicateKey>&) {
+ // A series of step-up and step-down events can cause a node to try and insert the
+ // document when it has already been persisted locally, but we must still wait for
+ // majority commit.
+ const auto replCoord = repl::ReplicationCoordinator::get(opCtx.get());
+ const auto lastLocalOpTime = replCoord->getMyLastAppliedOpTime();
+ WaitForMajorityService::get(opCtx->getServiceContext())
+ .waitUntilMajority(lastLocalOpTime, opCtx.get()->getCancellationToken())
+ .get(opCtx.get());
+ }
} else {
store.update(opCtx.get(),
BSON(StateDoc::kFromNssFieldName << fromNss().ns()),
newDoc.toBSON(),
- WriteConcerns::kMajorityWriteConcernShardingTimeout);
+ WriteConcerns::kMajorityWriteConcernNoTimeout);
}
_doc = std::move(newDoc);
@@ -222,7 +233,7 @@ void RenameParticipantInstance::_removeStateDocument(OperationContext* opCtx) {
PersistentTaskStore<StateDoc> store(NamespaceString::kShardingRenameParticipantsNamespace);
store.remove(opCtx,
BSON(StateDoc::kFromNssFieldName << fromNss().ns()),
- WriteConcerns::kMajorityWriteConcernShardingTimeout);
+ WriteConcerns::kMajorityWriteConcernNoTimeout);
_doc = {};
}
@@ -387,7 +398,7 @@ SemiFuture<void> RenameParticipantInstance::_runImpl(
service->releaseRecoverableCriticalSection(
opCtx, fromNss(), reason, ShardingCatalogClient::kLocalWriteConcern);
service->releaseRecoverableCriticalSection(
- opCtx, toNss(), reason, ShardingCatalogClient::kMajorityWriteConcern);
+ opCtx, toNss(), reason, WriteConcerns::kMajorityWriteConcernNoTimeout);
LOGV2(5515107, "CRUD unblocked", "fromNs"_attr = fromNss(), "toNs"_attr = toNss());
}))