summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-08-26 13:39:49 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-26 18:58:09 +0000
commit7fb0eb0a04a5a165428244524e32ae7cce206d22 (patch)
tree857d3ab1ad214f302824bfd63ed420a364b0005f /src/mongo
parent2c64cc5a0536aa4c496204af0ee38263426a4085 (diff)
downloadmongo-7fb0eb0a04a5a165428244524e32ae7cce206d22.tar.gz
SERVER-68215 add MongoDSessionCatalogTransactionInterface::abortTransaction()
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/session/session_catalog_mongod.cpp15
-rw-r--r--src/mongo/db/session/session_catalog_mongod_transaction_interface.h6
-rw-r--r--src/mongo/db/transaction/session_catalog_mongod_transaction_interface_impl.cpp13
-rw-r--r--src/mongo/db/transaction/session_catalog_mongod_transaction_interface_impl.h2
4 files changed, 25 insertions, 11 deletions
diff --git a/src/mongo/db/session/session_catalog_mongod.cpp b/src/mongo/db/session/session_catalog_mongod.cpp
index ff31b202e3f..2a45fb5722f 100644
--- a/src/mongo/db/session/session_catalog_mongod.cpp
+++ b/src/mongo/db/session/session_catalog_mongod.cpp
@@ -409,7 +409,8 @@ void createRetryableFindAndModifyTable(OperationContext* opCtx) {
void abortInProgressTransactions(OperationContext* opCtx,
- MongoDSessionCatalog* mongoDSessionCatalog) {
+ MongoDSessionCatalog* mongoDSessionCatalog,
+ MongoDSessionCatalogTransactionInterface* ti) {
DBDirectClient client(opCtx);
FindCommandRequest findRequest{NamespaceString::kSessionTransactionsTableNamespace};
findRequest.setFilter(BSON(SessionTxnRecord::kStateFieldName
@@ -434,15 +435,7 @@ void abortInProgressTransactions(OperationContext* opCtx,
hangDuringStepUpAbortInProgressTransactions.pauseWhileSet();
auto ocs = mongoDSessionCatalog->checkOutSessionWithoutRefresh(opCtx);
- auto txnParticipant = TransactionParticipant::get(opCtx);
- LOGV2_DEBUG(21978,
- 3,
- "Aborting transaction sessionId: {sessionId} txnNumber {txnNumber}",
- "Aborting transaction",
- "sessionId"_attr = txnRecord.getSessionId().toBSON(),
- "txnNumber"_attr = txnRecord.getTxnNum());
- txnParticipant.abortTransaction(opCtx);
- opCtx->resetMultiDocumentTransactionState();
+ ti->abortTransaction(opCtx, txnRecord);
}
}
@@ -571,7 +564,7 @@ void MongoDSessionCatalog::onStepUp(OperationContext* opCtx) {
}
}
- abortInProgressTransactions(opCtx, this);
+ abortInProgressTransactions(opCtx, this, _ti.get());
createTransactionTable(opCtx);
if (repl::feature_flags::gFeatureFlagRetryableFindAndModify.isEnabledAndIgnoreFCV()) {
diff --git a/src/mongo/db/session/session_catalog_mongod_transaction_interface.h b/src/mongo/db/session/session_catalog_mongod_transaction_interface.h
index fd800245c7e..9f3381035e8 100644
--- a/src/mongo/db/session/session_catalog_mongod_transaction_interface.h
+++ b/src/mongo/db/session/session_catalog_mongod_transaction_interface.h
@@ -31,6 +31,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/session/session_catalog.h" // for ScanSessionsCallbackFn
+#include "mongo/db/session/session_txn_record_gen.h" // for SessionTxnRecord
#include "mongo/db/transaction/transaction_participant.h" // for SessionToKill
namespace mongo {
@@ -47,6 +48,11 @@ public:
virtual ~MongoDSessionCatalogTransactionInterface() = default;
/**
+ * Aborts the transaction, releasing transaction resources.
+ */
+ virtual void abortTransaction(OperationContext* opCtx, const SessionTxnRecord& txnRecord) = 0;
+
+ /**
* Marks the session as requiring refresh. Used when the session state has been modified
* externally, such as through a direct write to the transactions table.
*/
diff --git a/src/mongo/db/transaction/session_catalog_mongod_transaction_interface_impl.cpp b/src/mongo/db/transaction/session_catalog_mongod_transaction_interface_impl.cpp
index 0c944cfffb4..3dad0360eb9 100644
--- a/src/mongo/db/transaction/session_catalog_mongod_transaction_interface_impl.cpp
+++ b/src/mongo/db/transaction/session_catalog_mongod_transaction_interface_impl.cpp
@@ -37,6 +37,19 @@
namespace mongo {
+void MongoDSessionCatalogTransactionInterfaceImpl::abortTransaction(
+ OperationContext* opCtx, const SessionTxnRecord& txnRecord) {
+ auto txnParticipant = TransactionParticipant::get(opCtx);
+ LOGV2_DEBUG(21978,
+ 3,
+ "Aborting transaction sessionId: {sessionId} txnNumber {txnNumber}",
+ "Aborting transaction",
+ "sessionId"_attr = txnRecord.getSessionId().toBSON(),
+ "txnNumber"_attr = txnRecord.getTxnNum());
+ txnParticipant.abortTransaction(opCtx);
+ opCtx->resetMultiDocumentTransactionState();
+}
+
void MongoDSessionCatalogTransactionInterfaceImpl::invalidateSessionToKill(
OperationContext* opCtx, const SessionToKill& session) {
auto participant = TransactionParticipant::get(session);
diff --git a/src/mongo/db/transaction/session_catalog_mongod_transaction_interface_impl.h b/src/mongo/db/transaction/session_catalog_mongod_transaction_interface_impl.h
index 8fdd82ab8dc..0104ae730fb 100644
--- a/src/mongo/db/transaction/session_catalog_mongod_transaction_interface_impl.h
+++ b/src/mongo/db/transaction/session_catalog_mongod_transaction_interface_impl.h
@@ -47,6 +47,8 @@ public:
MongoDSessionCatalogTransactionInterfaceImpl() = default;
virtual ~MongoDSessionCatalogTransactionInterfaceImpl() = default;
+ void abortTransaction(OperationContext* opCtx, const SessionTxnRecord& txnRecord) override;
+
void invalidateSessionToKill(OperationContext* opCtx, const SessionToKill& session) override;
ScanSessionsCallbackFn makeParentSessionWorkerFnForReap(