summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2018-10-22 21:57:16 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2018-11-08 18:11:44 -0500
commit4fb38d9c10123321dada6fe1be477f9cb99732a7 (patch)
tree0a84c02c5445e3ce996bf3e4efefbcfaf64b7a07 /src/mongo/db
parenta955b238b22c81c3cc4ec840aaf8e25d280ac9c8 (diff)
downloadmongo-4fb38d9c10123321dada6fe1be477f9cb99732a7.tar.gz
SERVER-37179 Pull out starting transaction from session checkout and push it down to before command execution.
Transaction will begin or continue after waiting for read concern. If an error is thrown on starting transaction, it'll be able to wait for write concern if a write concern is specified.
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/op_observer_impl_test.cpp234
-rw-r--r--src/mongo/db/operation_context_session_mongod.cpp14
-rw-r--r--src/mongo/db/read_concern_mongod.cpp12
-rw-r--r--src/mongo/db/repl/do_txn_test.cpp1
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp3
-rw-r--r--src/mongo/db/repl/storage_interface.h5
-rw-r--r--src/mongo/db/repl/storage_interface_impl.cpp6
-rw-r--r--src/mongo/db/repl/storage_interface_impl.h2
-rw-r--r--src/mongo/db/repl/storage_interface_mock.h4
-rw-r--r--src/mongo/db/s/session_catalog_migration_destination_test.cpp2
-rw-r--r--src/mongo/db/service_entry_point_common.cpp41
-rw-r--r--src/mongo/db/transaction_participant.cpp28
-rw-r--r--src/mongo/db/transaction_participant.h11
-rw-r--r--src/mongo/db/transaction_participant_test.cpp272
14 files changed, 310 insertions, 325 deletions
diff --git a/src/mongo/db/op_observer_impl_test.cpp b/src/mongo/db/op_observer_impl_test.cpp
index dd4cbc4b021..be392209657 100644
--- a/src/mongo/db/op_observer_impl_test.cpp
+++ b/src/mongo/db/op_observer_impl_test.cpp
@@ -102,13 +102,6 @@ private:
}
};
-OperationSessionInfoFromClient makeSessionInfo() {
- OperationSessionInfoFromClient sessionInfo;
- sessionInfo.setAutocommit(false);
- sessionInfo.setStartTransaction(true);
- return sessionInfo;
-}
-
TEST_F(OpObserverTest, CollModWithCollectionOptionsAndTTLInfo) {
OpObserverImpl opObserver;
auto opCtx = cc().makeOperationContext();
@@ -307,7 +300,7 @@ TEST_F(OpObserverTest, OnRenameCollectionOmitsDropTargetFieldIfDropTargetUuidIsN
/**
* Test fixture for testing OpObserver behavior specific to the SessionCatalog.
*/
-class OpObserverSessionCatalogTest : public OpObserverTest {
+class OpObserverSessionCatalogRollbackTest : public OpObserverTest {
public:
void setUp() override {
OpObserverTest::setUp();
@@ -345,8 +338,6 @@ public:
}
};
-using OpObserverSessionCatalogRollbackTest = OpObserverSessionCatalogTest;
-
TEST_F(OpObserverSessionCatalogRollbackTest,
OnRollbackInvalidatesSessionCatalogIfSessionOpsRolledBack) {
const NamespaceString nss("testDB", "testColl");
@@ -447,60 +438,6 @@ TEST_F(OpObserverSessionCatalogRollbackTest,
}
}
-/**
- * Test fixture with sessions and an extra-large oplog for testing large transactions.
- */
-class OpObserverLargeTransactionTest : public OpObserverSessionCatalogTest {
-private:
- repl::ReplSettings createReplSettings() override {
- repl::ReplSettings settings;
- // We need an oplog comfortably large enough to hold an oplog entry that exceeds the BSON
- // size limit. Otherwise we will get the wrong error code when trying to write one.
- settings.setOplogSizeBytes(BSONObjMaxInternalSize + 2 * 1024 * 1024);
- settings.setReplSetString("mySet/node1:12345");
- return settings;
- }
-};
-
-// Tests that a transaction aborts if it becomes too large only during the commit.
-TEST_F(OpObserverLargeTransactionTest, TransactionTooLargeWhileCommitting) {
- OpObserverImpl opObserver;
- auto opCtx = cc().makeOperationContext();
- const NamespaceString nss("testDB", "testColl");
-
- // Create a session.
- auto sessionCatalog = SessionCatalog::get(getServiceContext());
- auto sessionId = makeLogicalSessionIdForTest();
- auto session = sessionCatalog->getOrCreateSession(opCtx.get(), sessionId);
- auto uuid = CollectionUUID::gen();
-
- // Simulate adding transaction data to a session.
- const TxnNumber txnNum = 0;
- opCtx->setLogicalSessionId(sessionId);
- opCtx->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx.get(), true, makeSessionInfo());
- auto txnParticipant = TransactionParticipant::get(opCtx.get());
- txnParticipant->unstashTransactionResources(opCtx.get(), "insert");
-
- // This size is crafted such that two operations of this size are not too big to fit in a single
- // oplog entry, but two operations plus oplog overhead are too big to fit in a single oplog
- // entry.
- constexpr size_t kHalfTransactionSize = BSONObjMaxInternalSize / 2 - 175;
- std::unique_ptr<uint8_t[]> halfTransactionData(new uint8_t[kHalfTransactionSize]());
- auto operation = repl::OplogEntry::makeInsertOperation(
- nss,
- uuid,
- BSON(
- "_id" << 0 << "data"
- << BSONBinData(halfTransactionData.get(), kHalfTransactionSize, BinDataGeneral)));
- txnParticipant->addTransactionOperation(opCtx.get(), operation);
- txnParticipant->addTransactionOperation(opCtx.get(), operation);
- ASSERT_THROWS_CODE(opObserver.onTransactionCommit(opCtx.get(), boost::none, boost::none),
- AssertionException,
- ErrorCodes::TransactionTooLarge);
-}
-
TEST_F(OpObserverTest, OnRollbackInvalidatesAuthCacheWhenAuthNamespaceRolledBack) {
OpObserverImpl opObserver;
auto opCtx = cc().makeOperationContext();
@@ -585,29 +522,41 @@ DEATH_TEST_F(OpObserverTest,
/**
* Test fixture for testing OpObserver behavior specific to multi-document transactions.
*/
-class OpObserverTransactionTest : public OpObserverSessionCatalogTest {
+
+class OpObserverTransactionTest : public OpObserverTest {
public:
void setUp() override {
- OpObserverSessionCatalogTest::setUp();
+ OpObserverTest::setUp();
+ _opCtx = cc().makeOperationContext();
+ _opObserver.emplace();
+
+ MongoDSessionCatalog::onStepUp(opCtx());
// Create a session.
- _opCtx = cc().makeOperationContext();
auto sessionCatalog = SessionCatalog::get(getServiceContext());
auto sessionId = makeLogicalSessionIdForTest();
_session = sessionCatalog->getOrCreateSession(opCtx(), sessionId);
- const auto txnParticipant = TransactionParticipant::getFromNonCheckedOutSession(session());
- txnParticipant->refreshFromStorageIfNeeded(opCtx());
-
- opCtx()->setLogicalSessionId(sessionId);
- _opObserver.emplace();
_times.emplace(opCtx());
+ opCtx()->setLogicalSessionId(session()->getSessionId());
+ opCtx()->setTxnNumber(txnNum());
+ OperationSessionInfoFromClient sessionInfo;
+ sessionInfo.setAutocommit(false);
+ sessionInfo.setStartTransaction(true);
+ _sessionCheckout =
+ std::make_unique<OperationContextSessionMongod>(opCtx(), true, sessionInfo);
+ auto txnParticipant = TransactionParticipant::get(opCtx());
+ txnParticipant->beginOrContinue(*opCtx()->getTxnNumber(), false, true);
}
void tearDown() override {
+ _sessionCheckout.reset();
_times.reset();
_opCtx.reset();
- OpObserverSessionCatalogTest::tearDown();
+ auto sessionCatalog = SessionCatalog::get(getServiceContext());
+ sessionCatalog->reset_forTest();
+
+ OpObserverTest::tearDown();
}
@@ -620,18 +569,6 @@ protected:
ASSERT_EQ(expectedStmtId, oplogEntry.getIntField("stmtId"));
}
- OperationContext* opCtx() {
- return _opCtx.get();
- }
-
- Session* session() {
- return _session->get();
- }
-
- OpObserverImpl& opObserver() {
- return *_opObserver;
- }
-
void assertTxnRecord(TxnNumber txnNum,
repl::OpTime opTime,
boost::optional<DurableTxnStateEnum> txnState) {
@@ -668,27 +605,82 @@ protected:
ASSERT(!cursor->more());
}
+ Session* session() {
+ return _session->get();
+ }
+
+ OpObserverImpl& opObserver() {
+ return *_opObserver;
+ }
+
+ OperationContext* opCtx() {
+ return _opCtx.get();
+ }
+
+ TxnNumber& txnNum() {
+ return _txnNum;
+ }
+
private:
class ExposeOpObserverTimes : public OpObserver {
public:
typedef OpObserver::ReservedTimes ReservedTimes;
};
- ServiceContext::UniqueOperationContext _opCtx;
boost::optional<OpObserverImpl> _opObserver;
- boost::optional<ExposeOpObserverTimes::ReservedTimes> _times;
boost::optional<ScopedSession> _session;
+ ServiceContext::UniqueOperationContext _opCtx;
+ boost::optional<ExposeOpObserverTimes::ReservedTimes> _times;
+ std::unique_ptr<OperationContextSessionMongod> _sessionCheckout;
+ TxnNumber _txnNum = 0;
};
+/**
+ * Test fixture with sessions and an extra-large oplog for testing large transactions.
+ */
+class OpObserverLargeTransactionTest : public OpObserverTransactionTest {
+private:
+ repl::ReplSettings createReplSettings() override {
+ repl::ReplSettings settings;
+ // We need an oplog comfortably large enough to hold an oplog entry that exceeds the BSON
+ // size limit. Otherwise we will get the wrong error code when trying to write one.
+ settings.setOplogSizeBytes(BSONObjMaxInternalSize + 2 * 1024 * 1024);
+ settings.setReplSetString("mySet/node1:12345");
+ return settings;
+ }
+};
+
+// Tests that a transaction aborts if it becomes too large only during the commit.
+TEST_F(OpObserverLargeTransactionTest, TransactionTooLargeWhileCommitting) {
+ const NamespaceString nss("testDB", "testColl");
+ auto uuid = CollectionUUID::gen();
+
+ auto txnParticipant = TransactionParticipant::get(opCtx());
+ txnParticipant->unstashTransactionResources(opCtx(), "insert");
+
+ // This size is crafted such that two operations of this size are not too big to fit in a single
+ // oplog entry, but two operations plus oplog overhead are too big to fit in a single oplog
+ // entry.
+ constexpr size_t kHalfTransactionSize = BSONObjMaxInternalSize / 2 - 175;
+ std::unique_ptr<uint8_t[]> halfTransactionData(new uint8_t[kHalfTransactionSize]());
+ auto operation = repl::OplogEntry::makeInsertOperation(
+ nss,
+ uuid,
+ BSON(
+ "_id" << 0 << "data"
+ << BSONBinData(halfTransactionData.get(), kHalfTransactionSize, BinDataGeneral)));
+ txnParticipant->addTransactionOperation(opCtx(), operation);
+ txnParticipant->addTransactionOperation(opCtx(), operation);
+ ASSERT_THROWS_CODE(opObserver().onTransactionCommit(opCtx(), boost::none, boost::none),
+ AssertionException,
+ ErrorCodes::TransactionTooLarge);
+}
+
TEST_F(OpObserverTransactionTest, TransactionalPrepareTest) {
const NamespaceString nss1("testDB", "testColl");
const NamespaceString nss2("testDB2", "testColl2");
auto uuid1 = CollectionUUID::gen();
auto uuid2 = CollectionUUID::gen();
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -784,10 +776,6 @@ TEST_F(OpObserverTransactionTest, TransactionalPreparedCommitTest) {
const auto doc = BSON("_id" << 0 << "data"
<< "x");
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -854,10 +842,6 @@ TEST_F(OpObserverTransactionTest, TransactionalPreparedAbortTest) {
const auto doc = BSON("_id" << 0 << "data"
<< "x");
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -919,10 +903,6 @@ TEST_F(OpObserverTransactionTest, TransactionalPreparedAbortTest) {
TEST_F(OpObserverTransactionTest, TransactionalUnpreparedAbortTest) {
const NamespaceString nss("testDB", "testColl");
const auto uuid = CollectionUUID::gen();
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -947,10 +927,6 @@ TEST_F(OpObserverTransactionTest, TransactionalUnpreparedAbortTest) {
}
TEST_F(OpObserverTransactionTest, PreparingEmptyTransactionLogsEmptyApplyOps) {
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
txnParticipant->transitionToPreparedforTest();
@@ -974,10 +950,6 @@ TEST_F(OpObserverTransactionTest, PreparingEmptyTransactionLogsEmptyApplyOps) {
}
TEST_F(OpObserverTransactionTest, PreparingTransactionWritesToTransactionTable) {
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
txnParticipant->transitionToPreparedforTest();
@@ -993,15 +965,11 @@ TEST_F(OpObserverTransactionTest, PreparingTransactionWritesToTransactionTable)
ASSERT_EQ(prepareOpTime.getTimestamp(), opCtx()->recoveryUnit()->getPrepareTimestamp());
txnParticipant->stashTransactionResources(opCtx());
- assertTxnRecord(txnNum, prepareOpTime, DurableTxnStateEnum::kPrepared);
+ assertTxnRecord(txnNum(), prepareOpTime, DurableTxnStateEnum::kPrepared);
txnParticipant->unstashTransactionResources(opCtx(), "abortTransaction");
}
TEST_F(OpObserverTransactionTest, AbortingUnpreparedTransactionDoesNotWriteToTransactionTable) {
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
@@ -1015,10 +983,6 @@ TEST_F(OpObserverTransactionTest, AbortingUnpreparedTransactionDoesNotWriteToTra
}
TEST_F(OpObserverTransactionTest, AbortingPreparedTransactionWritesToTransactionTable) {
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
@@ -1043,16 +1007,12 @@ TEST_F(OpObserverTransactionTest, AbortingPreparedTransactionWritesToTransaction
// Abort the storage-transaction without calling the OpObserver.
txnParticipant->shutdown();
- assertTxnRecord(txnNum, {}, DurableTxnStateEnum::kAborted);
+ assertTxnRecord(txnNum(), {}, DurableTxnStateEnum::kAborted);
}
TEST_F(OpObserverTransactionTest, CommittingUnpreparedNonEmptyTransactionWritesToTransactionTable) {
const NamespaceString nss("testDB", "testColl");
const auto uuid = CollectionUUID::gen();
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
@@ -1069,15 +1029,11 @@ TEST_F(OpObserverTransactionTest, CommittingUnpreparedNonEmptyTransactionWritesT
opObserver().onTransactionCommit(opCtx(), boost::none, boost::none);
opCtx()->getWriteUnitOfWork()->commit();
- assertTxnRecord(txnNum, {}, DurableTxnStateEnum::kCommitted);
+ assertTxnRecord(txnNum(), {}, DurableTxnStateEnum::kCommitted);
}
TEST_F(OpObserverTransactionTest,
CommittingUnpreparedEmptyTransactionDoesNotWriteToTransactionTable) {
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
@@ -1092,10 +1048,6 @@ TEST_F(OpObserverTransactionTest,
}
TEST_F(OpObserverTransactionTest, CommittingPreparedTransactionWritesToTransactionTable) {
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
@@ -1118,7 +1070,7 @@ TEST_F(OpObserverTransactionTest, CommittingPreparedTransactionWritesToTransacti
opCtx()->lockState()->unsetMaxLockTimeout();
opObserver().onTransactionCommit(opCtx(), commitSlot, prepareOpTime.getTimestamp());
- assertTxnRecord(txnNum, commitOpTime, DurableTxnStateEnum::kCommitted);
+ assertTxnRecord(txnNum(), commitOpTime, DurableTxnStateEnum::kCommitted);
}
TEST_F(OpObserverTransactionTest, TransactionalInsertTest) {
@@ -1126,10 +1078,6 @@ TEST_F(OpObserverTransactionTest, TransactionalInsertTest) {
const NamespaceString nss2("testDB2", "testColl2");
auto uuid1 = CollectionUUID::gen();
auto uuid2 = CollectionUUID::gen();
- const TxnNumber txnNum = 2;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1203,10 +1151,6 @@ TEST_F(OpObserverTransactionTest, TransactionalUpdateTest) {
const NamespaceString nss2("testDB2", "testColl2");
auto uuid1 = CollectionUUID::gen();
auto uuid2 = CollectionUUID::gen();
- const TxnNumber txnNum = 3;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod opSession(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "update");
@@ -1269,10 +1213,6 @@ TEST_F(OpObserverTransactionTest, TransactionalDeleteTest) {
const NamespaceString nss2("testDB2", "testColl2");
auto uuid1 = CollectionUUID::gen();
auto uuid2 = CollectionUUID::gen();
- const TxnNumber txnNum = 3;
- opCtx()->setTxnNumber(txnNum);
-
- OperationContextSessionMongod sessionTxnState(opCtx(), true, makeSessionInfo());
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "delete");
diff --git a/src/mongo/db/operation_context_session_mongod.cpp b/src/mongo/db/operation_context_session_mongod.cpp
index c2222d572a9..0ccc9224eb0 100644
--- a/src/mongo/db/operation_context_session_mongod.cpp
+++ b/src/mongo/db/operation_context_session_mongod.cpp
@@ -32,7 +32,6 @@
#include "mongo/db/operation_context_session_mongod.h"
-#include "mongo/db/transaction_coordinator_factory.h"
#include "mongo/db/transaction_participant.h"
namespace mongo {
@@ -44,20 +43,7 @@ OperationContextSessionMongod::OperationContextSessionMongod(
: _operationContextSession(opCtx, shouldCheckOutSession) {
if (shouldCheckOutSession && !opCtx->getClient()->isInDirectClient()) {
const auto txnParticipant = TransactionParticipant::get(opCtx);
- const auto clientTxnNumber = *opCtx->getTxnNumber();
-
txnParticipant->refreshFromStorageIfNeeded(opCtx);
- txnParticipant->beginOrContinue(
- clientTxnNumber, sessionInfo.getAutocommit(), sessionInfo.getStartTransaction());
-
- // If "startTransaction" is present, it must be true.
- if (sessionInfo.getStartTransaction()) {
- // If this shard has been selected as the coordinator, set up the coordinator state
- // to be ready to receive votes.
- if (sessionInfo.getCoordinator() == boost::optional<bool>(true)) {
- createTransactionCoordinator(opCtx, clientTxnNumber);
- }
- }
}
}
diff --git a/src/mongo/db/read_concern_mongod.cpp b/src/mongo/db/read_concern_mongod.cpp
index fc4e437a6a7..c50d296601f 100644
--- a/src/mongo/db/read_concern_mongod.cpp
+++ b/src/mongo/db/read_concern_mongod.cpp
@@ -203,9 +203,8 @@ MONGO_REGISTER_SHIM(waitForReadConcern)
// illegal to wait for read concern. This is fine, since the outer operation should have handled
// waiting for read concern. We don't want to ignore prepare conflicts because snapshot reads
// should block on prepared transactions.
- auto txnParticipant = TransactionParticipant::get(opCtx);
- if (opCtx->getClient()->isInDirectClient() && txnParticipant &&
- txnParticipant->inMultiDocumentTransaction()) {
+ if (opCtx->getClient()->isInDirectClient() &&
+ readConcernArgs.getLevel() == repl::ReadConcernLevel::kSnapshotReadConcern) {
opCtx->recoveryUnit()->setIgnorePrepared(false);
return Status::OK();
}
@@ -293,13 +292,6 @@ MONGO_REGISTER_SHIM(waitForReadConcern)
return {ErrorCodes::NotAReplicaSet,
"node needs to be a replica set member to use readConcern: snapshot"};
}
- if (speculative) {
- txnParticipant->setSpeculativeTransactionOpTime(
- opCtx,
- readConcernArgs.getOriginalLevel() == repl::ReadConcernLevel::kSnapshotReadConcern
- ? SpeculativeTransactionOpTime::kAllCommitted
- : SpeculativeTransactionOpTime::kLastApplied);
- }
}
if (atClusterTime) {
diff --git a/src/mongo/db/repl/do_txn_test.cpp b/src/mongo/db/repl/do_txn_test.cpp
index 59c997aa4e0..a60656f2355 100644
--- a/src/mongo/db/repl/do_txn_test.cpp
+++ b/src/mongo/db/repl/do_txn_test.cpp
@@ -162,6 +162,7 @@ void DoTxnTest::setUp() {
_ocs.emplace(_opCtx.get(), true /* checkOutSession */, sessionInfo);
auto txnParticipant = TransactionParticipant::get(opCtx());
+ txnParticipant->beginOrContinue(*opCtx()->getTxnNumber(), false, true);
txnParticipant->unstashTransactionResources(opCtx(), "doTxn");
}
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index 9d2bfa42570..d7eedfa8102 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -1391,8 +1391,7 @@ Status ReplicationCoordinatorImpl::_waitUntilClusterTimeForRead(OperationContext
invariant(!readConcern.getArgsOpTime());
// TODO SERVER-34620: Re-enable speculative behavior when "atClusterTime" is specified.
- auto txnParticipant = TransactionParticipant::get(opCtx);
- const bool speculative = txnParticipant && txnParticipant->inMultiDocumentTransaction() &&
+ const bool speculative = readConcern.getLevel() == ReadConcernLevel::kSnapshotReadConcern &&
!readConcern.getArgsAtClusterTime();
const bool isMajorityCommittedRead =
diff --git a/src/mongo/db/repl/storage_interface.h b/src/mongo/db/repl/storage_interface.h
index 06f351797cb..702a339dbdc 100644
--- a/src/mongo/db/repl/storage_interface.h
+++ b/src/mongo/db/repl/storage_interface.h
@@ -440,6 +440,11 @@ public:
*/
virtual boost::optional<Timestamp> getLastStableCheckpointTimestampDeprecated(
ServiceContext* serviceCtx) const = 0;
+
+ /**
+ * Returns the read timestamp of the recovery unit of the given operation context.
+ */
+ virtual Timestamp getPointInTimeReadTimestamp(OperationContext* opCtx) const = 0;
};
} // namespace repl
diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp
index 12c9ad5dabc..9e9d6e07824 100644
--- a/src/mongo/db/repl/storage_interface_impl.cpp
+++ b/src/mongo/db/repl/storage_interface_impl.cpp
@@ -1195,5 +1195,11 @@ Timestamp StorageInterfaceImpl::getAllCommittedTimestamp(ServiceContext* service
return serviceCtx->getStorageEngine()->getAllCommittedTimestamp();
}
+Timestamp StorageInterfaceImpl::getPointInTimeReadTimestamp(OperationContext* opCtx) const {
+ auto readTimestamp = opCtx->recoveryUnit()->getPointInTimeReadTimestamp();
+ invariant(readTimestamp);
+ return *readTimestamp;
+}
+
} // namespace repl
} // namespace mongo
diff --git a/src/mongo/db/repl/storage_interface_impl.h b/src/mongo/db/repl/storage_interface_impl.h
index dccf503ea64..edbb4f47f2b 100644
--- a/src/mongo/db/repl/storage_interface_impl.h
+++ b/src/mongo/db/repl/storage_interface_impl.h
@@ -191,6 +191,8 @@ public:
boost::optional<Timestamp> getLastStableCheckpointTimestampDeprecated(
ServiceContext* serviceCtx) const override;
+ Timestamp getPointInTimeReadTimestamp(OperationContext* opCtx) const override;
+
private:
const NamespaceString _rollbackIdNss;
};
diff --git a/src/mongo/db/repl/storage_interface_mock.h b/src/mongo/db/repl/storage_interface_mock.h
index 87901cb9253..31194ef8b6b 100644
--- a/src/mongo/db/repl/storage_interface_mock.h
+++ b/src/mongo/db/repl/storage_interface_mock.h
@@ -341,6 +341,10 @@ public:
return boost::none;
}
+ Timestamp getPointInTimeReadTimestamp(OperationContext* opCtx) const override {
+ return {};
+ }
+
// Testing functions.
CreateCollectionForBulkFn createCollectionForBulkFn =
[](const NamespaceString& nss,
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 470fe242732..2eee3b7bf12 100644
--- a/src/mongo/db/s/session_catalog_migration_destination_test.cpp
+++ b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
@@ -252,6 +252,8 @@ public:
// up the session state and perform the insert.
initializeOperationSessionInfo(innerOpCtx.get(), insertBuilder.obj(), true, true, true);
OperationContextSessionMongod sessionTxnState(innerOpCtx.get(), true, {});
+ auto txnParticipant = TransactionParticipant::get(innerOpCtx.get());
+ txnParticipant->beginOrContinue(*sessionInfo.getTxnNumber(), boost::none, boost::none);
const auto reply = performInserts(innerOpCtx.get(), insertRequest);
ASSERT(reply.results.size() == 1);
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp
index c882dd457ee..1abaf6d163a 100644
--- a/src/mongo/db/service_entry_point_common.cpp
+++ b/src/mongo/db/service_entry_point_common.cpp
@@ -74,6 +74,7 @@
#include "mongo/db/snapshot_window_util.h"
#include "mongo/db/stats/counters.h"
#include "mongo/db/stats/top.h"
+#include "mongo/db/transaction_coordinator_factory.h"
#include "mongo/db/transaction_participant.h"
#include "mongo/db/transaction_validation.h"
#include "mongo/rpc/factory.h"
@@ -226,8 +227,9 @@ StatusWith<repl::ReadConcernArgs> _extractReadConcern(const CommandInvocation* i
// We must be in a transaction if the readConcern level was upconverted to snapshot and the
// command must support readConcern level snapshot in order to be supported in transactions.
if (upconvertToSnapshot) {
- return {ErrorCodes::OperationNotSupportedInTransaction,
- str::stream() << "Command is not supported in a transaction"};
+ return {
+ ErrorCodes::OperationNotSupportedInTransaction,
+ str::stream() << "Command is not supported as the first command in a transaction"};
}
return {ErrorCodes::InvalidOptions,
str::stream() << "Command does not support read concern "
@@ -346,6 +348,21 @@ void invokeInTransaction(OperationContext* opCtx,
TransactionParticipant* txnParticipant,
const OperationSessionInfoFromClient& sessionOptions,
rpc::ReplyBuilderInterface* replyBuilder) {
+
+ if (!opCtx->getClient()->isInDirectClient()) {
+ txnParticipant->beginOrContinue(*sessionOptions.getTxnNumber(),
+ sessionOptions.getAutocommit(),
+ sessionOptions.getStartTransaction());
+ // Create coordinator if needed. If "startTransaction" is present, it must be true.
+ if (sessionOptions.getStartTransaction()) {
+ // If this shard has been selected as the coordinator, set up the coordinator state
+ // to be ready to receive votes.
+ if (sessionOptions.getCoordinator() == boost::optional<bool>(true)) {
+ createTransactionCoordinator(opCtx, *sessionOptions.getTxnNumber());
+ }
+ }
+ }
+
txnParticipant->unstashTransactionResources(opCtx, invocation->definition()->getName());
ScopeGuard guard = MakeGuard([&txnParticipant, opCtx]() {
txnParticipant->abortActiveUnpreparedOrStashPreparedTransaction(opCtx);
@@ -417,7 +434,7 @@ bool runCommandImpl(OperationContext* opCtx,
}
} else {
auto wcResult = uassertStatusOK(extractWriteConcern(opCtx, request.body));
- if (txnParticipant && txnParticipant->inMultiDocumentTransaction()) {
+ if (sessionOptions.getAutocommit()) {
validateWriteConcernForTransaction(wcResult, invocation->definition()->getName());
}
@@ -649,26 +666,26 @@ void execCommandDatabase(OperationContext* opCtx,
}
auto& readConcernArgs = repl::ReadConcernArgs::get(opCtx);
- auto txnParticipant = TransactionParticipant::get(opCtx);
- if (!opCtx->getClient()->isInDirectClient() || !txnParticipant ||
- !txnParticipant->inMultiDocumentTransaction()) {
- const bool upconvertToSnapshot = txnParticipant &&
- txnParticipant->inMultiDocumentTransaction() &&
- sessionOptions.getStartTransaction();
+ // If the parent operation runs in snapshot isolation, we don't override the read concern.
+ auto skipReadConcern = opCtx->getClient()->isInDirectClient() &&
+ readConcernArgs.getLevel() == repl::ReadConcernLevel::kSnapshotReadConcern;
+ if (!skipReadConcern) {
+ // If "startTransaction" is present, it must be true due to the parsing above.
+ const bool upconvertToSnapshot(sessionOptions.getStartTransaction());
auto newReadConcernArgs = uassertStatusOK(
_extractReadConcern(invocation.get(), request.body, upconvertToSnapshot));
{
// We must obtain the client lock to set the ReadConcernArgs on the operation
// context as it may be concurrently read by CurrentOp.
stdx::lock_guard<Client> lk(*opCtx->getClient());
- readConcernArgs = newReadConcernArgs;
+ readConcernArgs = std::move(newReadConcernArgs);
}
}
if (readConcernArgs.getLevel() == repl::ReadConcernLevel::kSnapshotReadConcern) {
uassert(ErrorCodes::InvalidOptions,
- "readConcern level snapshot is only valid in multi-statement transactions",
- txnParticipant && txnParticipant->inActiveOrKilledMultiDocumentTransaction());
+ "readConcern level snapshot is only valid for the first transaction operation",
+ opCtx->getClient()->isInDirectClient() || sessionOptions.getStartTransaction());
uassert(ErrorCodes::InvalidOptions,
"readConcern level snapshot requires a session ID",
opCtx->getLogicalSessionId());
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp
index a65250499cc..1609c80d87b 100644
--- a/src/mongo/db/transaction_participant.cpp
+++ b/src/mongo/db/transaction_participant.cpp
@@ -51,6 +51,7 @@
#include "mongo/db/ops/update.h"
#include "mongo/db/query/get_executor.h"
#include "mongo/db/repl/repl_client_info.h"
+#include "mongo/db/repl/storage_interface.h"
#include "mongo/db/retryable_writes_stats.h"
#include "mongo/db/server_parameters.h"
#include "mongo/db/server_transactions_metrics.h"
@@ -438,9 +439,8 @@ void TransactionParticipant::beginOrContinueTransactionUnconditionally(TxnNumber
}
}
-void TransactionParticipant::setSpeculativeTransactionOpTime(
- OperationContext* opCtx, SpeculativeTransactionOpTime opTimeChoice) {
- stdx::lock_guard<stdx::mutex> lg(_mutex);
+void TransactionParticipant::_setSpeculativeTransactionOpTime(
+ WithLock, OperationContext* opCtx, SpeculativeTransactionOpTime opTimeChoice) {
repl::ReplicationCoordinator* replCoord =
repl::ReplicationCoordinator::get(opCtx->getClient()->getServiceContext());
opCtx->recoveryUnit()->setTimestampReadSource(
@@ -448,13 +448,12 @@ void TransactionParticipant::setSpeculativeTransactionOpTime(
? RecoveryUnit::ReadSource::kAllCommittedSnapshot
: RecoveryUnit::ReadSource::kLastAppliedSnapshot);
opCtx->recoveryUnit()->preallocateSnapshot();
- auto readTimestamp = opCtx->recoveryUnit()->getPointInTimeReadTimestamp();
- invariant(readTimestamp);
+ auto readTimestamp = repl::StorageInterface::get(opCtx)->getPointInTimeReadTimestamp(opCtx);
// Transactions do not survive term changes, so combining "getTerm" here with the
// recovery unit timestamp does not cause races.
- _speculativeTransactionReadOpTime = {*readTimestamp, replCoord->getTerm()};
+ _speculativeTransactionReadOpTime = {readTimestamp, replCoord->getTerm()};
stdx::lock_guard<stdx::mutex> lm(_metricsMutex);
- _transactionMetricsObserver.onChooseReadTimestamp(*readTimestamp);
+ _transactionMetricsObserver.onChooseReadTimestamp(readTimestamp);
}
TransactionParticipant::OplogSlotReserver::OplogSlotReserver(OperationContext* opCtx) {
@@ -680,6 +679,21 @@ void TransactionParticipant::unstashTransactionResources(OperationContext* opCtx
return;
}
+ // Set speculative execution.
+ const auto& readConcernArgs = repl::ReadConcernArgs::get(opCtx);
+ const bool speculative =
+ readConcernArgs.getLevel() == repl::ReadConcernLevel::kSnapshotReadConcern &&
+ !readConcernArgs.getArgsAtClusterTime();
+ // Only set speculative on primary.
+ if (opCtx->writesAreReplicated() && speculative) {
+ _setSpeculativeTransactionOpTime(lg,
+ opCtx,
+ readConcernArgs.getOriginalLevel() ==
+ repl::ReadConcernLevel::kSnapshotReadConcern
+ ? SpeculativeTransactionOpTime::kAllCommitted
+ : SpeculativeTransactionOpTime::kLastApplied);
+ }
+
// Stashed transaction resources do not exist for this in-progress multi-document
// transaction. Set up the transaction resources on the opCtx.
opCtx->setWriteUnitOfWork(std::make_unique<WriteUnitOfWork>(opCtx));
diff --git a/src/mongo/db/transaction_participant.h b/src/mongo/db/transaction_participant.h
index 1e1f7253e8d..e778de94cd3 100644
--- a/src/mongo/db/transaction_participant.h
+++ b/src/mongo/db/transaction_participant.h
@@ -166,12 +166,6 @@ public:
void shutdown();
/**
- * Called for speculative transactions to fix the optime of the snapshot to read from.
- */
- void setSpeculativeTransactionOpTime(OperationContext* opCtx,
- SpeculativeTransactionOpTime opTimeChoice);
-
- /**
* Transfers management of transaction resources from the OperationContext to the Session.
*/
void stashTransactionResources(OperationContext* opCtx);
@@ -645,6 +639,11 @@ private:
std::vector<StmtId> stmtIdsWritten,
const repl::OpTime& lastStmtIdWriteTs);
+ // Called for speculative transactions to fix the optime of the snapshot to read from.
+ void _setSpeculativeTransactionOpTime(WithLock,
+ OperationContext* opCtx,
+ SpeculativeTransactionOpTime opTimeChoice);
+
// Finishes committing the multi-document transaction after the storage-transaction has been
// committed, the oplog entry has been inserted into the oplog, and the transactions table has
// been updated.
diff --git a/src/mongo/db/transaction_participant_test.cpp b/src/mongo/db/transaction_participant_test.cpp
index a00a35add63..49513794f0e 100644
--- a/src/mongo/db/transaction_participant_test.cpp
+++ b/src/mongo/db/transaction_participant_test.cpp
@@ -281,6 +281,15 @@ protected:
runFunctionFromDifferentOpCtx(func);
}
+ std::unique_ptr<OperationContextSessionMongod> checkOutSession() {
+ auto sessionInfo = makeSessionInfo();
+ auto opCtxSession =
+ std::make_unique<OperationContextSessionMongod>(opCtx(), true, sessionInfo);
+ auto txnParticipant = TransactionParticipant::get(opCtx());
+ txnParticipant->beginOrContinue(*opCtx()->getTxnNumber(), false, true);
+ return opCtxSession;
+ }
+
OpObserverMock* _opObserver = nullptr;
LogicalSessionId _sessionId;
TxnNumber _txnNumber;
@@ -291,7 +300,7 @@ protected:
TEST_F(TxnParticipantTest, TransactionThrowsLockTimeoutIfLockIsUnavailable) {
const std::string dbName = "TestDB";
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -321,8 +330,8 @@ TEST_F(TxnParticipantTest, TransactionThrowsLockTimeoutIfLockIsUnavailable) {
newOpCtx.get()->setTxnNumber(newTxnNum);
OperationContextSessionMongod newOpCtxSession(newOpCtx.get(), true, makeSessionInfo());
-
auto newTxnParticipant = TransactionParticipant::get(newOpCtx.get());
+ newTxnParticipant->beginOrContinue(newTxnNum, false, true);
newTxnParticipant->unstashTransactionResources(newOpCtx.get(), "insert");
Date_t t1 = Date_t::now();
@@ -347,8 +356,7 @@ TEST_F(TxnParticipantTest, StashAndUnstashResources) {
ASSERT(originalLocker);
ASSERT(originalRecoveryUnit);
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
-
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -388,7 +396,7 @@ TEST_F(TxnParticipantTest, StashAndUnstashResources) {
TEST_F(TxnParticipantTest, CannotSpecifyStartTransactionOnInProgressTxn) {
// Must specify startTransaction=true and autocommit=false to start a transaction.
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT_TRUE(txnParticipant->inMultiDocumentTransaction());
@@ -399,7 +407,7 @@ TEST_F(TxnParticipantTest, CannotSpecifyStartTransactionOnInProgressTxn) {
}
TEST_F(TxnParticipantTest, AutocommitRequiredOnEveryTxnOp) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// We must have stashed transaction resources to do a second operation on the transaction.
@@ -419,7 +427,7 @@ TEST_F(TxnParticipantTest, AutocommitRequiredOnEveryTxnOp) {
}
DEATH_TEST_F(TxnParticipantTest, AutocommitCannotBeTrue, "invariant") {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Passing 'autocommit=true' is not allowed and should crash.
@@ -427,7 +435,7 @@ DEATH_TEST_F(TxnParticipantTest, AutocommitCannotBeTrue, "invariant") {
}
DEATH_TEST_F(TxnParticipantTest, StartTransactionCannotBeFalse, "invariant") {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Passing 'startTransaction=false' is not allowed and should crash.
@@ -435,7 +443,7 @@ DEATH_TEST_F(TxnParticipantTest, StartTransactionCannotBeFalse, "invariant") {
}
TEST_F(TxnParticipantTest, SameTransactionPreservesStoredStatements) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// We must have stashed transaction resources to re-open the transaction.
@@ -459,7 +467,7 @@ TEST_F(TxnParticipantTest, SameTransactionPreservesStoredStatements) {
}
TEST_F(TxnParticipantTest, AbortClearsStoredStatements) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
auto operation = repl::OplogEntry::makeInsertOperation(kNss, kUUID, BSON("TestValue" << 0));
@@ -478,7 +486,7 @@ TEST_F(TxnParticipantTest, AbortClearsStoredStatements) {
// This test makes sure the commit machinery works even when no operations are done on the
// transaction.
TEST_F(TxnParticipantTest, EmptyTransactionCommit) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -491,7 +499,7 @@ TEST_F(TxnParticipantTest, EmptyTransactionCommit) {
}
TEST_F(TxnParticipantTest, CommitTransactionSetsCommitTimestampOnPreparedTransaction) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -524,7 +532,7 @@ TEST_F(TxnParticipantTest, CommitTransactionSetsCommitTimestampOnPreparedTransac
TEST_F(TxnParticipantTest, CommitTransactionWithCommitTimestampFailsOnUnpreparedTransaction) {
const auto commitTimestamp = Timestamp(6, 6);
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -536,7 +544,7 @@ TEST_F(TxnParticipantTest, CommitTransactionWithCommitTimestampFailsOnUnprepared
}
TEST_F(TxnParticipantTest, CommitTransactionDoesNotSetCommitTimestampOnUnpreparedTransaction) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto originalFn = _opObserver->onTransactionCommitFn;
_opObserver->onTransactionCommitFn = [&](boost::optional<OplogSlot> commitOplogEntryOpTime,
@@ -562,7 +570,7 @@ TEST_F(TxnParticipantTest, CommitTransactionDoesNotSetCommitTimestampOnUnprepare
}
TEST_F(TxnParticipantTest, CommitTransactionWithoutCommitTimestampFailsOnPreparedTransaction) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -576,7 +584,7 @@ TEST_F(TxnParticipantTest, CommitTransactionWithoutCommitTimestampFailsOnPrepare
}
TEST_F(TxnParticipantTest, CommitTransactionWithNullCommitTimestampFailsOnPreparedTransaction) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -591,7 +599,7 @@ TEST_F(TxnParticipantTest, CommitTransactionWithNullCommitTimestampFailsOnPrepar
TEST_F(TxnParticipantTest,
CommitTransactionWithCommitTimestampLessThanPrepareTimestampFailsOnPreparedTransaction) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -607,7 +615,7 @@ TEST_F(TxnParticipantTest,
TEST_F(TxnParticipantTest,
CommitTransactionWithCommitTimestampEqualToPrepareTimestampFailsOnPreparedTransaction) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -623,7 +631,7 @@ TEST_F(TxnParticipantTest,
// This test makes sure the abort machinery works even when no operations are done on the
// transaction.
TEST_F(TxnParticipantTest, EmptyTransactionAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "abortTransaction");
@@ -635,7 +643,7 @@ TEST_F(TxnParticipantTest, EmptyTransactionAbort) {
}
TEST_F(TxnParticipantTest, ConcurrencyOfUnstashAndAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// The transaction may be aborted without checking out the txnParticipant.
@@ -648,7 +656,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfUnstashAndAbort) {
}
TEST_F(TxnParticipantTest, ConcurrencyOfUnstashAndMigration) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -670,7 +678,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfUnstashAndMigration) {
}
TEST_F(TxnParticipantTest, ConcurrencyOfStashAndAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "find");
@@ -682,7 +690,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfStashAndAbort) {
}
TEST_F(TxnParticipantTest, ConcurrencyOfStashAndMigration) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -701,7 +709,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfStashAndMigration) {
}
TEST_F(TxnParticipantTest, ConcurrencyOfAddTransactionOperationAndAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -716,7 +724,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfAddTransactionOperationAndAbort) {
}
TEST_F(TxnParticipantTest, ConcurrencyOfAddTransactionOperationAndMigration) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "find");
@@ -736,7 +744,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfAddTransactionOperationAndMigration) {
}
TEST_F(TxnParticipantTest, ConcurrencyOfEndTransactionAndRetrieveOperationsAndAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -750,7 +758,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfEndTransactionAndRetrieveOperationsAndAb
}
TEST_F(TxnParticipantTest, ConcurrencyOfEndTransactionAndRetrieveOperationsAndMigration) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -769,7 +777,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfEndTransactionAndRetrieveOperationsAndMi
}
TEST_F(TxnParticipantTest, ConcurrencyOfCommitUnpreparedTransactionAndAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -784,7 +792,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfCommitUnpreparedTransactionAndAbort) {
}
TEST_F(TxnParticipantTest, ConcurrencyOfCommitPreparedTransactionAndAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -802,7 +810,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfCommitPreparedTransactionAndAbort) {
}
TEST_F(TxnParticipantTest, ConcurrencyOfActiveUnpreparedAbortAndArbitraryAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -819,7 +827,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfActiveUnpreparedAbortAndArbitraryAbort)
}
TEST_F(TxnParticipantTest, ConcurrencyOfActiveUnpreparedAbortAndMigration) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -842,7 +850,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfActiveUnpreparedAbortAndMigration) {
}
TEST_F(TxnParticipantTest, ConcurrencyOfActivePreparedAbortAndArbitraryAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -860,7 +868,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfActivePreparedAbortAndArbitraryAbort) {
}
TEST_F(TxnParticipantTest, ConcurrencyOfPrepareTransactionAndAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
@@ -878,7 +886,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfPrepareTransactionAndAbort) {
}
TEST_F(TxnParticipantTest, KillSessionsDuringPrepareDoesNotAbortTransaction) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
@@ -907,7 +915,7 @@ TEST_F(TxnParticipantTest, KillSessionsDuringPrepareDoesNotAbortTransaction) {
}
DEATH_TEST_F(TxnParticipantTest, AbortDuringPrepareIsFatal, "Invariant") {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
@@ -924,7 +932,7 @@ DEATH_TEST_F(TxnParticipantTest, AbortDuringPrepareIsFatal, "Invariant") {
}
TEST_F(TxnParticipantTest, ThrowDuringOnTransactionPrepareAbortsTransaction) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
@@ -939,7 +947,7 @@ TEST_F(TxnParticipantTest, ThrowDuringOnTransactionPrepareAbortsTransaction) {
}
TEST_F(TxnParticipantTest, KillSessionsDuringPreparedCommitDoesNotAbortTransaction) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -971,7 +979,7 @@ TEST_F(TxnParticipantTest, KillSessionsDuringPreparedCommitDoesNotAbortTransacti
}
TEST_F(TxnParticipantTest, ArbitraryAbortDuringPreparedCommitDoesNotAbortTransaction) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -1006,7 +1014,7 @@ TEST_F(TxnParticipantTest, ArbitraryAbortDuringPreparedCommitDoesNotAbortTransac
DEATH_TEST_F(TxnParticipantTest,
ThrowDuringPreparedOnTransactionCommitIsFatal,
"Caught exception during commit") {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -1018,7 +1026,7 @@ DEATH_TEST_F(TxnParticipantTest,
}
TEST_F(TxnParticipantTest, ThrowDuringUnpreparedCommitLetsTheAbortAtEntryPointToCleanUp) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -1037,7 +1045,7 @@ TEST_F(TxnParticipantTest, ThrowDuringUnpreparedCommitLetsTheAbortAtEntryPointTo
}
TEST_F(TxnParticipantTest, ConcurrencyOfCommitUnpreparedTransactionAndMigration) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1056,7 +1064,7 @@ TEST_F(TxnParticipantTest, ConcurrencyOfCommitUnpreparedTransactionAndMigration)
}
TEST_F(TxnParticipantTest, ConcurrencyOfPrepareTransactionAndMigration) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1076,14 +1084,21 @@ TEST_F(TxnParticipantTest, ConcurrencyOfPrepareTransactionAndMigration) {
}
TEST_F(TxnParticipantTest, ContinuingATransactionWithNoResourcesAborts) {
- OperationContextSessionMongod(opCtx(), true, makeSessionInfo());
- ASSERT_THROWS_CODE(OperationContextSessionMongod(opCtx(), true, makeSessionInfo(false)),
- AssertionException,
- ErrorCodes::NoSuchTransaction);
+ // Check out a session, start the transaction and check it in.
+ checkOutSession();
+
+ // Check out the session again for a new operation.
+ OperationContextSessionMongod sessionCheckout(opCtx(), true, makeSessionInfo(false));
+ auto txnParticipant = TransactionParticipant::get(opCtx());
+
+ ASSERT_THROWS_CODE(
+ txnParticipant->beginOrContinue(*opCtx()->getTxnNumber(), false, boost::none),
+ AssertionException,
+ ErrorCodes::NoSuchTransaction);
}
TEST_F(TxnParticipantTest, KillSessionsDoesNotAbortPreparedTransactions) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1110,7 +1125,7 @@ TEST_F(TxnParticipantTest, KillSessionsDoesNotAbortPreparedTransactions) {
}
TEST_F(TxnParticipantTest, TransactionTimeoutDoesNotAbortPreparedTransactions) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1138,7 +1153,7 @@ TEST_F(TxnParticipantTest, TransactionTimeoutDoesNotAbortPreparedTransactions) {
}
TEST_F(TxnParticipantTest, CannotStartNewTransactionWhilePreparedTransactionInProgress) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1185,7 +1200,7 @@ TEST_F(TxnParticipantTest, CannotStartNewTransactionWhilePreparedTransactionInPr
}
TEST_F(TxnParticipantTest, CannotInsertInPreparedTransaction) {
- OperationContextSessionMongod outerScopedSession(opCtx(), true, makeSessionInfo());
+ auto outerScopedSession = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1203,7 +1218,7 @@ TEST_F(TxnParticipantTest, CannotInsertInPreparedTransaction) {
}
TEST_F(TxnParticipantTest, MigrationThrowsOnPreparedTransaction) {
- OperationContextSessionMongod outerScopedSession(opCtx(), true, makeSessionInfo());
+ auto outerScopedSession = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1223,7 +1238,7 @@ TEST_F(TxnParticipantTest, MigrationThrowsOnPreparedTransaction) {
}
TEST_F(TxnParticipantTest, ImplictAbortDoesNotAbortPreparedTransaction) {
- OperationContextSessionMongod outerScopedSession(opCtx(), true, makeSessionInfo());
+ auto outerScopedSession = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1240,7 +1255,7 @@ TEST_F(TxnParticipantTest, ImplictAbortDoesNotAbortPreparedTransaction) {
}
DEATH_TEST_F(TxnParticipantTest, AbortIsIllegalDuringCommittingPreparedTransaction, "invariant") {
- OperationContextSessionMongod outerScopedSession(opCtx(), true, makeSessionInfo());
+ auto outerScopedSession = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1274,14 +1289,17 @@ DEATH_TEST_F(TxnParticipantTest, AbortIsIllegalDuringCommittingPreparedTransacti
}
TEST_F(TxnParticipantTest, CannotContinueNonExistentTransaction) {
- ASSERT_THROWS_CODE(OperationContextSessionMongod(opCtx(), true, makeSessionInfo(false)),
- AssertionException,
- ErrorCodes::NoSuchTransaction);
+ OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo(false));
+ auto txnParticipant = TransactionParticipant::get(opCtx());
+ ASSERT_THROWS_CODE(
+ txnParticipant->beginOrContinue(*opCtx()->getTxnNumber(), false, boost::none),
+ AssertionException,
+ ErrorCodes::NoSuchTransaction);
}
// Tests that a transaction aborts if it becomes too large before trying to commit it.
TEST_F(TxnParticipantTest, TransactionTooLargeWhileBuilding) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1301,7 +1319,7 @@ TEST_F(TxnParticipantTest, TransactionTooLargeWhileBuilding) {
}
TEST_F(TxnParticipantTest, StashInNestedSessionIsANoop) {
- OperationContextSessionMongod outerScopedSession(opCtx(), true, makeSessionInfo());
+ auto outerScopedSession = checkOutSession();
Locker* originalLocker = opCtx()->lockState();
RecoveryUnit* originalRecoveryUnit = opCtx()->recoveryUnit();
ASSERT(originalLocker);
@@ -1340,7 +1358,7 @@ TEST_F(TxnParticipantTest, StashInNestedSessionIsANoop) {
TEST_F(TxnParticipantTest, UnstashInNestedSessionIsANoop) {
- OperationContextSessionMongod outerScopedSession(opCtx(), true, makeSessionInfo());
+ auto outerScopedSession = checkOutSession();
Locker* originalLocker = opCtx()->lockState();
RecoveryUnit* originalRecoveryUnit = opCtx()->recoveryUnit();
@@ -1383,8 +1401,7 @@ protected:
void canSpecifyStartTransactionOnInProgressTxn() {
auto autocommit = false;
auto startTransaction = true;
- OperationContextSessionMongod opCtxSession(
- opCtx(), true /* shouldCheckOutSession */, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT(txnParticipant->inMultiDocumentTransaction());
@@ -1396,8 +1413,7 @@ protected:
void canSpecifyStartTransactionOnAbortedTxn() {
auto autocommit = false;
auto startTransaction = true;
- OperationContextSessionMongod opCtxSession(
- opCtx(), true /* shouldCheckOutSession */, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT(txnParticipant->inMultiDocumentTransaction());
@@ -1412,8 +1428,7 @@ protected:
void cannotSpecifyStartTransactionOnCommittedTxn() {
auto autocommit = false;
auto startTransaction = true;
- OperationContextSessionMongod opCtxSession(
- opCtx(), true /* shouldCheckOutSession */, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT(txnParticipant->inMultiDocumentTransaction());
@@ -1430,8 +1445,7 @@ protected:
void cannotSpecifyStartTransactionOnPreparedTxn() {
auto autocommit = false;
auto startTransaction = true;
- OperationContextSessionMongod opCtxSession(
- opCtx(), true /* shouldCheckOutSession */, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
ASSERT(txnParticipant->inMultiDocumentTransaction());
@@ -1448,9 +1462,10 @@ protected:
}
void cannotSpecifyStartTransactionOnStartedRetryableWrite() {
- OperationContextSessionMongod opCtxSession(opCtx(), true /* shouldCheckOutSession */, {});
+ OperationContextSessionMongod opCtxSession(opCtx(), true, {});
auto txnParticipant = TransactionParticipant::get(opCtx());
+ txnParticipant->beginOrContinue(*opCtx()->getTxnNumber(), boost::none, boost::none);
ASSERT_FALSE(txnParticipant->inMultiDocumentTransaction());
auto autocommit = false;
@@ -1539,7 +1554,7 @@ TEST_F(ConfigTxnParticipantTest, CannotSpecifyStartTransactionOnStartedRetryable
}
TEST_F(TxnParticipantTest, KillSessionsDuringUnpreparedAbortSucceeds) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "abortTransaction");
@@ -1559,7 +1574,7 @@ TEST_F(TxnParticipantTest, KillSessionsDuringUnpreparedAbortSucceeds) {
}
TEST_F(TxnParticipantTest, ActiveAbortIsLegalDuringUnpreparedAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "abortTransaction");
@@ -1587,7 +1602,7 @@ TEST_F(TxnParticipantTest, ActiveAbortIsLegalDuringUnpreparedAbort) {
}
TEST_F(TxnParticipantTest, ThrowDuringUnpreparedOnTransactionAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "abortTransaction");
@@ -1599,7 +1614,7 @@ TEST_F(TxnParticipantTest, ThrowDuringUnpreparedOnTransactionAbort) {
}
TEST_F(TxnParticipantTest, KillSessionsDuringPreparedAbortFails) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "abortTransaction");
txnParticipant->prepareTransaction(opCtx(), {});
@@ -1621,7 +1636,7 @@ TEST_F(TxnParticipantTest, KillSessionsDuringPreparedAbortFails) {
}
TEST_F(TxnParticipantTest, ActiveAbortSucceedsDuringPreparedAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "abortTransaction");
txnParticipant->prepareTransaction(opCtx(), {});
@@ -1650,7 +1665,7 @@ TEST_F(TxnParticipantTest, ActiveAbortSucceedsDuringPreparedAbort) {
}
TEST_F(TxnParticipantTest, ThrowDuringPreparedOnTransactionAbortIsFatal) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "abortTransaction");
txnParticipant->prepareTransaction(opCtx(), {});
@@ -1695,7 +1710,7 @@ TEST_F(TransactionsMetricsTest, IncrementTotalStartedUponStartTransaction) {
unsigned long long beforeTransactionStart =
ServerTransactionsMetrics::get(opCtx())->getTotalStarted();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
// Tests that the total transactions started counter is incremented by 1 when a new transaction
// is started.
@@ -1704,7 +1719,7 @@ TEST_F(TransactionsMetricsTest, IncrementTotalStartedUponStartTransaction) {
}
TEST_F(TransactionsMetricsTest, IncrementPreparedTransaction) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
unsigned long long beforePrepareCount =
ServerTransactionsMetrics::get(opCtx())->getTotalPrepared();
@@ -1715,7 +1730,7 @@ TEST_F(TransactionsMetricsTest, IncrementPreparedTransaction) {
}
TEST_F(TransactionsMetricsTest, IncrementTotalCommittedOnCommit) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
@@ -1729,7 +1744,7 @@ TEST_F(TransactionsMetricsTest, IncrementTotalCommittedOnCommit) {
}
TEST_F(TransactionsMetricsTest, IncrementTotalPreparedThenCommitted) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
const auto prepareTimestamp = txnParticipant->prepareTransaction(opCtx(), {});
@@ -1748,7 +1763,7 @@ TEST_F(TransactionsMetricsTest, IncrementTotalPreparedThenCommitted) {
TEST_F(TransactionsMetricsTest, IncrementTotalAbortedUponAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -1765,7 +1780,7 @@ TEST_F(TransactionsMetricsTest, IncrementTotalPreparedThenAborted) {
unsigned long long beforePreparedThenAbortedCount =
ServerTransactionsMetrics::get(opCtx())->getTotalPreparedThenAborted();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "prepareTransaction");
txnParticipant->prepareTransaction(opCtx(), {});
@@ -1780,7 +1795,7 @@ TEST_F(TransactionsMetricsTest, IncrementCurrentPreparedWithCommit) {
unsigned long long beforeCurrentPrepared =
ServerTransactionsMetrics::get(opCtx())->getCurrentPrepared();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
const auto prepareTimestamp = txnParticipant->prepareTransaction(opCtx(), {});
@@ -1798,7 +1813,7 @@ TEST_F(TransactionsMetricsTest, IncrementCurrentPreparedWithAbort) {
unsigned long long beforeCurrentPrepared =
ServerTransactionsMetrics::get(opCtx())->getCurrentPrepared();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "abortTransaction");
txnParticipant->prepareTransaction(opCtx(), {});
@@ -1815,7 +1830,7 @@ TEST_F(TransactionsMetricsTest, TrackTotalOpenTransactionsWithAbort) {
ServerTransactionsMetrics::get(opCtx())->getCurrentOpen();
// Tests that starting a transaction increments the open transactions counter by 1.
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
ASSERT_EQ(ServerTransactionsMetrics::get(opCtx())->getCurrentOpen(),
@@ -1837,7 +1852,7 @@ TEST_F(TransactionsMetricsTest, TrackTotalOpenTransactionsWithCommit) {
ServerTransactionsMetrics::get(opCtx())->getCurrentOpen();
// Tests that starting a transaction increments the open transactions counter by 1.
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
ASSERT_EQ(ServerTransactionsMetrics::get(opCtx())->getCurrentOpen(),
@@ -1863,7 +1878,7 @@ TEST_F(TransactionsMetricsTest, TrackTotalActiveAndInactiveTransactionsWithCommi
ServerTransactionsMetrics::get(opCtx())->getCurrentInactive();
// Starting the transaction should put it into an inactive state.
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
ASSERT_EQ(ServerTransactionsMetrics::get(opCtx())->getCurrentInactive(),
beforeInactiveCounter + 1);
@@ -1903,7 +1918,7 @@ TEST_F(TransactionsMetricsTest, TrackTotalActiveAndInactiveTransactionsWithStash
ServerTransactionsMetrics::get(opCtx())->getCurrentInactive();
// Starting the transaction should put it into an inactive state.
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
ASSERT_EQ(ServerTransactionsMetrics::get(opCtx())->getCurrentInactive(),
beforeInactiveCounter + 1);
@@ -1936,7 +1951,7 @@ TEST_F(TransactionsMetricsTest, TrackTotalActiveAndInactiveTransactionsWithUnsta
ServerTransactionsMetrics::get(opCtx())->getCurrentInactive();
// Starting the transaction should put it into an inactive state.
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
ASSERT_EQ(ServerTransactionsMetrics::get(opCtx())->getCurrentInactive(),
beforeInactiveCounter + 1);
@@ -1959,7 +1974,7 @@ TEST_F(TransactionsMetricsTest, TrackCurrentActiveAndInactivePreparedTransaction
ServerTransactionsMetrics::get(opCtx())->getCurrentActive();
unsigned long long beforeInactivePreparedCounter =
ServerTransactionsMetrics::get(opCtx())->getCurrentInactive();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
unsigned long long beforePrepareCount =
ServerTransactionsMetrics::get(opCtx())->getTotalPrepared();
unsigned long long beforePreparedThenCommittedCount =
@@ -2008,7 +2023,7 @@ TEST_F(TransactionsMetricsTest,
ServerTransactionsMetrics::get(opCtx())->getCurrentActive();
unsigned long long beforeInactivePreparedCounter =
ServerTransactionsMetrics::get(opCtx())->getCurrentInactive();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
@@ -2045,7 +2060,7 @@ TEST_F(TransactionsMetricsTest,
TEST_F(TransactionsMetricsTest, SingleTransactionStatsDurationShouldBeSetUponCommit) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
// The transaction machinery cannot store an empty locker.
@@ -2063,7 +2078,7 @@ TEST_F(TransactionsMetricsTest, SingleTransactionStatsDurationShouldBeSetUponCom
TEST_F(TransactionsMetricsTest, SingleTranasactionStatsPreparedDurationShouldBeSetUponCommit) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
// The transaction machinery cannot store an empty locker.
@@ -2088,7 +2103,7 @@ TEST_F(TransactionsMetricsTest, SingleTranasactionStatsPreparedDurationShouldBeS
TEST_F(TransactionsMetricsTest, SingleTransactionStatsDurationShouldBeSetUponAbort) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
@@ -2104,7 +2119,7 @@ TEST_F(TransactionsMetricsTest, SingleTransactionStatsDurationShouldBeSetUponAbo
TEST_F(TransactionsMetricsTest, SingleTransactionStatsPreparedDurationShouldBeSetUponAbort) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "abortTransaction");
@@ -2124,7 +2139,7 @@ TEST_F(TransactionsMetricsTest, SingleTransactionStatsPreparedDurationShouldBeSe
TEST_F(TransactionsMetricsTest, SingleTransactionStatsDurationShouldKeepIncreasingUntilCommit) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
// The transaction machinery cannot store an empty locker.
@@ -2156,7 +2171,7 @@ TEST_F(TransactionsMetricsTest,
SingleTransactionStatsPreparedDurationShouldKeepIncreasingUntilCommit) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "commitTransaction");
// The transaction machinery cannot store an empty locker.
@@ -2193,7 +2208,7 @@ TEST_F(TransactionsMetricsTest,
TEST_F(TransactionsMetricsTest, SingleTransactionStatsDurationShouldKeepIncreasingUntilAbort) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
// The transaction machinery cannot store an empty locker.
@@ -2225,7 +2240,7 @@ TEST_F(TransactionsMetricsTest,
SingleTransactionStatsPreparedDurationShouldKeepIncreasingUntilAbort) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "abortTransaction");
// The transaction machinery cannot store an empty locker.
@@ -2259,7 +2274,7 @@ TEST_F(TransactionsMetricsTest,
TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldBeSetUponUnstashAndStash) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Time active should be zero.
@@ -2306,7 +2321,7 @@ TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldBeSetUponUnstashAndStash)
TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldBeSetUponUnstashAndAbort) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Time active should be zero.
@@ -2334,7 +2349,7 @@ TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldBeSetUponUnstashAndAbort)
TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldNotBeSetUponAbortOnly) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Time active should be zero.
@@ -2356,7 +2371,7 @@ TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldNotBeSetUponAbortOnly) {
TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldIncreaseUntilStash) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Time active should be zero.
@@ -2393,7 +2408,7 @@ TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldIncreaseUntilStash) {
TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldIncreaseUntilCommit) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Time active should be zero.
@@ -2429,7 +2444,7 @@ TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldIncreaseUntilCommit) {
TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldNotBeSetIfUnstashHasBadReadConcernArgs) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Initialize bad read concern args (!readConcernArgs.isEmpty()).
@@ -2465,7 +2480,7 @@ TEST_F(TransactionsMetricsTest, TimeActiveMicrosShouldNotBeSetIfUnstashHasBadRea
}
TEST_F(TransactionsMetricsTest, AdditiveMetricsObjectsShouldBeAddedTogetherUponStash) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Initialize field values for both AdditiveMetrics objects.
@@ -2501,7 +2516,7 @@ TEST_F(TransactionsMetricsTest, AdditiveMetricsObjectsShouldBeAddedTogetherUponS
}
TEST_F(TransactionsMetricsTest, AdditiveMetricsObjectsShouldBeAddedTogetherUponCommit) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Initialize field values for both AdditiveMetrics objects.
@@ -2537,7 +2552,7 @@ TEST_F(TransactionsMetricsTest, AdditiveMetricsObjectsShouldBeAddedTogetherUponC
}
TEST_F(TransactionsMetricsTest, AdditiveMetricsObjectsShouldBeAddedTogetherUponAbort) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Initialize field values for both AdditiveMetrics objects.
@@ -2574,7 +2589,7 @@ TEST_F(TransactionsMetricsTest, AdditiveMetricsObjectsShouldBeAddedTogetherUponA
TEST_F(TransactionsMetricsTest, TimeInactiveMicrosShouldBeSetUponUnstashAndStash) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Time inactive should have increased.
@@ -2613,7 +2628,7 @@ TEST_F(TransactionsMetricsTest, TimeInactiveMicrosShouldBeSetUponUnstashAndStash
TEST_F(TransactionsMetricsTest, TimeInactiveMicrosShouldBeSetUponUnstashAndAbort) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Time inactive should be greater than or equal to zero.
@@ -2646,7 +2661,7 @@ TEST_F(TransactionsMetricsTest, TimeInactiveMicrosShouldBeSetUponUnstashAndAbort
TEST_F(TransactionsMetricsTest, TimeInactiveMicrosShouldIncreaseUntilCommit) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Time inactive should be greater than or equal to zero.
@@ -2686,7 +2701,7 @@ TEST_F(TransactionsMetricsTest, ReportStashedResources) {
ASSERT(opCtx()->lockState());
ASSERT(opCtx()->recoveryUnit());
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
// Create a ClientMetadata object and set it on ClientMetadataIsMasterState.
BSONObjBuilder builder;
@@ -2792,7 +2807,7 @@ TEST_F(TransactionsMetricsTest, ReportUnstashedResources) {
ASSERT(opCtx()->recoveryUnit());
const auto autocommit = false;
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -2857,6 +2872,7 @@ TEST_F(TransactionsMetricsTest, ReportUnstashedResourcesForARetryableWrite) {
OperationContextSessionMongod opCtxSession(opCtx(), true, {});
auto txnParticipant = TransactionParticipant::get(opCtx());
+ txnParticipant->beginOrContinue(*opCtx()->getTxnNumber(), boost::none, boost::none);
txnParticipant->unstashTransactionResources(opCtx(), "find");
// Build a BSONObj containing the details which we expect to see reported when we call
@@ -2901,7 +2917,7 @@ TEST_F(TransactionsMetricsTest, LastClientInfoShouldUpdateUponStash) {
clientMetadataIsMasterState.setClientMetadata(opCtx()->getClient(),
std::move(clientMetadata.getValue()));
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
// The transaction machinery cannot store an empty locker.
@@ -2938,7 +2954,7 @@ TEST_F(TransactionsMetricsTest, LastClientInfoShouldUpdateUponCommit) {
clientMetadataIsMasterState.setClientMetadata(opCtx()->getClient(),
std::move(clientMetadata.getValue()));
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
// The transaction machinery cannot store an empty locker.
@@ -2962,7 +2978,7 @@ TEST_F(TransactionsMetricsTest, LastClientInfoShouldUpdateUponAbort) {
clientMetadataIsMasterState.setClientMetadata(opCtx()->getClient(),
std::move(clientMetadata.getValue()));
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant->unstashTransactionResources(opCtx(), "insert");
txnParticipant->abortActiveTransaction(opCtx());
@@ -3122,7 +3138,7 @@ TEST_F(TransactionsMetricsTest, TestTransactionInfoForLogAfterCommit) {
const int metricValue = 1;
setupAdditiveMetrics(metricValue, opCtx());
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -3162,7 +3178,7 @@ TEST_F(TransactionsMetricsTest, TestPreparedTransactionInfoForLogAfterCommit) {
const int metricValue = 1;
setupAdditiveMetrics(metricValue, opCtx());
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -3206,7 +3222,7 @@ TEST_F(TransactionsMetricsTest, TestTransactionInfoForLogAfterAbort) {
const int metricValue = 1;
setupAdditiveMetrics(metricValue, opCtx());
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -3246,7 +3262,7 @@ TEST_F(TransactionsMetricsTest, TestPreparedTransactionInfoForLogAfterAbort) {
const int metricValue = 1;
setupAdditiveMetrics(metricValue, opCtx());
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -3283,7 +3299,7 @@ TEST_F(TransactionsMetricsTest, TestPreparedTransactionInfoForLogAfterAbort) {
}
DEATH_TEST_F(TransactionsMetricsTest, TestTransactionInfoForLogWithNoLockerInfoStats, "invariant") {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -3307,7 +3323,7 @@ DEATH_TEST_F(TransactionsMetricsTest, TestTransactionInfoForLogWithNoLockerInfoS
TEST_F(TransactionsMetricsTest, LogTransactionInfoAfterSlowCommit) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -3343,7 +3359,7 @@ TEST_F(TransactionsMetricsTest, LogTransactionInfoAfterSlowCommit) {
TEST_F(TransactionsMetricsTest, LogPreparedTransactionInfoAfterSlowCommit) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -3382,7 +3398,7 @@ TEST_F(TransactionsMetricsTest, LogPreparedTransactionInfoAfterSlowCommit) {
TEST_F(TransactionsMetricsTest, LogTransactionInfoAfterSlowAbort) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -3418,7 +3434,7 @@ TEST_F(TransactionsMetricsTest, LogTransactionInfoAfterSlowAbort) {
TEST_F(TransactionsMetricsTest, LogPreparedTransactionInfoAfterSlowAbort) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -3455,7 +3471,7 @@ TEST_F(TransactionsMetricsTest, LogPreparedTransactionInfoAfterSlowAbort) {
TEST_F(TransactionsMetricsTest, LogTransactionInfoAfterSlowStashedAbort) {
auto tickSource = initMockTickSource();
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
repl::ReadConcernArgs readConcernArgs;
ASSERT_OK(readConcernArgs.initialize(BSON("find"
@@ -3494,7 +3510,7 @@ TEST_F(TransactionsMetricsTest, LogTransactionInfoAfterSlowStashedAbort) {
}
TEST_F(TxnParticipantTest, WhenOldestTSRemovedNextOldestBecomesNewOldest) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Check that there are no Timestamps in the set.
@@ -3532,6 +3548,7 @@ TEST_F(TxnParticipantTest, WhenOldestTSRemovedNextOldestBecomesNewOldest) {
OperationContextSessionMongod newOpCtxSession(newOpCtx.get(), true, makeSessionInfo());
auto newTxnParticipant = TransactionParticipant::get(newOpCtx.get());
+ newTxnParticipant->beginOrContinue(newTxnNum, false, true);
newTxnParticipant->unstashTransactionResources(newOpCtx.get(), "prepareTransaction");
// secondPrepareTimestamp should be greater than firstPreparedTimestamp because this
@@ -3560,7 +3577,7 @@ TEST_F(TxnParticipantTest, WhenOldestTSRemovedNextOldestBecomesNewOldest) {
}
TEST_F(TxnParticipantTest, ReturnNullTimestampIfNoOldestActiveTimestamp) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Check that there are no Timestamps in the set.
@@ -3593,6 +3610,7 @@ TEST_F(TxnParticipantTest, ReturnNullTimestampIfNoOldestActiveTimestamp) {
OperationContextSessionMongod newOpCtxSession(newOpCtx.get(), true, makeSessionInfo());
auto newTxnParticipant = TransactionParticipant::get(newOpCtx.get());
+ newTxnParticipant->beginOrContinue(newTxnNum, false, true);
newTxnParticipant->unstashTransactionResources(newOpCtx.get(), "prepareTransaction");
// secondPrepareTimestamp should be greater than firstPreparedTimestamp because this
@@ -3622,7 +3640,7 @@ TEST_F(TxnParticipantTest, ReturnNullTimestampIfNoOldestActiveTimestamp) {
}
TEST_F(TxnParticipantTest, ProperlyMaintainOldestNonMajorityCommittedOpTimeSet) {
- OperationContextSessionMongod opCtxSession(opCtx(), true, makeSessionInfo());
+ auto sessionCheckout = checkOutSession();
auto txnParticipant = TransactionParticipant::get(opCtx());
// Check that there are no Timestamps in the set.