summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/shardsvr_rename_collection_participant_command.cpp
diff options
context:
space:
mode:
authorJordi Serra Torrens <jordi.serra-torrens@mongodb.com>2021-10-18 14:07:28 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-18 14:50:56 +0000
commitc83185229c960f321d2eb121ff6a4e8a043dd124 (patch)
tree8eddcb4d8e542eccd64d2556dbcd532ad9144385 /src/mongo/db/s/shardsvr_rename_collection_participant_command.cpp
parent8e530000b5d48f4d105039f822168d2e949ca956 (diff)
downloadmongo-c83185229c960f321d2eb121ff6a4e8a043dd124.tar.gz
SERVER-60592 DDL participant commands need to ensure they make a write with their txnNumber
Diffstat (limited to 'src/mongo/db/s/shardsvr_rename_collection_participant_command.cpp')
-rw-r--r--src/mongo/db/s/shardsvr_rename_collection_participant_command.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/mongo/db/s/shardsvr_rename_collection_participant_command.cpp b/src/mongo/db/s/shardsvr_rename_collection_participant_command.cpp
index b31c7802e4c..61c9718b4e1 100644
--- a/src/mongo/db/s/shardsvr_rename_collection_participant_command.cpp
+++ b/src/mongo/db/s/shardsvr_rename_collection_participant_command.cpp
@@ -33,9 +33,11 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
+#include "mongo/db/dbdirectclient.h"
#include "mongo/db/s/rename_collection_participant_service.h"
#include "mongo/db/s/sharded_rename_collection_gen.h"
#include "mongo/db/s/sharding_state.h"
+#include "mongo/db/transaction_participant.h"
#include "mongo/db/write_concern.h"
#include "mongo/logv2/log.h"
@@ -97,6 +99,24 @@ public:
<< participantDocBSON << "`");
renameCollectionParticipant->getBlockCRUDAndRenameCompletionFuture().get(opCtx);
+
+ // 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.
+ // TODO SERVER-60773: Once 6.0 has branched out, txnParticipant must always exist. Add a
+ // uassert for that.
+ auto txnParticipant = TransactionParticipant::get(opCtx);
+ if (txnParticipant) {
+ // Since no write that generated a retryable write oplog entry with this sessionId
+ // and txnNumber happened, we need to make a dummy write so that the session gets
+ // durably persisted on the oplog. This must be the last operation done on this
+ // command.
+ DBDirectClient client(opCtx);
+ client.update(NamespaceString::kServerConfigurationNamespace.ns(),
+ BSON("_id" << Request::kCommandName),
+ BSON("$inc" << BSON("count" << 1)),
+ true /* upsert */,
+ false /* multi */);
+ }
}
private:
@@ -169,6 +189,24 @@ public:
optRenameCollectionParticipant.get()->sourceUUID() == req.getSourceUUID());
optRenameCollectionParticipant.get()->getUnblockCrudFuture().get(opCtx);
}
+
+ // 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.
+ // TODO SERVER-60773: Once 6.0 has branched out, txnParticipant must always exist. Add a
+ // uassert for that.
+ auto txnParticipant = TransactionParticipant::get(opCtx);
+ if (txnParticipant) {
+ // Since no write that generated a retryable write oplog entry with this sessionId
+ // and txnNumber happened, we need to make a dummy write so that the session gets
+ // durably persisted on the oplog. This must be the last operation done on this
+ // command.
+ DBDirectClient client(opCtx);
+ client.update(NamespaceString::kServerConfigurationNamespace.ns(),
+ BSON("_id" << Request::kCommandName),
+ BSON("$inc" << BSON("count" << 1)),
+ true /* upsert */,
+ false /* multi */);
+ }
}
private: