summaryrefslogtreecommitdiff
path: root/src/mongo/db/op_observer_impl.cpp
diff options
context:
space:
mode:
authorCheahuychou Mao <mao.cheahuychou@gmail.com>2021-08-24 22:01:27 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-08 18:06:16 +0000
commit6a96149eb7a142892fb775ce5970a9890493f0b3 (patch)
tree643e21cf90f53c2f84a02699933f2395ab38f395 /src/mongo/db/op_observer_impl.cpp
parentb0a5eeea2155c0b049cbd1ab6c4633cf0dffdc79 (diff)
downloadmongo-6a96149eb7a142892fb775ce5970a9890493f0b3.tar.gz
SERVER-58752 Persist txnRetryCounter and reload it on stepup
Diffstat (limited to 'src/mongo/db/op_observer_impl.cpp')
-rw-r--r--src/mongo/db/op_observer_impl.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp
index f2cfd63e83d..761ccca0f94 100644
--- a/src/mongo/db/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer_impl.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/index/index_descriptor.h"
+#include "mongo/db/internal_transactions_feature_flag_gen.h"
#include "mongo/db/keys_collection_document_gen.h"
#include "mongo/db/logical_time_validator.h"
#include "mongo/db/namespace_string.h"
@@ -127,9 +128,17 @@ void onWriteOpCompleted(OperationContext* opCtx,
// be uninitialized.
return;
+ const bool inMultiDocumentTransaction = txnParticipant.transactionIsOpen();
+
// We add these here since they may not exist if we return early.
sessionTxnRecord.setSessionId(*opCtx->getLogicalSessionId());
sessionTxnRecord.setTxnNum(*opCtx->getTxnNumber());
+ if (feature_flags::gFeatureFlagInternalTransactions.isEnabled(
+ serverGlobalParams.featureCompatibility) &&
+ inMultiDocumentTransaction) {
+ invariant(opCtx->getTxnRetryCounter());
+ sessionTxnRecord.setTxnRetryCounter(*opCtx->getTxnRetryCounter());
+ }
txnParticipant.onWriteOpCompletedOnPrimary(opCtx, std::move(stmtIdsWritten), sessionTxnRecord);
}
@@ -1188,6 +1197,11 @@ OpTimeBundle logApplyOpsForTransaction(OperationContext* opCtx,
oplogEntry->setNss({"admin", "$cmd"});
oplogEntry->setSessionId(opCtx->getLogicalSessionId());
oplogEntry->setTxnNumber(opCtx->getTxnNumber());
+ if (feature_flags::gFeatureFlagInternalTransactions.isEnabled(
+ serverGlobalParams.featureCompatibility)) {
+ invariant(opCtx->getTxnRetryCounter());
+ oplogEntry->getOperationSessionInfo().setTxnRetryCounter(*opCtx->getTxnRetryCounter());
+ }
try {
OpTimeBundle times;
@@ -1369,6 +1383,11 @@ void logCommitOrAbortForPreparedTransaction(OperationContext* opCtx,
oplogEntry->setNss({"admin", "$cmd"});
oplogEntry->setSessionId(opCtx->getLogicalSessionId());
oplogEntry->setTxnNumber(opCtx->getTxnNumber());
+ if (feature_flags::gFeatureFlagInternalTransactions.isEnabled(
+ serverGlobalParams.featureCompatibility)) {
+ invariant(opCtx->getTxnRetryCounter());
+ oplogEntry->getOperationSessionInfo().setTxnRetryCounter(*opCtx->getTxnRetryCounter());
+ }
oplogEntry->setPrevWriteOpTimeInTransaction(
TransactionParticipant::get(opCtx).getLastWriteOpTime());