summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops/write_ops_exec.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/ops/write_ops_exec.cpp')
-rw-r--r--src/mongo/db/ops/write_ops_exec.cpp37
1 files changed, 12 insertions, 25 deletions
diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp
index f5b9791cf00..d648e60239f 100644
--- a/src/mongo/db/ops/write_ops_exec.cpp
+++ b/src/mongo/db/ops/write_ops_exec.cpp
@@ -202,8 +202,7 @@ void assertCanWrite_inlock(OperationContext* opCtx, const NamespaceString& ns, b
}
void makeCollection(OperationContext* opCtx, const NamespaceString& ns) {
- auto txnParticipant = TransactionParticipant::get(opCtx);
- auto inTransaction = txnParticipant && txnParticipant.inMultiDocumentTransaction();
+ auto inTransaction = opCtx->inMultiDocumentTransaction();
uassert(ErrorCodes::OperationNotSupportedInTransaction,
str::stream() << "Cannot create namespace " << ns.ns()
<< " in multi-document transaction.",
@@ -303,8 +302,7 @@ void insertDocuments(OperationContext* opCtx,
auto batchSize = std::distance(begin, end);
if (supportsDocLocking()) {
auto replCoord = repl::ReplicationCoordinator::get(opCtx);
- auto txnParticipant = TransactionParticipant::get(opCtx);
- auto inTransaction = txnParticipant && txnParticipant.inMultiDocumentTransaction();
+ auto inTransaction = opCtx->inMultiDocumentTransaction();
if (!inTransaction && !replCoord->isOplogDisabledFor(opCtx, collection->ns())) {
// Populate 'slots' with new optimes for each insert.
@@ -334,8 +332,7 @@ void insertDocuments(OperationContext* opCtx,
* collection lock, which we cannot hold in transactions.
*/
Status checkIfTransactionOnCappedColl(OperationContext* opCtx, Collection* collection) {
- auto txnParticipant = TransactionParticipant::get(opCtx);
- if (txnParticipant && txnParticipant.inMultiDocumentTransaction() && collection->isCapped()) {
+ if (opCtx->inMultiDocumentTransaction() && collection->isCapped()) {
return {ErrorCodes::OperationNotSupportedInTransaction,
str::stream() << "Collection '" << collection->ns()
<< "' is a capped collection. Writes in transactions are not allowed "
@@ -543,7 +540,7 @@ WriteResult performInserts(OperationContext* opCtx,
} else {
const auto stmtId = getStmtIdForWriteOp(opCtx, wholeOp, stmtIdIndex++);
if (opCtx->getTxnNumber()) {
- if (!txnParticipant.inMultiDocumentTransaction() &&
+ if (!opCtx->inMultiDocumentTransaction() &&
txnParticipant.checkStatementExecutedNoOplogEntryFetch(stmtId)) {
containsRetry = true;
RetryableWritesStats::get(opCtx)->incrementRetriedStatementsCount();
@@ -696,11 +693,9 @@ static SingleWriteResult performSingleUpdateOpWithDupKeyRetry(OperationContext*
curOp.ensureStarted();
}
- auto txnParticipant = TransactionParticipant::get(opCtx);
uassert(ErrorCodes::InvalidOptions,
"Cannot use (or request) retryable writes with multi=true",
- (txnParticipant && txnParticipant.inMultiDocumentTransaction()) ||
- !opCtx->getTxnNumber() || !op.getMulti());
+ opCtx->inMultiDocumentTransaction() || !opCtx->getTxnNumber() || !op.getMulti());
UpdateRequest request(ns);
request.setQuery(op.getQ());
@@ -714,11 +709,8 @@ static SingleWriteResult performSingleUpdateOpWithDupKeyRetry(OperationContext*
request.setUpsert(op.getUpsert());
request.setHint(op.getHint());
- auto readConcernArgs = repl::ReadConcernArgs::get(opCtx);
- request.setYieldPolicy(readConcernArgs.getLevel() ==
- repl::ReadConcernLevel::kSnapshotReadConcern
- ? PlanExecutor::INTERRUPT_ONLY
- : PlanExecutor::YIELD_AUTO);
+ request.setYieldPolicy(opCtx->inMultiDocumentTransaction() ? PlanExecutor::INTERRUPT_ONLY
+ : PlanExecutor::YIELD_AUTO);
size_t numAttempts = 0;
while (true) {
@@ -779,7 +771,7 @@ WriteResult performUpdates(OperationContext* opCtx, const write_ops::Update& who
for (auto&& singleOp : wholeOp.getUpdates()) {
const auto stmtId = getStmtIdForWriteOp(opCtx, wholeOp, stmtIdIndex++);
if (opCtx->getTxnNumber()) {
- if (!txnParticipant.inMultiDocumentTransaction()) {
+ if (!opCtx->inMultiDocumentTransaction()) {
if (auto entry = txnParticipant.checkStatementExecuted(opCtx, stmtId)) {
containsRetry = true;
RetryableWritesStats::get(opCtx)->incrementRetriedStatementsCount();
@@ -819,11 +811,9 @@ static SingleWriteResult performSingleDeleteOp(OperationContext* opCtx,
const NamespaceString& ns,
StmtId stmtId,
const write_ops::DeleteOpEntry& op) {
- auto txnParticipant = TransactionParticipant::get(opCtx);
uassert(ErrorCodes::InvalidOptions,
"Cannot use (or request) retryable writes with limit=0",
- (txnParticipant && txnParticipant.inMultiDocumentTransaction()) ||
- !opCtx->getTxnNumber() || !op.getMulti());
+ opCtx->inMultiDocumentTransaction() || !opCtx->getTxnNumber() || !op.getMulti());
globalOpCounters.gotDelete();
ServerWriteConcernMetrics::get(opCtx)->recordWriteConcernForDelete(opCtx->getWriteConcern());
@@ -841,11 +831,8 @@ static SingleWriteResult performSingleDeleteOp(OperationContext* opCtx,
request.setQuery(op.getQ());
request.setCollation(write_ops::collationOf(op));
request.setMulti(op.getMulti());
- auto readConcernArgs = repl::ReadConcernArgs::get(opCtx);
- request.setYieldPolicy(readConcernArgs.getLevel() ==
- repl::ReadConcernLevel::kSnapshotReadConcern
- ? PlanExecutor::INTERRUPT_ONLY
- : PlanExecutor::YIELD_AUTO);
+ request.setYieldPolicy(opCtx->inMultiDocumentTransaction() ? PlanExecutor::INTERRUPT_ONLY
+ : PlanExecutor::YIELD_AUTO);
request.setStmtId(stmtId);
ParsedDelete parsedDelete(opCtx, &request);
@@ -930,7 +917,7 @@ WriteResult performDeletes(OperationContext* opCtx, const write_ops::Delete& who
for (auto&& singleOp : wholeOp.getDeletes()) {
const auto stmtId = getStmtIdForWriteOp(opCtx, wholeOp, stmtIdIndex++);
if (opCtx->getTxnNumber()) {
- if (!txnParticipant.inMultiDocumentTransaction() &&
+ if (!opCtx->inMultiDocumentTransaction() &&
txnParticipant.checkStatementExecutedNoOplogEntryFetch(stmtId)) {
containsRetry = true;
RetryableWritesStats::get(opCtx)->incrementRetriedStatementsCount();