summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-08-24 07:04:40 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-24 12:23:08 +0000
commitdbb9f3a2783be8581a91373dfb5de8eef66df656 (patch)
tree14600eb0ea481c454aa72a08fc01ed4e31b1b5c8 /src
parent3b63216fb7beabecb79d51b291f7f49ac1a8ba1c (diff)
downloadmongo-dbb9f3a2783be8581a91373dfb5de8eef66df656.tar.gz
SERVER-68215 check out mongod sessions through MongoDSessionCatalog
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/fle_crud_mongod.cpp8
-rw-r--r--src/mongo/db/op_observer/op_observer_impl_test.cpp36
-rw-r--r--src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp3
-rw-r--r--src/mongo/db/repl/replication_recovery_test.cpp10
-rw-r--r--src/mongo/db/repl/storage_timestamp_test.cpp10
-rw-r--r--src/mongo/db/repl/tenant_migration_recipient_service.cpp3
-rw-r--r--src/mongo/db/repl/tenant_oplog_applier.cpp18
-rw-r--r--src/mongo/db/repl/tenant_oplog_applier_test.cpp2
-rw-r--r--src/mongo/db/repl/transaction_oplog_application.cpp9
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp14
-rw-r--r--src/mongo/db/s/resharding/resharding_data_copy_util.cpp4
-rw-r--r--src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp3
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_application.cpp4
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_batch_applier_test.cpp6
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_session_application_test.cpp15
-rw-r--r--src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp15
-rw-r--r--src/mongo/db/s/session_catalog_migration_destination.cpp5
-rw-r--r--src/mongo/db/s/session_catalog_migration_destination_test.cpp67
-rw-r--r--src/mongo/db/s/txn_two_phase_commit_cmds.cpp5
-rw-r--r--src/mongo/db/service_entry_point_common.cpp12
-rw-r--r--src/mongo/db/session/session_catalog_mongod.cpp58
-rw-r--r--src/mongo/db/session/session_catalog_mongod.h118
-rw-r--r--src/mongo/db/transaction/transaction_participant_resource_yielder.cpp8
-rw-r--r--src/mongo/db/transaction/transaction_participant_test.cpp191
24 files changed, 446 insertions, 178 deletions
diff --git a/src/mongo/db/fle_crud_mongod.cpp b/src/mongo/db/fle_crud_mongod.cpp
index 22ff5e72f87..2e18d831ec6 100644
--- a/src/mongo/db/fle_crud_mongod.cpp
+++ b/src/mongo/db/fle_crud_mongod.cpp
@@ -107,8 +107,9 @@ public:
txnParticipant.stashTransactionResources(opCtx);
}
- MongoDOperationContextSession::checkIn(opCtx,
- OperationContextSession::CheckInReason::kYield);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ mongoDSessionCatalog->checkInUnscopedSession(
+ opCtx, OperationContextSession::CheckInReason::kYield);
}
_yielded = (session != nullptr);
}
@@ -120,7 +121,8 @@ public:
// unblocking this thread of execution. However, we must wait until the child operation
// on this shard finishes so we can get the session back. This may limit the throughput
// of the operation, but it's correct.
- MongoDOperationContextSession::checkOut(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ mongoDSessionCatalog->checkOutUnscopedSession(opCtx);
if (auto txnParticipant = TransactionParticipant::get(opCtx)) {
// Assumes this is only called from the 'aggregate' or 'getMore' commands. The code
diff --git a/src/mongo/db/op_observer/op_observer_impl_test.cpp b/src/mongo/db/op_observer/op_observer_impl_test.cpp
index c5b9d58ab41..474650e0d13 100644
--- a/src/mongo/db/op_observer/op_observer_impl_test.cpp
+++ b/src/mongo/db/op_observer/op_observer_impl_test.cpp
@@ -86,11 +86,12 @@ OplogEntry getInnerEntryFromApplyOpsOplogEntry(const OplogEntry& oplogEntry) {
void beginRetryableWriteWithTxnNumber(
OperationContext* opCtx,
TxnNumber txnNumber,
- std::unique_ptr<MongoDOperationContextSession>& contextSession) {
+ std::unique_ptr<MongoDSessionCatalog::Session>& contextSession) {
opCtx->setLogicalSessionId(makeLogicalSessionIdForTest());
opCtx->setTxnNumber(txnNumber);
- contextSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ contextSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(opCtx,
{*opCtx->getTxnNumber()},
@@ -101,12 +102,13 @@ void beginRetryableWriteWithTxnNumber(
void beginNonRetryableTransactionWithTxnNumber(
OperationContext* opCtx,
TxnNumber txnNumber,
- std::unique_ptr<MongoDOperationContextSession>& contextSession) {
+ std::unique_ptr<MongoDSessionCatalog::Session>& contextSession) {
opCtx->setLogicalSessionId(makeLogicalSessionIdForTest());
opCtx->setTxnNumber(txnNumber);
opCtx->setInMultiDocumentTransaction();
- contextSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ contextSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {*opCtx->getTxnNumber()}, false /* autocommit */, true /* startTransaction */);
@@ -115,12 +117,13 @@ void beginNonRetryableTransactionWithTxnNumber(
void beginRetryableInternalTransactionWithTxnNumber(
OperationContext* opCtx,
TxnNumber txnNumber,
- std::unique_ptr<MongoDOperationContextSession>& contextSession) {
+ std::unique_ptr<MongoDSessionCatalog::Session>& contextSession) {
opCtx->setLogicalSessionId(makeLogicalSessionIdWithTxnNumberAndUUIDForTest());
opCtx->setTxnNumber(txnNumber);
opCtx->setInMultiDocumentTransaction();
- contextSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ contextSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {*opCtx->getTxnNumber()}, false /* autocommit */, true /* startTransaction */);
@@ -1003,10 +1006,11 @@ TEST_F(OpObserverSessionCatalogRollbackTest,
const TxnNumber txnNum = 0;
const StmtId stmtId = 1000;
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(getServiceContext());
{
auto opCtx = cc().makeOperationContext();
opCtx->setLogicalSessionId(sessionId);
- MongoDOperationContextSession ocs(opCtx.get());
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx.get());
auto txnParticipant = TransactionParticipant::get(opCtx.get());
txnParticipant.refreshFromStorageIfNeeded(opCtx.get());
@@ -1030,7 +1034,7 @@ TEST_F(OpObserverSessionCatalogRollbackTest,
{
auto opCtx = cc().makeOperationContext();
opCtx->setLogicalSessionId(sessionId);
- MongoDOperationContextSession ocs(opCtx.get());
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx.get());
auto txnParticipant = TransactionParticipant::get(opCtx.get());
ASSERT(txnParticipant.checkStatementExecutedNoOplogEntryFetch(opCtx.get(), stmtId));
}
@@ -1161,7 +1165,7 @@ private:
boost::optional<ExposeOpObserverTimes::ReservedTimes> _times;
boost::optional<TransactionParticipant::Participant> _txnParticipant;
- std::unique_ptr<MongoDOperationContextSession> _sessionCheckout;
+ std::unique_ptr<MongoDSessionCatalog::Session> _sessionCheckout;
TxnNumber _txnNum = 0;
};
@@ -2427,7 +2431,7 @@ TEST_F(OnUpdateOutputsTest, TestNonTransactionFundamentalOnUpdateOutputs) {
// Phase 1: Clearing any state and setting up fixtures/the update call.
resetOplogAndTransactions(opCtx);
- std::unique_ptr<MongoDOperationContextSession> contextSession;
+ std::unique_ptr<MongoDSessionCatalog::Session> contextSession;
if (testCase.isRetryable()) {
beginRetryableWriteWithTxnNumber(opCtx, testIdx, contextSession);
}
@@ -2470,7 +2474,7 @@ TEST_F(OnUpdateOutputsTest, TestFundamentalTransactionOnUpdateOutputs) {
// Phase 1: Clearing any state and setting up fixtures/the update call.
resetOplogAndTransactions(opCtx);
- std::unique_ptr<MongoDOperationContextSession> contextSession;
+ std::unique_ptr<MongoDSessionCatalog::Session> contextSession;
if (testCase.isRetryable()) {
beginRetryableInternalTransactionWithTxnNumber(opCtx, testIdx, contextSession);
} else {
@@ -2514,7 +2518,7 @@ TEST_F(OnUpdateOutputsTest,
resetOplogAndTransactions(opCtx);
- std::unique_ptr<MongoDOperationContextSession> contextSession;
+ std::unique_ptr<MongoDSessionCatalog::Session> contextSession;
beginRetryableInternalTransactionWithTxnNumber(opCtx, 0, contextSession);
CollectionUpdateArgs updateArgs;
@@ -2572,7 +2576,7 @@ TEST_F(OpObserverTest, TestFundamentalOnInsertsOutputs) {
toInsert.emplace_back(stmtId, BSON("_id" << stmtIdx));
}
- std::unique_ptr<MongoDOperationContextSession> contextSession;
+ std::unique_ptr<MongoDSessionCatalog::Session> contextSession;
if (testCase.isRetryableWrite) {
beginRetryableWriteWithTxnNumber(opCtx, testIdx, contextSession);
}
@@ -3366,7 +3370,7 @@ TEST_F(OnDeleteOutputsTest, TestNonTransactionFundamentalOnDeleteOutputs) {
// Phase 1: Clearing any state and setting up fixtures/the delete call.
resetOplogAndTransactions(opCtx);
- std::unique_ptr<MongoDOperationContextSession> contextSession;
+ std::unique_ptr<MongoDSessionCatalog::Session> contextSession;
if (testCase.isRetryable()) {
beginRetryableWriteWithTxnNumber(opCtx, testIdx, contextSession);
}
@@ -3413,7 +3417,7 @@ TEST_F(OnDeleteOutputsTest, TestTransactionFundamentalOnDeleteOutputs) {
// Phase 1: Clearing any state and setting up fixtures/the delete call.
resetOplogAndTransactions(opCtx);
- std::unique_ptr<MongoDOperationContextSession> contextSession;
+ std::unique_ptr<MongoDSessionCatalog::Session> contextSession;
if (testCase.isRetryable()) {
beginRetryableInternalTransactionWithTxnNumber(opCtx, testIdx, contextSession);
} else {
@@ -3461,7 +3465,7 @@ TEST_F(OnDeleteOutputsTest,
resetOplogAndTransactions(opCtx);
- std::unique_ptr<MongoDOperationContextSession> contextSession;
+ std::unique_ptr<MongoDSessionCatalog::Session> contextSession;
beginRetryableInternalTransactionWithTxnNumber(opCtx, 0, contextSession);
OplogDeleteEntryArgs deleteEntryArgs;
diff --git a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp
index cd7599013eb..76750e8c790 100644
--- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp
+++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/repl/replication_recovery_mock.h"
#include "mongo/db/repl/storage_interface.h"
#include "mongo/db/repl/storage_interface_impl.h"
+#include "mongo/db/session/session_catalog_mongod.h"
#include "mongo/db/vector_clock_mutable.h"
namespace mongo {
@@ -159,6 +160,8 @@ void OplogApplierImplTest::setUp() {
StorageInterface::set(serviceContext, std::make_unique<StorageInterfaceImpl>());
+ MongoDSessionCatalog::set(serviceContext, std::make_unique<MongoDSessionCatalog>());
+
DropPendingCollectionReaper::set(
serviceContext, std::make_unique<DropPendingCollectionReaper>(getStorageInterface()));
repl::createOplog(_opCtx.get());
diff --git a/src/mongo/db/repl/replication_recovery_test.cpp b/src/mongo/db/repl/replication_recovery_test.cpp
index 573fef8bc8e..fcaef636ac7 100644
--- a/src/mongo/db/repl/replication_recovery_test.cpp
+++ b/src/mongo/db/repl/replication_recovery_test.cpp
@@ -1341,8 +1341,9 @@ TEST_F(ReplicationRecoveryTest, RecoverFromOplogUpToReconstructsPreparedTransact
const auto sessionId = makeLogicalSessionIdForTest();
opCtx->setLogicalSessionId(sessionId);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
{
- MongoDOperationContextSession ocs(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
OperationSessionInfo sessionInfo;
sessionInfo.setSessionId(sessionId);
@@ -1365,7 +1366,7 @@ TEST_F(ReplicationRecoveryTest, RecoverFromOplogUpToReconstructsPreparedTransact
recovery.recoverFromOplogUpTo(opCtx, Timestamp(3, 3));
{
- MongoDOperationContextSession ocs(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
ASSERT_EQ(txnParticipant.getPrepareOpTime().getTimestamp(), Timestamp(3, 3));
@@ -1385,8 +1386,9 @@ TEST_F(ReplicationRecoveryTest,
const auto sessionId = makeLogicalSessionIdForTest();
opCtx->setLogicalSessionId(sessionId);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
{
- MongoDOperationContextSession ocs(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
OperationSessionInfo sessionInfo;
sessionInfo.setSessionId(sessionId);
@@ -1423,7 +1425,7 @@ TEST_F(ReplicationRecoveryTest,
countTextFormatLogLinesContaining("No stored oplog entries to apply for recovery between"));
{
- MongoDOperationContextSession ocs(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
ASSERT_EQ(txnParticipant.getPrepareOpTime().getTimestamp(), Timestamp(1, 1));
diff --git a/src/mongo/db/repl/storage_timestamp_test.cpp b/src/mongo/db/repl/storage_timestamp_test.cpp
index 89afdde3ec3..73fdc89ac88 100644
--- a/src/mongo/db/repl/storage_timestamp_test.cpp
+++ b/src/mongo/db/repl/storage_timestamp_test.cpp
@@ -1735,7 +1735,7 @@ TEST_F(StorageTimestampTest, PrimarySetsMultikeyInsideMultiDocumentTransaction)
_opCtx->setInMultiDocumentTransaction();
// Check out the session.
- MongoDOperationContextSession ocs(_opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(_opCtx);
auto txnParticipant = TransactionParticipant::get(_opCtx);
ASSERT(txnParticipant);
@@ -3254,7 +3254,7 @@ public:
const auto txnNumber = 10;
_opCtx->setTxnNumber(txnNumber);
- ocs.emplace(_opCtx);
+ ocs = mongoDSessionCatalog->checkOutSession(_opCtx);
{
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_IX);
@@ -3283,7 +3283,7 @@ protected:
Timestamp beforeOplogTs;
Timestamp oplogTs;
- boost::optional<MongoDOperationContextSession> ocs;
+ std::unique_ptr<MongoDSessionCatalog::Session> ocs;
};
TEST_F(RetryableFindAndModifyTest, RetryableFindAndModifyUpdate) {
@@ -3458,7 +3458,7 @@ public:
_opCtx->setTxnNumber(26);
_opCtx->setInMultiDocumentTransaction();
- ocs.emplace(_opCtx);
+ ocs = mongoDSessionCatalog->checkOutSession(_opCtx);
auto txnParticipant = TransactionParticipant::get(_opCtx);
ASSERT(txnParticipant);
@@ -3520,7 +3520,7 @@ protected:
Timestamp beforeTxnTs;
Timestamp commitEntryTs;
- boost::optional<MongoDOperationContextSession> ocs;
+ std::unique_ptr<MongoDSessionCatalog::Session> ocs;
};
TEST_F(MultiDocumentTransactionTest, MultiDocumentTransaction) {
diff --git a/src/mongo/db/repl/tenant_migration_recipient_service.cpp b/src/mongo/db/repl/tenant_migration_recipient_service.cpp
index 7f3b1e2474f..539e7c486b9 100644
--- a/src/mongo/db/repl/tenant_migration_recipient_service.cpp
+++ b/src/mongo/db/repl/tenant_migration_recipient_service.cpp
@@ -1321,7 +1321,8 @@ void TenantMigrationRecipientService::Instance::_processCommittedTransactionEntr
opCtx->setLogicalSessionId(sessionId);
opCtx->setTxnNumber(txnNumber);
opCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
LOGV2_DEBUG(5351301,
1,
diff --git a/src/mongo/db/repl/tenant_oplog_applier.cpp b/src/mongo/db/repl/tenant_oplog_applier.cpp
index 098439436ee..7dac5595470 100644
--- a/src/mongo/db/repl/tenant_oplog_applier.cpp
+++ b/src/mongo/db/repl/tenant_oplog_applier.cpp
@@ -552,7 +552,7 @@ void TenantOplogApplier::_writeSessionNoOpsForRange(
// All the ops will have the same session, so we can retain the scopedSession throughout
// the loop, except when invalidated by multi-document transactions. This allows us to
// track the statements in a retryable write.
- boost::optional<MongoDOperationContextSessionWithoutOplogRead> scopedSession;
+ std::unique_ptr<MongoDSessionCatalog::Session> scopedSession;
// Make sure a partial session doesn't escape.
ON_BLOCK_EXIT([this, &scopedSession, &opCtx] {
@@ -606,8 +606,11 @@ void TenantOplogApplier::_writeSessionNoOpsForRange(
"op"_attr = redact(entry.toBSONForLogging()));
// Check out the session.
- if (!scopedSession)
- scopedSession.emplace(opCtx.get());
+ if (!scopedSession) {
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx.get());
+ scopedSession = mongoDSessionCatalog->checkOutSessionWithoutOplogRead(opCtx.get());
+ }
+
auto txnParticipant = TransactionParticipant::get(opCtx.get());
uassert(
5351500,
@@ -750,8 +753,11 @@ void TenantOplogApplier::_writeSessionNoOpsForRange(
opCtx->setLogicalSessionId(sessionId);
opCtx->setTxnNumber(txnNumber);
- if (!scopedSession)
- scopedSession.emplace(opCtx.get());
+ if (!scopedSession) {
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx.get());
+ scopedSession = mongoDSessionCatalog->checkOutSessionWithoutOplogRead(opCtx.get());
+ }
+
auto txnParticipant = TransactionParticipant::get(opCtx.get());
uassert(5350900,
str::stream() << "Tenant oplog application failed to get retryable write "
@@ -864,7 +870,7 @@ void TenantOplogApplier::_writeSessionNoOpsForRange(
invariant(txnParticipant);
txnParticipant.invalidate(opCtx.get());
opCtx->resetMultiDocumentTransactionState();
- scopedSession = boost::none;
+ scopedSession = {};
}
}
}
diff --git a/src/mongo/db/repl/tenant_oplog_applier_test.cpp b/src/mongo/db/repl/tenant_oplog_applier_test.cpp
index 437ce7dc6ba..04d8005f23a 100644
--- a/src/mongo/db/repl/tenant_oplog_applier_test.cpp
+++ b/src/mongo/db/repl/tenant_oplog_applier_test.cpp
@@ -153,6 +153,8 @@ public:
_opCtx = cc().makeOperationContext();
repl::createOplog(_opCtx.get());
+ MongoDSessionCatalog::set(service, std::make_unique<MongoDSessionCatalog>());
+
// Ensure that we are primary.
auto replCoord = ReplicationCoordinator::get(_opCtx.get());
ASSERT_OK(replCoord->setFollowerMode(MemberState::RS_PRIMARY));
diff --git a/src/mongo/db/repl/transaction_oplog_application.cpp b/src/mongo/db/repl/transaction_oplog_application.cpp
index a2ea789e9bc..4a8cb35e6f3 100644
--- a/src/mongo/db/repl/transaction_oplog_application.cpp
+++ b/src/mongo/db/repl/transaction_oplog_application.cpp
@@ -220,7 +220,8 @@ Status applyCommitTransaction(OperationContext* opCtx,
// The write on transaction table may be applied concurrently, so refreshing state
// from disk may read that write, causing starting a new transaction on an existing
// txnNumber. Thus, we start a new transaction without refreshing state from disk.
- MongoDOperationContextSessionWithoutRefresh sessionCheckout(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto sessionCheckout = mongoDSessionCatalog->checkOutSessionWithoutRefresh(opCtx);
auto transaction = TransactionParticipant::get(opCtx);
invariant(transaction);
@@ -265,7 +266,8 @@ Status applyAbortTransaction(OperationContext* opCtx,
// The write on transaction table may be applied concurrently, so refreshing state
// from disk may read that write, causing starting a new transaction on an existing
// txnNumber. Thus, we start a new transaction without refreshing state from disk.
- MongoDOperationContextSessionWithoutRefresh sessionCheckout(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto sessionCheckout = mongoDSessionCatalog->checkOutSessionWithoutRefresh(opCtx);
auto transaction = TransactionParticipant::get(opCtx);
transaction.unstashTransactionResources(opCtx, "abortTransaction");
@@ -445,7 +447,8 @@ Status _applyPrepareTransaction(OperationContext* opCtx,
// from disk may read that write, causing starting a new transaction on an existing
// txnNumber. Thus, we start a new transaction without refreshing state from disk.
hangBeforeSessionCheckOutForApplyPrepare.pauseWhileSet();
- MongoDOperationContextSessionWithoutRefresh sessionCheckout(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto sessionCheckout = mongoDSessionCatalog->checkOutSessionWithoutRefresh(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index 39689a39da8..415a0fb1042 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -111,7 +111,8 @@ BSONObj makeLocalReadConcernWithAfterClusterTime(Timestamp afterClusterTime) {
}
void checkOutSessionAndVerifyTxnState(OperationContext* opCtx) {
- MongoDOperationContextSession::checkOut(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ mongoDSessionCatalog->checkOutUnscopedSession(opCtx);
TransactionParticipant::get(opCtx).beginOrContinue(opCtx,
{*opCtx->getTxnNumber()},
boost::none /* autocommit */,
@@ -127,7 +128,9 @@ constexpr bool returnsVoid() {
// throwing, will reacquire the session and verify it is still valid to proceed with the migration.
template <typename Callable, std::enable_if_t<!returnsVoid<Callable>(), int> = 0>
auto runWithoutSession(OperationContext* opCtx, Callable&& callable) {
- MongoDOperationContextSession::checkIn(opCtx, OperationContextSession::CheckInReason::kYield);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ mongoDSessionCatalog->checkInUnscopedSession(opCtx,
+ OperationContextSession::CheckInReason::kYield);
auto retVal = callable();
@@ -141,7 +144,9 @@ auto runWithoutSession(OperationContext* opCtx, Callable&& callable) {
// Same as runWithoutSession above but takes a void function.
template <typename Callable, std::enable_if_t<returnsVoid<Callable>(), int> = 0>
void runWithoutSession(OperationContext* opCtx, Callable&& callable) {
- MongoDOperationContextSession::checkIn(opCtx, OperationContextSession::CheckInReason::kYield);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ mongoDSessionCatalog->checkInUnscopedSession(opCtx,
+ OperationContextSession::CheckInReason::kYield);
callable();
@@ -1083,7 +1088,8 @@ void MigrationDestinationManager::_migrateThread(CancellationToken cancellationT
opCtx->setLogicalSessionId(_lsid);
opCtx->setTxnNumber(_txnNumber);
- MongoDOperationContextSession sessionTxnState(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto sessionTxnState = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(opCtx,
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 876e2338bdf..105bec7d644 100644
--- a/src/mongo/db/s/resharding/resharding_data_copy_util.cpp
+++ b/src/mongo/db/s/resharding/resharding_data_copy_util.cpp
@@ -260,7 +260,9 @@ boost::optional<SharedSemiFuture<void>> withSessionCheckedOut(OperationContext*
opCtx->setLogicalSessionId(std::move(lsid));
opCtx->setTxnNumber(txnNumber);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
+
auto txnParticipant = TransactionParticipant::get(opCtx);
try {
diff --git a/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp b/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp
index 614accf368a..7d237aa306e 100644
--- a/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp
@@ -65,7 +65,8 @@ void runInTransaction(OperationContext* opCtx, Callable&& func) {
opCtx->setTxnNumber(txnNum);
opCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
ASSERT(txnParticipant);
diff --git a/src/mongo/db/s/resharding/resharding_oplog_application.cpp b/src/mongo/db/s/resharding/resharding_oplog_application.cpp
index 6d40f1b0cd6..03f6e20095e 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_application.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_application.cpp
@@ -84,7 +84,9 @@ void runWithTransaction(OperationContext* opCtx,
ShardVersion::IGNORED() /* shardVersion */,
boost::none /* databaseVersion */);
- MongoDOperationContextSession ocs(asr.opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(asr.opCtx());
+ auto ocs = mongoDSessionCatalog->checkOutSession(asr.opCtx());
+
auto txnParticipant = TransactionParticipant::get(asr.opCtx());
ScopeGuard guard([opCtx = asr.opCtx(), &txnParticipant] {
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 600eb735962..6b99c919b82 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
@@ -190,7 +190,8 @@ public:
opCtx->setLogicalSessionId(std::move(lsid));
opCtx->setTxnNumber(txnNumber);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {txnNumber}, false /* autocommit */, true /* startTransaction */);
@@ -222,7 +223,8 @@ public:
opCtx->setLogicalSessionId(std::move(lsid));
opCtx->setTxnNumber(txnNumber);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {txnNumber}, false /* autocommit */, boost::none /* startTransaction */);
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 df5dab79569..f9e3b4fccfd 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
@@ -86,7 +86,8 @@ public:
opCtx->setLogicalSessionId(std::move(lsid));
opCtx->setTxnNumber(txnNumber);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {txnNumber}, boost::none /* autocommit */, boost::none /* startTransaction */);
@@ -117,7 +118,8 @@ public:
opCtx->setLogicalSessionId(std::move(lsid));
opCtx->setTxnNumber(txnNumber);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {txnNumber}, false /* autocommit */, true /* startTransaction */);
@@ -133,7 +135,8 @@ public:
opCtx->setLogicalSessionId(std::move(lsid));
opCtx->setTxnNumber(txnNumber);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {txnNumber}, false /* autocommit */, true /* startTransaction */);
@@ -165,7 +168,8 @@ public:
opCtx->setLogicalSessionId(std::move(lsid));
opCtx->setTxnNumber(txnNumber);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {txnNumber}, false /* autocommit */, boost::none /* startTransaction */);
@@ -336,7 +340,8 @@ public:
opCtx->setLogicalSessionId(std::move(lsid));
opCtx->setTxnNumber(txnNumber);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {txnNumber}, boost::none /* autocommit */, boost::none /* startTransaction */);
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 bf8716b8bed..ea8af11ebda 100644
--- a/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp
@@ -240,7 +240,8 @@ protected:
opCtx->setInMultiDocumentTransaction();
}
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
ASSERT(txnParticipant);
@@ -281,7 +282,8 @@ protected:
void checkTxnHasNotBeenUpdated(LogicalSessionId sessionId, TxnNumber txnNum) {
auto opCtx = operationContext();
opCtx->setLogicalSessionId(sessionId);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
DBDirectClient client(operationContext());
@@ -388,7 +390,8 @@ protected:
opCtx->setLogicalSessionId(std::move(lsid));
opCtx->setTxnNumber(txnNumber);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {txnNumber}, false /* autocommit */, true /* startTransaction */);
@@ -404,7 +407,8 @@ protected:
opCtx->setLogicalSessionId(std::move(lsid));
opCtx->setTxnNumber(txnNumber);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {txnNumber}, false /* autocommit */, true /* startTransaction */);
@@ -436,7 +440,8 @@ protected:
opCtx->setLogicalSessionId(std::move(lsid));
opCtx->setTxnNumber(txnNumber);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {txnNumber}, false /* autocommit */, boost::none /* startTransaction */);
diff --git a/src/mongo/db/s/session_catalog_migration_destination.cpp b/src/mongo/db/s/session_catalog_migration_destination.cpp
index 5ebc16ff05c..1174effbf42 100644
--- a/src/mongo/db/s/session_catalog_migration_destination.cpp
+++ b/src/mongo/db/s/session_catalog_migration_destination.cpp
@@ -257,7 +257,10 @@ ProcessOplogResult processSessionOplog(const BSONObj& oplogBSON,
auto opCtx = uniqueOpCtx.get();
opCtx->setLogicalSessionId(result.sessionId);
opCtx->setTxnNumber(result.txnNum);
- MongoDOperationContextSession ocs(opCtx);
+
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
+
auto txnParticipant = TransactionParticipant::get(opCtx);
try {
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 be6d1b7e1a4..9486e1a70fe 100644
--- a/src/mongo/db/s/session_catalog_migration_destination_test.cpp
+++ b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
@@ -180,7 +180,8 @@ public:
const TxnNumber& txnNum) {
opCtx->setLogicalSessionId(sessionId);
opCtx->setTxnNumber(txnNum);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {txnNum}, boost::none /* autocommit */, boost::none /* startTransaction */);
@@ -248,7 +249,8 @@ public:
auto innerOpCtx = Client::getCurrent()->makeOperationContext();
initializeOperationSessionInfo(innerOpCtx.get(), insertBuilder.obj(), true, true, true);
- MongoDOperationContextSession sessionTxnState(innerOpCtx.get());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(innerOpCtx.get());
+ auto sessionTxnState = mongoDSessionCatalog->checkOutSession(innerOpCtx.get());
auto txnParticipant = TransactionParticipant::get(innerOpCtx.get());
txnParticipant.beginOrContinue(innerOpCtx.get(),
{*sessionInfo.getTxnNumber()},
@@ -378,7 +380,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, OplogEntriesWithSameTxn) {
finishSessionExpectSuccess(&sessionMigration);
auto opCtx = operationContext();
setUpSessionWithTxn(opCtx, sessionId, 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -439,7 +442,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, OplogEntriesWithMultiStmtIds) {
finishSessionExpectSuccess(&sessionMigration);
auto opCtx = operationContext();
setUpSessionWithTxn(opCtx, sessionId, 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -507,7 +511,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldOnlyStoreHistoryOfLatestTxn
auto opCtx = operationContext();
setUpSessionWithTxn(opCtx, sessionId, txnNum);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -562,7 +567,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, OplogEntriesWithSameTxnInSeparate
auto opCtx = operationContext();
setUpSessionWithTxn(opCtx, sessionId, 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -630,10 +636,11 @@ TEST_F(SessionCatalogMigrationDestinationTest, OplogEntriesWithDifferentSession)
ASSERT_TRUE(SessionCatalogMigrationDestination::State::Done == sessionMigration.getState());
auto opCtx = operationContext();
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
{
setUpSessionWithTxn(opCtx, sessionId1, 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -650,7 +657,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, OplogEntriesWithDifferentSession)
AlternativeClientRegion acr(client2);
auto opCtx2 = cc().makeOperationContext();
setUpSessionWithTxn(opCtx2.get(), sessionId2, 42);
- MongoDOperationContextSession ocs(opCtx2.get());
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx2.get());
auto txnParticipant = TransactionParticipant::get(opCtx2.get());
@@ -717,7 +724,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldNotNestAlreadyNestedOplog)
auto opCtx = operationContext();
setUpSessionWithTxn(opCtx, sessionId, 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -770,7 +778,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldBeAbleToHandlePreImageFindA
auto opCtx = operationContext();
setUpSessionWithTxn(opCtx, sessionId, 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
@@ -865,7 +874,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldBeAbleToHandleForgedPreImag
auto opCtx = operationContext();
setUpSessionWithTxn(opCtx, sessionId, 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -957,7 +967,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldBeAbleToHandlePostImageFind
auto opCtx = operationContext();
setUpSessionWithTxn(opCtx, sessionId, 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -1050,7 +1061,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldBeAbleToHandleForgedPostIma
auto opCtx = operationContext();
setUpSessionWithTxn(opCtx, sessionId, 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -1145,7 +1157,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldBeAbleToHandleFindAndModify
auto opCtx = operationContext();
setUpSessionWithTxn(opCtx, sessionId, 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
@@ -1248,7 +1261,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, OlderTxnShouldBeIgnored) {
ASSERT_TRUE(SessionCatalogMigrationDestination::State::Done == sessionMigration.getState());
setUpSessionWithTxn(opCtx, sessionId, 20);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
@@ -1313,7 +1327,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, NewerTxnWriteShouldNotBeOverwritt
finishSessionExpectSuccess(&sessionMigration);
setUpSessionWithTxn(opCtx, sessionId, 20);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -1501,7 +1516,8 @@ TEST_F(SessionCatalogMigrationDestinationTest,
finishSessionExpectSuccess(&sessionMigration);
setUpSessionWithTxn(opCtx, sessionId, 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
@@ -1814,7 +1830,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, ShouldIgnoreAlreadyExecutedStatem
finishSessionExpectSuccess(&sessionMigration);
setUpSessionWithTxn(opCtx, sessionId, 19);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -1882,7 +1899,8 @@ TEST_F(SessionCatalogMigrationDestinationTest, OplogEntriesWithIncompleteHistory
auto opCtx = operationContext();
setUpSessionWithTxn(opCtx, *sessionInfo.getSessionId(), 2);
- MongoDOperationContextSession ocs(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant.getLastWriteOpTime());
@@ -1899,6 +1917,7 @@ TEST_F(SessionCatalogMigrationDestinationTest, OplogEntriesWithIncompleteHistory
TEST_F(SessionCatalogMigrationDestinationTest,
OplogEntriesWithOldTransactionFollowedByUpToDateEntries) {
auto opCtx = operationContext();
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
OperationSessionInfo sessionInfo1;
sessionInfo1.setSessionId(makeLogicalSessionIdForTest());
@@ -1908,7 +1927,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
// in TransactionTooOld. This should not preclude the entries for session 2 from getting
// applied.
setUpSessionWithTxn(opCtx, *sessionInfo1.getSessionId(), *sessionInfo1.getTxnNumber());
- MongoDOperationContextSession ocs(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.refreshFromStorageIfNeeded(opCtx);
@@ -1968,7 +1987,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
auto opCtx1 = cc().makeOperationContext();
auto opCtx = opCtx1.get();
setUpSessionWithTxn(opCtx, *sessionInfo1.getSessionId(), 3);
- MongoDOperationContextSession ocs(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant1 = TransactionParticipant::get(opCtx);
ASSERT(txnParticipant1.getLastWriteOpTime().isNull());
}
@@ -1980,7 +1999,7 @@ TEST_F(SessionCatalogMigrationDestinationTest,
auto opCtx2 = cc().makeOperationContext();
auto opCtx = opCtx2.get();
setUpSessionWithTxn(opCtx, *sessionInfo2.getSessionId(), 15);
- MongoDOperationContextSession ocs(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant2 = TransactionParticipant::get(opCtx);
TransactionHistoryIterator historyIter(txnParticipant2.getLastWriteOpTime());
@@ -2006,12 +2025,14 @@ TEST_F(SessionCatalogMigrationDestinationTest, MigratingKnownStmtWhileOplogTrunc
insertDocWithSessionInfo(sessionInfo, kNs, BSON("_id" << 46), kStmtId);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(getServiceContext());
+
auto getLastWriteOpTime = [&]() {
auto c1 = getServiceContext()->makeClient("c1");
AlternativeClientRegion acr(c1);
auto innerOpCtx = cc().makeOperationContext();
setUpSessionWithTxn(innerOpCtx.get(), *sessionInfo.getSessionId(), 19);
- MongoDOperationContextSession ocs(innerOpCtx.get());
+ auto ocs = mongoDSessionCatalog->checkOutSession(innerOpCtx.get());
auto txnParticipant = TransactionParticipant::get(innerOpCtx.get());
return txnParticipant.getLastWriteOpTime();
};
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 68865c61f30..6292abe4f2c 100644
--- a/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
+++ b/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
@@ -328,8 +328,9 @@ public:
"txnNumberAndRetryCounter"_attr = txnNumberAndRetryCounter);
boost::optional<SharedSemiFuture<void>> participantExitPrepareFuture;
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
{
- MongoDOperationContextSession sessionTxnState(opCtx);
+ auto sessionTxnState = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(opCtx,
txnNumberAndRetryCounter,
@@ -349,7 +350,7 @@ public:
participantExitPrepareFuture->get(opCtx);
{
- MongoDOperationContextSession sessionTxnState(opCtx);
+ auto sessionTxnState = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
// Call beginOrContinue again in case the transaction number has changed.
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp
index 70d6abb1d31..4284484daf5 100644
--- a/src/mongo/db/service_entry_point_common.cpp
+++ b/src/mongo/db/service_entry_point_common.cpp
@@ -856,7 +856,7 @@ private:
ExecCommandDatabase* const _ecd;
- std::unique_ptr<MongoDOperationContextSession> _sessionTxnState;
+ std::unique_ptr<MongoDSessionCatalog::Session> _sessionTxnState;
bool _shouldCleanUp = false;
};
@@ -976,15 +976,15 @@ void CheckoutSessionAndInvokeCommand::_checkOutSession() {
// for both multi-statement transactions and retryable writes. Currently, only requests with
// a transaction number will check out the session.
hangBeforeSessionCheckOut.pauseWhileSet();
- _sessionTxnState = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ _sessionTxnState = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
hangAfterSessionCheckOut.pauseWhileSet();
// Used for waiting for an in-progress transaction to transition out of the conflicting state.
- auto waitForInProgressTxn = [](OperationContext* opCtx, auto& stateTransitionFuture) {
+ auto waitForInProgressTxn = [this](OperationContext* opCtx, auto& stateTransitionFuture) {
// Check the session back in and wait for the conflict to resolve.
- MongoDOperationContextSession::checkIn(opCtx,
- OperationContextSession::CheckInReason::kYield);
+ _sessionTxnState->checkIn(opCtx, OperationContextSession::CheckInReason::kYield);
stateTransitionFuture.wait(opCtx);
// Wait for any commit or abort oplog entry to be visible in the oplog. This will prevent a
// new transaction from missing the transaction table update for the previous commit or
@@ -992,7 +992,7 @@ void CheckoutSessionAndInvokeCommand::_checkOutSession() {
auto storageInterface = repl::StorageInterface::get(opCtx);
storageInterface->waitForAllEarlierOplogWritesToBeVisible(opCtx);
// Check out the session again.
- MongoDOperationContextSession::checkOut(opCtx);
+ _sessionTxnState->checkOut(opCtx);
};
auto apiParamsFromClient = APIParameters::get(opCtx);
diff --git a/src/mongo/db/session/session_catalog_mongod.cpp b/src/mongo/db/session/session_catalog_mongod.cpp
index 82198fdf50c..2822274690b 100644
--- a/src/mongo/db/session/session_catalog_mongod.cpp
+++ b/src/mongo/db/session/session_catalog_mongod.cpp
@@ -448,7 +448,8 @@ void createRetryableFindAndModifyTable(OperationContext* opCtx) {
}
-void abortInProgressTransactions(OperationContext* opCtx) {
+void abortInProgressTransactions(OperationContext* opCtx,
+ MongoDSessionCatalog* mongoDSessionCatalog) {
DBDirectClient client(opCtx);
FindCommandRequest findRequest{NamespaceString::kSessionTransactionsTableNamespace};
findRequest.setFilter(BSON(SessionTxnRecord::kStateFieldName
@@ -464,7 +465,7 @@ void abortInProgressTransactions(OperationContext* opCtx) {
opCtx->setLogicalSessionId(txnRecord.getSessionId());
opCtx->setTxnNumber(txnRecord.getTxnNum());
opCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSessionWithoutRefresh ocs(opCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSessionWithoutRefresh(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
LOGV2_DEBUG(21978,
3,
@@ -476,6 +477,18 @@ void abortInProgressTransactions(OperationContext* opCtx) {
opCtx->resetMultiDocumentTransactionState();
}
}
+
+void _checkInUnscopedSession(OperationContext* opCtx,
+ OperationContextSession::CheckInReason reason) {
+ OperationContextSession::checkIn(opCtx, reason);
+}
+
+void _checkOutUnscopedSession(OperationContext* opCtx) {
+ OperationContextSession::checkOut(opCtx);
+ auto txnParticipant = TransactionParticipant::get(opCtx);
+ txnParticipant.refreshFromStorageIfNeeded(opCtx);
+}
+
} // namespace
const std::string MongoDSessionCatalog::kConfigTxnsPartialIndexName = "parent_lsid";
@@ -566,7 +579,7 @@ void MongoDSessionCatalog::onStepUp(OperationContext* opCtx) {
// expected to cause a deadlock since this 'newOpCtx' will need to acquire the global
// lock in the IS mode prior to reading the config.transactions collection but it
// cannot do that while the RSTL lock is being held by 'opCtx'.
- MongoDOperationContextSessionWithoutRefresh ocs(newOpCtx.get());
+ auto ocs = checkOutSessionWithoutRefresh(newOpCtx.get());
auto txnParticipant = TransactionParticipant::get(newOpCtx.get());
LOGV2_DEBUG(21979,
3,
@@ -580,7 +593,7 @@ void MongoDSessionCatalog::onStepUp(OperationContext* opCtx) {
}
}
- abortInProgressTransactions(opCtx);
+ abortInProgressTransactions(opCtx, this);
createTransactionTable(opCtx);
if (repl::feature_flags::gFeatureFlagRetryableFindAndModify.isEnabledAndIgnoreFCV()) {
@@ -691,7 +704,32 @@ int MongoDSessionCatalog::removeSessionsTransactionRecords(
return numReaped;
}
-MongoDOperationContextSession::MongoDOperationContextSession(OperationContext* opCtx)
+std::unique_ptr<MongoDSessionCatalog::Session> MongoDSessionCatalog::checkOutSession(
+ OperationContext* opCtx) {
+ return std::make_unique<MongoDOperationContextSession>(opCtx, CheckoutTag());
+}
+
+std::unique_ptr<MongoDSessionCatalog::Session> MongoDSessionCatalog::checkOutSessionWithoutRefresh(
+ OperationContext* opCtx) {
+ return std::make_unique<MongoDOperationContextSessionWithoutRefresh>(opCtx, CheckoutTag());
+}
+
+std::unique_ptr<MongoDSessionCatalog::Session>
+MongoDSessionCatalog::checkOutSessionWithoutOplogRead(OperationContext* opCtx) {
+ return std::make_unique<MongoDOperationContextSessionWithoutOplogRead>(opCtx, CheckoutTag());
+}
+
+void MongoDSessionCatalog::checkInUnscopedSession(OperationContext* opCtx,
+ OperationContextSession::CheckInReason reason) {
+ _checkInUnscopedSession(opCtx, reason);
+}
+
+void MongoDSessionCatalog::checkOutUnscopedSession(OperationContext* opCtx) {
+ _checkOutUnscopedSession(opCtx);
+}
+
+MongoDOperationContextSession::MongoDOperationContextSession(OperationContext* opCtx,
+ MongoDSessionCatalog::CheckoutTag tag)
: _operationContextSession(opCtx) {
invariant(!opCtx->getClient()->isInDirectClient());
@@ -703,17 +741,15 @@ MongoDOperationContextSession::~MongoDOperationContextSession() = default;
void MongoDOperationContextSession::checkIn(OperationContext* opCtx,
OperationContextSession::CheckInReason reason) {
- OperationContextSession::checkIn(opCtx, reason);
+ _checkInUnscopedSession(opCtx, reason);
}
void MongoDOperationContextSession::checkOut(OperationContext* opCtx) {
- OperationContextSession::checkOut(opCtx);
- auto txnParticipant = TransactionParticipant::get(opCtx);
- txnParticipant.refreshFromStorageIfNeeded(opCtx);
+ _checkOutUnscopedSession(opCtx);
}
MongoDOperationContextSessionWithoutRefresh::MongoDOperationContextSessionWithoutRefresh(
- OperationContext* opCtx)
+ OperationContext* opCtx, MongoDSessionCatalog::CheckoutTag tag)
: _operationContextSession(opCtx), _opCtx(opCtx) {
invariant(!opCtx->getClient()->isInDirectClient());
const auto clientTxnNumber = *opCtx->getTxnNumber();
@@ -732,7 +768,7 @@ MongoDOperationContextSessionWithoutRefresh::~MongoDOperationContextSessionWitho
}
MongoDOperationContextSessionWithoutOplogRead::MongoDOperationContextSessionWithoutOplogRead(
- OperationContext* opCtx)
+ OperationContext* opCtx, MongoDSessionCatalog::CheckoutTag tag)
: _operationContextSession(opCtx), _opCtx(opCtx) {
invariant(!opCtx->getClient()->isInDirectClient());
diff --git a/src/mongo/db/session/session_catalog_mongod.h b/src/mongo/db/session/session_catalog_mongod.h
index 7b65df78193..ce5de294b51 100644
--- a/src/mongo/db/session/session_catalog_mongod.h
+++ b/src/mongo/db/session/session_catalog_mongod.h
@@ -40,6 +40,8 @@ class MongoDSessionCatalog {
MongoDSessionCatalog& operator=(const MongoDSessionCatalog&) = delete;
public:
+ class CheckoutTag {};
+
/**
* Retrieves the mongod session transaction table associated with the service or operation
* context.
@@ -109,6 +111,75 @@ public:
*/
int removeSessionsTransactionRecords(OperationContext* opCtx,
const std::vector<LogicalSessionId>& lsidsToRemove);
+
+ /**
+ * Functions to check out a session. Returns a scoped object that checks in the session on
+ * destruction.
+ */
+ class Session {
+ Session(const Session&) = delete;
+ Session& operator=(const Session&) = delete;
+
+ public:
+ Session() = default;
+ virtual ~Session() = default;
+
+ /**
+ * This method allows a checked-out session to be temporarily or permanently checked
+ * back in, in order to allow other operations to use it.
+ *
+ * Applies to Session objects returned by checkOutSession() only.
+ *
+ * May only be called if the session has actually been checked out previously.
+ */
+ virtual void checkIn(OperationContext* opCtx,
+ OperationContextSession::CheckInReason reason) = 0;
+
+ /**
+ * Applies to Session objects returned by checkOutSession() only.
+ *
+ * May only be called if the session is not checked out already.
+ */
+ virtual void checkOut(OperationContext* opCtx) = 0;
+ };
+
+ /**
+ * Checks out the session specified in the passed operation context and stores it
+ * for later access by the command. The session is installed when this method returns
+ * and is removed at when the returned Session object goes out of scope.
+ */
+ std::unique_ptr<Session> checkOutSession(OperationContext* opCtx);
+
+ /**
+ * Similar to checkOutSession(), but marks the TransactionParticipant as valid without
+ * refreshing from disk and starts a new transaction unconditionally.
+ *
+ * Returns a scoped Session object that does not support checkIn() or checkOut().
+ *
+ * NOTE: Only used by the replication oplog application logic on secondaries in order to replay
+ * prepared transactions.
+ */
+ std::unique_ptr<Session> checkOutSessionWithoutRefresh(OperationContext* opCtx);
+
+ /**
+ * Similar to checkOutSession(), but marks the TransactionParticipant as valid without
+ * loading the retryable write oplog history. If the last operation was a multi-document
+ * transaction, is equivalent to MongoDOperationContextSession.
+ *
+ * Returns a scoped Session object that does not support checkIn() or checkOut().
+ *
+ * NOTE: Should only be used when reading the oplog history is not possible.
+ */
+ std::unique_ptr<Session> checkOutSessionWithoutOplogRead(OperationContext* opCtx);
+
+ /**
+ * These are lower-level functions for checking in or out sessions without a scoped Session
+ * object (see checkOutSession*() functions above).
+ * Used to implement checkIn()/checkOut() in MongoDOperationContextSession.
+ */
+ void checkInUnscopedSession(OperationContext* opCtx,
+ OperationContextSession::CheckInReason reason);
+ void checkOutUnscopedSession(OperationContext* opCtx);
};
/**
@@ -116,9 +187,12 @@ public:
* it for later access by the command. The session is installed at construction time and is removed
* at destruction.
*/
-class MongoDOperationContextSession {
+class MongoDOperationContextSession : public MongoDSessionCatalog::Session {
+ MongoDOperationContextSession(const MongoDOperationContextSession&) = delete;
+ MongoDOperationContextSession& operator=(const MongoDOperationContextSession&) = delete;
+
public:
- MongoDOperationContextSession(OperationContext* opCtx);
+ MongoDOperationContextSession(OperationContext* opCtx, MongoDSessionCatalog::CheckoutTag tag);
~MongoDOperationContextSession();
/**
@@ -127,12 +201,12 @@ public:
*
* May only be called if the session has actually been checked out previously.
*/
- static void checkIn(OperationContext* opCtx, OperationContextSession::CheckInReason reason);
+ void checkIn(OperationContext* opCtx, OperationContextSession::CheckInReason reason) override;
/**
* May only be called if the session is not checked out already.
*/
- static void checkOut(OperationContext* opCtx);
+ void checkOut(OperationContext* opCtx) override;
private:
OperationContextSession _operationContextSession;
@@ -145,11 +219,25 @@ private:
* NOTE: Only used by the replication oplog application logic on secondaries in order to replay
* prepared transactions.
*/
-class MongoDOperationContextSessionWithoutRefresh {
+class MongoDOperationContextSessionWithoutRefresh : public MongoDSessionCatalog::Session {
+ MongoDOperationContextSessionWithoutRefresh(
+ const MongoDOperationContextSessionWithoutRefresh&) = delete;
+ MongoDOperationContextSessionWithoutRefresh& operator=(
+ const MongoDOperationContextSessionWithoutRefresh&) = delete;
+
public:
- MongoDOperationContextSessionWithoutRefresh(OperationContext* opCtx);
+ MongoDOperationContextSessionWithoutRefresh(OperationContext* opCtx,
+ MongoDSessionCatalog::CheckoutTag tag);
~MongoDOperationContextSessionWithoutRefresh();
+ void checkIn(OperationContext* opCtx, OperationContextSession::CheckInReason reason) override {
+ MONGO_UNREACHABLE;
+ }
+
+ void checkOut(OperationContext* opCtx) override {
+ MONGO_UNREACHABLE;
+ }
+
private:
OperationContextSession _operationContextSession;
OperationContext* const _opCtx;
@@ -162,11 +250,25 @@ private:
*
* NOTE: Should only be used when reading the oplog history is not possible.
*/
-class MongoDOperationContextSessionWithoutOplogRead {
+class MongoDOperationContextSessionWithoutOplogRead : public MongoDSessionCatalog::Session {
+ MongoDOperationContextSessionWithoutOplogRead(
+ const MongoDOperationContextSessionWithoutOplogRead&) = delete;
+ MongoDOperationContextSessionWithoutOplogRead& operator=(
+ const MongoDOperationContextSessionWithoutOplogRead&) = delete;
+
public:
- MongoDOperationContextSessionWithoutOplogRead(OperationContext* opCtx);
+ MongoDOperationContextSessionWithoutOplogRead(OperationContext* opCtx,
+ MongoDSessionCatalog::CheckoutTag tag);
~MongoDOperationContextSessionWithoutOplogRead();
+ void checkIn(OperationContext* opCtx, OperationContextSession::CheckInReason reason) override {
+ MONGO_UNREACHABLE;
+ }
+
+ void checkOut(OperationContext* opCtx) override {
+ MONGO_UNREACHABLE;
+ }
+
private:
OperationContextSession _operationContextSession;
OperationContext* const _opCtx;
diff --git a/src/mongo/db/transaction/transaction_participant_resource_yielder.cpp b/src/mongo/db/transaction/transaction_participant_resource_yielder.cpp
index 4a6ae9c71a1..fd335bb6412 100644
--- a/src/mongo/db/transaction/transaction_participant_resource_yielder.cpp
+++ b/src/mongo/db/transaction/transaction_participant_resource_yielder.cpp
@@ -51,8 +51,9 @@ void TransactionParticipantResourceYielder::yield(OperationContext* opCtx) {
txnParticipant.stashTransactionResources(opCtx);
}
- MongoDOperationContextSession::checkIn(opCtx,
- OperationContextSession::CheckInReason::kYield);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ mongoDSessionCatalog->checkInUnscopedSession(
+ opCtx, OperationContextSession::CheckInReason::kYield);
}
_yielded = (session != nullptr);
}
@@ -64,7 +65,8 @@ void TransactionParticipantResourceYielder::unyield(OperationContext* opCtx) {
// unblocking this thread of execution. However, we must wait until the child operation on
// this shard finishes so we can get the session back. This may limit the throughput of the
// operation, but it's correct.
- MongoDOperationContextSession::checkOut(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ mongoDSessionCatalog->checkOutUnscopedSession(opCtx);
if (auto txnParticipant = TransactionParticipant::get(opCtx)) {
txnParticipant.unstashTransactionResources(opCtx, _cmdName);
diff --git a/src/mongo/db/transaction/transaction_participant_test.cpp b/src/mongo/db/transaction/transaction_participant_test.cpp
index d7b66f8a3ae..e2d601b7228 100644
--- a/src/mongo/db/transaction/transaction_participant_test.cpp
+++ b/src/mongo/db/transaction/transaction_participant_test.cpp
@@ -335,11 +335,12 @@ protected:
func(newOpCtx.get());
}
- std::unique_ptr<MongoDOperationContextSession> checkOutSession(
+ std::unique_ptr<MongoDSessionCatalog::Session> checkOutSession(
boost::optional<bool> startNewTxn = true) {
opCtx()->lockState()->setShouldConflictWithSecondaryBatchApplication(false);
opCtx()->setInMultiDocumentTransaction();
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant.beginOrContinue(opCtx(),
{*opCtx()->getTxnNumber()},
@@ -361,7 +362,8 @@ protected:
opCtx->setInMultiDocumentTransaction();
}
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
if (beginOrContinueTxn) {
auto txnParticipant = TransactionParticipant::get(opCtx);
@@ -443,7 +445,8 @@ TEST_F(TxnParticipantTest, TransactionThrowsLockTimeoutIfLockIsUnavailable) {
newOpCtx.get()->setTxnNumber(newTxnNum);
newOpCtx.get()->setInMultiDocumentTransaction();
- MongoDOperationContextSession newOpCtxSession(newOpCtx.get());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx.get());
+ auto newOpCtxSession = mongoDSessionCatalog->checkOutSession(newOpCtx.get());
auto newTxnParticipant = TransactionParticipant::get(newOpCtx.get());
newTxnParticipant.beginOrContinue(
newOpCtx.get(), {newTxnNum}, false /* autocommit */, true /* startTransaction */);
@@ -870,7 +873,8 @@ TEST_F(TxnParticipantTest, KillOpBeforeCommittingPreparedTransaction) {
opCtx->setInMultiDocumentTransaction();
// Check out the session and continue the transaction.
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto newTxnParticipant = TransactionParticipant::get(opCtx);
newTxnParticipant.beginOrContinue(opCtx,
{*(opCtx->getTxnNumber())},
@@ -914,7 +918,8 @@ TEST_F(TxnParticipantTest, KillOpBeforeAbortingPreparedTransaction) {
opCtx->setInMultiDocumentTransaction();
// Check out the session and continue the transaction.
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto newTxnParticipant = TransactionParticipant::get(opCtx);
newTxnParticipant.beginOrContinue(opCtx,
{*(opCtx->getTxnNumber())},
@@ -1249,7 +1254,8 @@ TEST_F(TxnParticipantTest, ContinuingATransactionWithNoResourcesAborts) {
checkOutSession();
// Check out the session again for a new operation.
- MongoDOperationContextSession sessionCheckout(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto sessionCheckout = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(opCtx(),
@@ -1264,7 +1270,8 @@ TEST_F(TxnParticipantTest, CannotStartNewTransactionIfNotPrimary) {
ASSERT_OK(repl::ReplicationCoordinator::get(opCtx())->setFollowerMode(
repl::MemberState::RS_SECONDARY));
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
// Include 'autocommit=false' for transactions.
@@ -1280,7 +1287,8 @@ TEST_F(TxnParticipantTest, CannotStartRetryableWriteIfNotPrimary) {
ASSERT_OK(repl::ReplicationCoordinator::get(opCtx())->setFollowerMode(
repl::MemberState::RS_SECONDARY));
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
// Omit the 'autocommit' field for retryable writes.
@@ -1383,7 +1391,8 @@ TEST_F(TxnParticipantTest, CannotStartNewTransactionWhilePreparedTransactionInPr
newOpCtx->setTxnNumber(txnNumberToStart);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(newOpCtx,
{txnNumberToStart},
@@ -1418,7 +1427,8 @@ TEST_F(TxnParticipantTest, CannotInsertInPreparedTransaction) {
}
TEST_F(TxnParticipantTest, CannotContinueNonExistentTransaction) {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(opCtx(),
{*opCtx()->getTxnNumber()},
@@ -1655,7 +1665,8 @@ protected:
}
void canSpecifyStartTransactionOnRetryableWriteWithNoWritesExecuted() {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant.beginOrContinue(opCtx(),
@@ -1693,7 +1704,8 @@ protected:
runFunctionFromDifferentOpCtx([&](OperationContext* opCtx) {
opCtx->setLogicalSessionId(lsid);
opCtx->setTxnNumber(txnNumber);
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
TransactionParticipant::get(opCtx).beginOrContinue(
opCtx, {*opCtx->getTxnNumber()}, boost::none, boost::none);
});
@@ -1704,7 +1716,8 @@ protected:
opCtx->setLogicalSessionId(lsid);
opCtx->setTxnNumber(txnNumber);
opCtx->setInMultiDocumentTransaction();
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(opCtx, {*opCtx->getTxnNumber()}, false, true);
@@ -3098,7 +3111,8 @@ TEST_F(TransactionsMetricsTest, ReportUnstashedResourcesForARetryableWrite) {
opCtx->setLogicalSessionId(_sessionId);
opCtx->setTxnNumber(_txnNumber);
- MongoDOperationContextSession opCtxSession(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(opCtx,
{*opCtx->getTxnNumber()},
@@ -3131,7 +3145,8 @@ TEST_F(TransactionsMetricsTest, UseAPIParametersOnOpCtxForARetryableWrite) {
firstAPIParameters.setAPIDeprecationErrors(true);
APIParameters::get(opCtx()) = firstAPIParameters;
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant.beginOrContinue(opCtx(),
{*opCtx()->getTxnNumber()},
@@ -4386,7 +4401,8 @@ TEST_F(TxnParticipantTest, AbortTransactionOnSessionCheckoutWithoutRefresh) {
// MongoDOperationContextSessionWithoutRefresh will begin a new transaction with txnNumber
// unconditionally since the participant's _activeTxnNumber is kUninitializedTxnNumber at time
// of session checkout.
- MongoDOperationContextSessionWithoutRefresh sessionCheckout(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto sessionCheckout = mongoDSessionCatalog->checkOutSessionWithoutRefresh(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT(txnParticipant.transactionIsOpen());
@@ -4398,13 +4414,15 @@ TEST_F(TxnParticipantTest, AbortTransactionOnSessionCheckoutWithoutRefresh) {
}
TEST_F(TxnParticipantTest, ResponseMetadataHasHasReadOnlyFalseIfNothingInProgress) {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT_FALSE(txnParticipant.getResponseMetadata().getReadOnly());
}
TEST_F(TxnParticipantTest, ResponseMetadataHasReadOnlyFalseIfInRetryableWrite) {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT_FALSE(txnParticipant.getResponseMetadata().getReadOnly());
@@ -4417,7 +4435,8 @@ TEST_F(TxnParticipantTest, ResponseMetadataHasReadOnlyFalseIfInRetryableWrite) {
}
TEST_F(TxnParticipantTest, ResponseMetadataHasReadOnlyTrueIfInProgressAndOperationsVectorEmpty) {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT_FALSE(txnParticipant.getResponseMetadata().getReadOnly());
@@ -4432,7 +4451,8 @@ TEST_F(TxnParticipantTest, ResponseMetadataHasReadOnlyTrueIfInProgressAndOperati
TEST_F(TxnParticipantTest,
ResponseMetadataHasReadOnlyFalseIfInProgressAndOperationsVectorNotEmpty) {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT_FALSE(txnParticipant.getResponseMetadata().getReadOnly());
@@ -4452,7 +4472,8 @@ TEST_F(TxnParticipantTest,
}
TEST_F(TxnParticipantTest, ResponseMetadataHasReadOnlyFalseIfAborted) {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT_FALSE(txnParticipant.getResponseMetadata().getReadOnly());
@@ -4539,7 +4560,8 @@ TEST_F(TxnParticipantTest, OldestActiveTransactionTimestampTimeout) {
};
TEST_F(TxnParticipantTest, ExitPreparePromiseIsFulfilledOnAbortAfterPrepare) {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant.beginOrContinue(
@@ -4566,7 +4588,8 @@ TEST_F(TxnParticipantTest, ExitPreparePromiseIsFulfilledOnAbortAfterPrepare) {
}
TEST_F(TxnParticipantTest, ExitPreparePromiseIsFulfilledOnCommitAfterPrepare) {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant.beginOrContinue(
@@ -4592,7 +4615,8 @@ TEST_F(TxnParticipantTest, ExitPreparePromiseIsFulfilledOnCommitAfterPrepare) {
}
TEST_F(ShardTxnParticipantTest, CanSpecifyTxnRetryCounterOnShardSvr) {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant.beginOrContinue(opCtx(),
{*opCtx()->getTxnNumber(), 0},
@@ -4601,7 +4625,8 @@ TEST_F(ShardTxnParticipantTest, CanSpecifyTxnRetryCounterOnShardSvr) {
}
TEST_F(ConfigTxnParticipantTest, CanSpecifyTxnRetryCounterOnConfigSvr) {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant.beginOrContinue(opCtx(),
{*opCtx()->getTxnNumber(), 0},
@@ -4610,7 +4635,8 @@ TEST_F(ConfigTxnParticipantTest, CanSpecifyTxnRetryCounterOnConfigSvr) {
}
TEST_F(TxnParticipantTest, CanOnlySpecifyTxnRetryCounterInShardedClusters) {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(opCtx(),
{*opCtx()->getTxnNumber(), 0},
@@ -4623,7 +4649,8 @@ TEST_F(TxnParticipantTest, CanOnlySpecifyTxnRetryCounterInShardedClusters) {
DEATH_TEST_F(ShardTxnParticipantTest,
CannotSpecifyNegativeTxnRetryCounter,
"Cannot specify a negative txnRetryCounter") {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant.beginOrContinue(opCtx(),
{*opCtx()->getTxnNumber(), -1},
@@ -4634,7 +4661,8 @@ DEATH_TEST_F(ShardTxnParticipantTest,
DEATH_TEST_F(ShardTxnParticipantTest,
CannotSpecifyTxnRetryCounterForRetryableWrite,
"Cannot specify a txnRetryCounter for retryable write") {
- MongoDOperationContextSession opCtxSession(opCtx());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx());
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx());
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(opCtx(),
{*opCtx()->getTxnNumber(), 0},
@@ -4892,7 +4920,8 @@ TEST_F(ShardTxnParticipantTest, CannotRetryInProgressRetryableTxn_ConflictingRet
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */);
@@ -4916,7 +4945,8 @@ TEST_F(ShardTxnParticipantTest, CannotRetryInProgressRetryableTxn_ConflictingRet
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */),
@@ -4930,7 +4960,8 @@ TEST_F(ShardTxnParticipantTest, CannotRetryInProgressRetryableTxn_ConflictingRet
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, boost::none /* startTransaction */);
@@ -4959,7 +4990,8 @@ TEST_F(ShardTxnParticipantTest, CannotRetryInProgressRetryableTxn_ConflictingRet
newOpCtx->setTxnNumber(parentTxnNumber);
// Shouldn't throw.
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
txnParticipant.beginOrContinue(newOpCtx,
{parentTxnNumber},
@@ -4994,7 +5026,8 @@ TEST_F(ShardTxnParticipantTest, CannotRetryInProgressRetryableTxn_ConflictingRet
newOpCtx->setLogicalSessionId(parentLsid);
newOpCtx->setTxnNumber(parentTxnNumber);
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(newOpCtx,
{parentTxnNumber},
@@ -5034,7 +5067,8 @@ TEST_F(ShardTxnParticipantTest, RetryableTransactionInProgressCounterResetsUponN
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */);
@@ -5050,7 +5084,8 @@ TEST_F(ShardTxnParticipantTest, RetryableTransactionInProgressCounterResetsUponN
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */),
@@ -5069,7 +5104,8 @@ TEST_F(ShardTxnParticipantTest, RetryableTransactionInProgressCounterResetsUponN
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */);
@@ -5083,7 +5119,8 @@ TEST_F(ShardTxnParticipantTest, RetryableTransactionInProgressCounterResetsUponN
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */);
@@ -5098,7 +5135,8 @@ TEST_F(ShardTxnParticipantTest, RetryableTransactionInProgressCounterResetsUponN
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */),
@@ -5131,7 +5169,8 @@ TEST_F(ShardTxnParticipantTest, HigherTxnNumberAbortsLowerChildTransactions_Retr
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */);
@@ -5160,7 +5199,8 @@ TEST_F(ShardTxnParticipantTest, HigherTxnNumberAbortsLowerChildTransactions_Retr
newOpCtx->setLogicalSessionId(parentLsid);
newOpCtx->setTxnNumber(parentTxnNumber);
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
txnParticipant.beginOrContinue(newOpCtx,
{parentTxnNumber},
@@ -5191,7 +5231,8 @@ TEST_F(ShardTxnParticipantTest, HigherTxnNumberAbortsLowerChildTransactions_Tran
newOpCtx->setTxnNumber(parentTxnNumber);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
txnParticipant.beginOrContinue(newOpCtx,
*newOpCtx->getTxnNumber(),
@@ -5229,7 +5270,8 @@ TEST_F(ShardTxnParticipantTest, HigherTxnNumberDoesNotAbortPreparedLowerChildTra
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */),
@@ -5241,7 +5283,8 @@ TEST_F(ShardTxnParticipantTest, HigherTxnNumberDoesNotAbortPreparedLowerChildTra
newOpCtx->setLogicalSessionId(parentLsid);
newOpCtx->setTxnNumber(higherParentTxnNumber);
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(newOpCtx,
{higherParentTxnNumber},
@@ -5268,7 +5311,8 @@ TEST_F(ShardTxnParticipantTest, HigherTxnNumberDoesNotAbortPreparedLowerChildTra
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */);
@@ -5282,7 +5326,8 @@ TEST_F(ShardTxnParticipantTest, HigherTxnNumberDoesNotAbortPreparedLowerChildTra
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */);
@@ -5332,7 +5377,8 @@ TEST_F(ShardTxnParticipantTest,
newOpCtx->setTxnNumber(0);
newOpCtx->setInMultiDocumentTransaction();
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(
newOpCtx, {0}, false /* autocommit */, true /* startTransaction */),
@@ -5363,7 +5409,8 @@ TEST_F(ShardTxnParticipantTest,
newOpCtx->setLogicalSessionId(parentLsid);
newOpCtx->setTxnNumber(parentTxnNumber);
- MongoDOperationContextSession ocs(newOpCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx);
+ auto ocs = mongoDSessionCatalog->checkOutSession(newOpCtx);
auto txnParticipant = TransactionParticipant::get(newOpCtx);
ASSERT_THROWS_CODE(txnParticipant.beginOrContinue(newOpCtx,
{parentTxnNumber},
@@ -5632,7 +5679,8 @@ TEST_F(ShardTxnParticipantTest,
newOpCtx.get()->setTxnNumber(20);
newOpCtx.get()->setTxnRetryCounter(1);
newOpCtx.get()->setInMultiDocumentTransaction();
- MongoDOperationContextSession newOpCtxSession(newOpCtx.get());
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(newOpCtx.get());
+ auto newOpCtxSession = mongoDSessionCatalog->checkOutSession(newOpCtx.get());
auto txnParticipant = TransactionParticipant::get(newOpCtx.get());
txnParticipant.beginOrContinue(newOpCtx.get(),
@@ -5660,8 +5708,9 @@ TEST_F(TxnParticipantTest, UnstashTransactionAfterActiveTxnNumberHasChanged) {
opCtx->setTxnNumber(_txnNumber);
opCtx->setInMultiDocumentTransaction();
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
{
- MongoDOperationContextSession opCtxSession(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {*opCtx->getTxnNumber()}, false /* autocommit */, true /* startTransaction */);
@@ -5675,7 +5724,7 @@ TEST_F(TxnParticipantTest, UnstashTransactionAfterActiveTxnNumberHasChanged) {
sideOpCtx.get()->setLogicalSessionId(_sessionId);
sideOpCtx.get()->setTxnNumber(_txnNumber + 1);
sideOpCtx.get()->setInMultiDocumentTransaction();
- MongoDOperationContextSession sideOpCtxSession(sideOpCtx.get());
+ auto sideOpCtxSession = mongoDSessionCatalog->checkOutSession(sideOpCtx.get());
auto txnParticipant = TransactionParticipant::get(sideOpCtx.get());
txnParticipant.beginOrContinue(sideOpCtx.get(),
@@ -5685,7 +5734,7 @@ TEST_F(TxnParticipantTest, UnstashTransactionAfterActiveTxnNumberHasChanged) {
}
{
- MongoDOperationContextSession opCtxSession(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
ASSERT_THROWS_CODE(txnParticipant.unstashTransactionResources(opCtx, "insert"),
AssertionException,
@@ -5701,8 +5750,9 @@ TEST_F(TxnParticipantTest, UnstashRetryableWriteAfterActiveTxnNumberHasChanged)
opCtx->setLogicalSessionId(_sessionId);
opCtx->setTxnNumber(_txnNumber);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
{
- MongoDOperationContextSession opCtxSession(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(opCtx,
{*opCtx->getTxnNumber()},
@@ -5718,7 +5768,7 @@ TEST_F(TxnParticipantTest, UnstashRetryableWriteAfterActiveTxnNumberHasChanged)
sideOpCtx.get()->setLogicalSessionId(_sessionId);
sideOpCtx.get()->setTxnNumber(_txnNumber + 1);
sideOpCtx.get()->setInMultiDocumentTransaction();
- MongoDOperationContextSession sideOpCtxSession(sideOpCtx.get());
+ auto sideOpCtxSession = mongoDSessionCatalog->checkOutSession(sideOpCtx.get());
auto txnParticipant = TransactionParticipant::get(sideOpCtx.get());
txnParticipant.beginOrContinue(sideOpCtx.get(),
@@ -5728,7 +5778,7 @@ TEST_F(TxnParticipantTest, UnstashRetryableWriteAfterActiveTxnNumberHasChanged)
}
{
- MongoDOperationContextSession opCtxSession(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
ASSERT_THROWS_CODE(txnParticipant.unstashTransactionResources(opCtx, "insert"),
AssertionException,
@@ -5745,8 +5795,9 @@ TEST_F(TxnParticipantTest, UnstashTransactionAfterActiveTxnNumberNoLongerCorresp
opCtx->setTxnNumber(_txnNumber);
opCtx->setInMultiDocumentTransaction();
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
{
- MongoDOperationContextSession opCtxSession(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(
opCtx, {*opCtx->getTxnNumber()}, false /* autocommit */, true /* startTransaction */);
@@ -5762,7 +5813,7 @@ TEST_F(TxnParticipantTest, UnstashTransactionAfterActiveTxnNumberNoLongerCorresp
sideOpCtx.get()->setLogicalSessionId(_sessionId);
sideOpCtx.get()->setTxnNumber(_txnNumber);
sideOpCtx.get()->setInMultiDocumentTransaction();
- MongoDOperationContextSession sideOpCtxSession(sideOpCtx.get());
+ auto sideOpCtxSession = mongoDSessionCatalog->checkOutSession(sideOpCtx.get());
auto txnParticipant = TransactionParticipant::get(sideOpCtx.get());
txnParticipant.beginOrContinue(sideOpCtx.get(),
@@ -5772,7 +5823,7 @@ TEST_F(TxnParticipantTest, UnstashTransactionAfterActiveTxnNumberNoLongerCorresp
}
{
- MongoDOperationContextSession opCtxSession(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
ASSERT_THROWS_CODE(txnParticipant.unstashTransactionResources(opCtx, "insert"),
AssertionException,
@@ -5789,8 +5840,9 @@ TEST_F(TxnParticipantTest,
opCtx->setLogicalSessionId(_sessionId);
opCtx->setTxnNumber(_txnNumber);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
{
- MongoDOperationContextSession opCtxSession(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
txnParticipant.beginOrContinue(opCtx,
{*opCtx->getTxnNumber()},
@@ -5808,7 +5860,7 @@ TEST_F(TxnParticipantTest,
sideOpCtx.get()->setLogicalSessionId(_sessionId);
sideOpCtx.get()->setTxnNumber(_txnNumber);
sideOpCtx.get()->setInMultiDocumentTransaction();
- MongoDOperationContextSession sideOpCtxSession(sideOpCtx.get());
+ auto sideOpCtxSession = mongoDSessionCatalog->checkOutSession(sideOpCtx.get());
auto txnParticipant = TransactionParticipant::get(sideOpCtx.get());
txnParticipant.beginOrContinue(sideOpCtx.get(),
@@ -5818,7 +5870,7 @@ TEST_F(TxnParticipantTest,
}
{
- MongoDOperationContextSession opCtxSession(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
ASSERT_THROWS_CODE(txnParticipant.unstashTransactionResources(opCtx, "insert"),
AssertionException,
@@ -5970,11 +6022,13 @@ TEST_F(
parentTxnNumber++;
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(getServiceContext());
+
// Does not call beginOrContinue.
runFunctionFromDifferentOpCtx([&](OperationContext* opCtx) {
opCtx->setLogicalSessionId(parentLsid);
opCtx->setTxnNumber(parentTxnNumber);
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
});
// Does not call beginOrContinue.
auto higherRetryableChildLsid =
@@ -5983,14 +6037,14 @@ TEST_F(
opCtx->setLogicalSessionId(higherRetryableChildLsid);
opCtx->setTxnNumber(0);
opCtx->setInMultiDocumentTransaction();
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
});
// beginOrContinue fails because no startTransaction=true.
runFunctionFromDifferentOpCtx([&](OperationContext* opCtx) {
opCtx->setLogicalSessionId(parentLsid);
opCtx->setTxnNumber(parentTxnNumber);
opCtx->setInMultiDocumentTransaction();
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
ASSERT_THROWS_CODE(
@@ -6052,7 +6106,8 @@ TEST_F(ShardTxnParticipantTest, EagerlyReapLowerTxnNumbers) {
opCtx->setLogicalSessionId(lowerRetryableChildLsid);
opCtx->setTxnNumber(0);
opCtx->setInMultiDocumentTransaction();
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
});
ASSERT_EQ(sessionCatalog->size(), 1);
@@ -6100,7 +6155,8 @@ TEST_F(ShardTxnParticipantTest, EagerlyReapSkipsHigherUnusedTxnNumbers) {
opCtx->setLogicalSessionId(higherUnusedRetryableChildLsid);
opCtx->setTxnNumber(0);
opCtx->setInMultiDocumentTransaction();
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
});
ASSERT_EQ(sessionCatalog->size(), 1);
@@ -6148,7 +6204,8 @@ TEST_F(ShardTxnParticipantTest, EagerlyReapSkipsKilledSessions) {
runFunctionFromDifferentOpCtx([&](OperationContext* opCtx) {
opCtx->setLogicalSessionId(parentLsid);
opCtx->setTxnNumber(parentTxnNumber);
- auto opCtxSession = std::make_unique<MongoDOperationContextSession>(opCtx);
+ auto mongoDSessionCatalog = MongoDSessionCatalog::get(opCtx);
+ auto opCtxSession = mongoDSessionCatalog->checkOutSession(opCtx);
TransactionParticipant::get(opCtx).beginOrContinue(
opCtx, {*opCtx->getTxnNumber()}, boost::none, boost::none);