summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorCheahuychou Mao <mao.cheahuychou@gmail.com>2021-08-19 05:37:25 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-01 22:02:16 +0000
commit22beeff23a26e44127a15587e8bfd84f1d1e916c (patch)
treebc88a80b18693021bdb60db0399d9ec20630e97c /src/mongo/db/s
parent9486a2779da1e8821b4b6d90ef3327a649c10b62 (diff)
downloadmongo-22beeff23a26e44127a15587e8bfd84f1d1e916c.tar.gz
SERVER-58752 Support retrying internal transactions on transient transaction errors
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp6
-rw-r--r--src/mongo/db/s/resharding/resharding_data_copy_util.cpp6
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_application.cpp6
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_batch_applier_test.cpp14
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_session_application_test.cpp26
-rw-r--r--src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp26
-rw-r--r--src/mongo/db/s/resharding_destined_recipient_test.cpp6
-rw-r--r--src/mongo/db/s/session_catalog_migration_destination.cpp6
-rw-r--r--src/mongo/db/s/session_catalog_migration_destination_test.cpp19
-rw-r--r--src/mongo/db/s/txn_two_phase_commit_cmds.cpp6
10 files changed, 93 insertions, 28 deletions
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index 1451fd2eced..5f81beb94fa 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -108,7 +108,8 @@ void checkOutSessionAndVerifyTxnState(OperationContext* opCtx) {
TransactionParticipant::get(opCtx).beginOrContinue(opCtx,
*opCtx->getTxnNumber(),
boost::none /* autocommit */,
- boost::none /* startTransaction */);
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
}
template <typename Callable>
@@ -921,7 +922,8 @@ void MigrationDestinationManager::_migrateThread() {
txnParticipant.beginOrContinue(opCtx,
*opCtx->getTxnNumber(),
boost::none /* autocommit */,
- boost::none /* startTransaction */);
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
_migrateDriver(opCtx);
} catch (...) {
_setStateFail(str::stream() << "migrate failed: " << redact(exceptionToStatus()));
diff --git a/src/mongo/db/s/resharding/resharding_data_copy_util.cpp b/src/mongo/db/s/resharding/resharding_data_copy_util.cpp
index 3461c15b815..745e83a40f9 100644
--- a/src/mongo/db/s/resharding/resharding_data_copy_util.cpp
+++ b/src/mongo/db/s/resharding/resharding_data_copy_util.cpp
@@ -249,7 +249,11 @@ boost::optional<SharedSemiFuture<void>> withSessionCheckedOut(OperationContext*
auto txnParticipant = TransactionParticipant::get(opCtx);
try {
- txnParticipant.beginOrContinue(opCtx, txnNumber, boost::none, boost::none);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNumber,
+ boost::none /* autocommit */,
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
if (stmtId && txnParticipant.checkStatementExecuted(opCtx, *stmtId)) {
// Skip the incoming statement because it has already been logged locally.
diff --git a/src/mongo/db/s/resharding/resharding_oplog_application.cpp b/src/mongo/db/s/resharding/resharding_oplog_application.cpp
index 104e79cdd37..5a71b14a7da 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_application.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_application.cpp
@@ -86,7 +86,11 @@ void runWithTransaction(OperationContext* opCtx, unique_function<void(OperationC
}
});
- txnParticipant.beginOrContinue(asr.opCtx(), txnNumber, false, true);
+ txnParticipant.beginOrContinue(asr.opCtx(),
+ txnNumber,
+ false /* autocommit */,
+ true /* startTransaction */,
+ boost::none /* txnRetryCounter */);
txnParticipant.unstashTransactionResources(asr.opCtx(), "reshardingOplogApplication");
func(asr.opCtx());
diff --git a/src/mongo/db/s/resharding/resharding_oplog_batch_applier_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_batch_applier_test.cpp
index 9691a947954..f89da1f5b2d 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_batch_applier_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_batch_applier_test.cpp
@@ -177,8 +177,11 @@ public:
MongoDOperationContextSession ocs(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
- txnParticipant.beginOrContinue(
- opCtx, txnNumber, false /* autocommit */, true /* startTransaction */);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNumber,
+ false /* autocommit */,
+ true /* startTransaction */,
+ boost::none /* txnRetryCounter */);
txnParticipant.unstashTransactionResources(opCtx, "prepareTransaction");
@@ -198,8 +201,11 @@ public:
MongoDOperationContextSession ocs(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
- txnParticipant.beginOrContinue(
- opCtx, txnNumber, false /* autocommit */, boost::none /* startTransaction */);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNumber,
+ false /* autocommit */,
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
txnParticipant.unstashTransactionResources(opCtx, "abortTransaction");
txnParticipant.abortTransaction(opCtx);
diff --git a/src/mongo/db/s/resharding/resharding_oplog_session_application_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_session_application_test.cpp
index 61a519c7493..29c6fd3c26b 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_session_application_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_session_application_test.cpp
@@ -79,7 +79,11 @@ public:
MongoDOperationContextSession ocs(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
- txnParticipant.beginOrContinue(opCtx, txnNumber, boost::none, boost::none);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNumber,
+ boost::none /* autocommit */,
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
WriteUnitOfWork wuow(opCtx);
auto opTime = repl::getNextOpTime(opCtx);
@@ -102,8 +106,11 @@ public:
MongoDOperationContextSession ocs(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
- txnParticipant.beginOrContinue(
- opCtx, txnNumber, false /* autocommit */, true /* startTransaction */);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNumber,
+ false /* autocommit */,
+ true /* startTransaction */,
+ boost::none /* txnRetryCounter */);
txnParticipant.unstashTransactionResources(opCtx, "prepareTransaction");
@@ -123,8 +130,11 @@ public:
MongoDOperationContextSession ocs(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
- txnParticipant.beginOrContinue(
- opCtx, txnNumber, false /* autocommit */, boost::none /* startTransaction */);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNumber,
+ false /* autocommit */,
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
txnParticipant.unstashTransactionResources(opCtx, "abortTransaction");
txnParticipant.abortTransaction(opCtx);
@@ -255,7 +265,11 @@ public:
MongoDOperationContextSession ocs(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
- txnParticipant.beginOrContinue(opCtx, txnNumber, boost::none, boost::none);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNumber,
+ boost::none /* autocommit */,
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
ASSERT_TRUE(bool(txnParticipant.checkStatementExecuted(opCtx, stmtId)));
}
};
diff --git a/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp b/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp
index e302f943693..ba1efd5a017 100644
--- a/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp
@@ -243,9 +243,17 @@ protected:
auto txnParticipant = TransactionParticipant::get(opCtx);
ASSERT(txnParticipant);
if (multiDocTxn) {
- txnParticipant.beginOrContinue(opCtx, txnNum, false, true);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNum,
+ false /* autocommit */,
+ true /* startTransaction */,
+ boost::none /* txnRetryCounter */);
} else {
- txnParticipant.beginOrContinue(opCtx, txnNum, boost::none, boost::none);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNum,
+ boost::none /* autocommit */,
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
}
}
@@ -389,8 +397,11 @@ protected:
MongoDOperationContextSession ocs(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
- txnParticipant.beginOrContinue(
- opCtx, txnNumber, false /* autocommit */, true /* startTransaction */);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNumber,
+ false /* autocommit */,
+ true /* startTransaction */,
+ boost::none /* txnRetryCounter */);
txnParticipant.unstashTransactionResources(opCtx, "prepareTransaction");
@@ -410,8 +421,11 @@ protected:
MongoDOperationContextSession ocs(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
- txnParticipant.beginOrContinue(
- opCtx, txnNumber, false /* autocommit */, boost::none /* startTransaction */);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNumber,
+ false /* autocommit */,
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
txnParticipant.unstashTransactionResources(opCtx, "abortTransaction");
txnParticipant.abortTransaction(opCtx);
diff --git a/src/mongo/db/s/resharding_destined_recipient_test.cpp b/src/mongo/db/s/resharding_destined_recipient_test.cpp
index 98d534ca694..6592bb4f35d 100644
--- a/src/mongo/db/s/resharding_destined_recipient_test.cpp
+++ b/src/mongo/db/s/resharding_destined_recipient_test.cpp
@@ -70,7 +70,11 @@ void runInTransaction(OperationContext* opCtx, Callable&& func) {
auto txnParticipant = TransactionParticipant::get(opCtx);
ASSERT(txnParticipant);
- txnParticipant.beginOrContinue(opCtx, txnNum, false, true);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNum,
+ false /* autocommit */,
+ true /* startTransaction */,
+ boost::none /* txnRetryCounter */);
txnParticipant.unstashTransactionResources(opCtx, "SetDestinedRecipient");
func();
diff --git a/src/mongo/db/s/session_catalog_migration_destination.cpp b/src/mongo/db/s/session_catalog_migration_destination.cpp
index 80226a9c463..8350f974581 100644
--- a/src/mongo/db/s/session_catalog_migration_destination.cpp
+++ b/src/mongo/db/s/session_catalog_migration_destination.cpp
@@ -247,7 +247,11 @@ ProcessOplogResult processSessionOplog(const BSONObj& oplogBSON,
auto txnParticipant = TransactionParticipant::get(opCtx);
try {
- txnParticipant.beginOrContinue(opCtx, result.txnNum, boost::none, boost::none);
+ txnParticipant.beginOrContinue(opCtx,
+ result.txnNum,
+ boost::none /* autocommit */,
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
if (txnParticipant.checkStatementExecuted(opCtx, stmtIds.front())) {
// Skip the incoming statement because it has already been logged locally
return lastResult;
diff --git a/src/mongo/db/s/session_catalog_migration_destination_test.cpp b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
index 7d770e47cff..446fedd435a 100644
--- a/src/mongo/db/s/session_catalog_migration_destination_test.cpp
+++ b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
@@ -183,7 +183,11 @@ public:
opCtx->setTxnNumber(txnNum);
MongoDOperationContextSession ocs(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
- txnParticipant.beginOrContinue(opCtx, txnNum, boost::none, boost::none);
+ txnParticipant.beginOrContinue(opCtx,
+ txnNum,
+ boost::none /* autocommit */,
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
}
void checkOplog(const repl::OplogEntry& originalOplog, const repl::OplogEntry& oplogToCheck) {
@@ -250,8 +254,11 @@ public:
initializeOperationSessionInfo(innerOpCtx.get(), insertBuilder.obj(), true, true, true);
MongoDOperationContextSession sessionTxnState(innerOpCtx.get());
auto txnParticipant = TransactionParticipant::get(innerOpCtx.get());
- txnParticipant.beginOrContinue(
- innerOpCtx.get(), *sessionInfo.getTxnNumber(), boost::none, boost::none);
+ txnParticipant.beginOrContinue(innerOpCtx.get(),
+ *sessionInfo.getTxnNumber(),
+ boost::none /* autocommit */,
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
const auto reply = write_ops_exec::performInserts(innerOpCtx.get(), insertRequest);
ASSERT(reply.results.size() == 1);
@@ -1879,7 +1886,11 @@ TEST_F(SessionCatalogMigrationDestinationTest,
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.refreshFromStorageIfNeeded(opCtx);
- txnParticipant.beginOrContinue(opCtx, 3, boost::none, boost::none);
+ txnParticipant.beginOrContinue(opCtx,
+ 3,
+ boost::none /* autocommit */,
+ boost::none /* startTransaction */,
+ boost::none /* txnRetryCounter */);
}
OperationSessionInfo sessionInfo2;
diff --git a/src/mongo/db/s/txn_two_phase_commit_cmds.cpp b/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
index b228c301d95..3fce3dda429 100644
--- a/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
+++ b/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
@@ -314,7 +314,8 @@ public:
txnParticipant.beginOrContinue(opCtx,
*opCtx->getTxnNumber(),
false /* autocommit */,
- boost::none /* startTransaction */);
+ boost::none /* startTransaction */,
+ *opCtx->getTxnRetryCounter());
if (txnParticipant.transactionIsCommitted())
return;
@@ -336,7 +337,8 @@ public:
txnParticipant.beginOrContinue(opCtx,
*opCtx->getTxnNumber(),
false /* autocommit */,
- boost::none /* startTransaction */);
+ boost::none /* startTransaction */,
+ *opCtx->getTxnRetryCounter());
invariant(!txnParticipant.transactionIsOpen(),
"The participant should not be in progress after we waited for the "