summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2018-09-12 15:42:45 -0400
committerSpencer T Brody <spencer@mongodb.com>2018-09-13 12:50:20 -0400
commitacc2f4f010aee30505c0fab0c46d5faee84390d9 (patch)
treeccc6fd153bfa38d77c6fe916da899345319cff2e
parent63868859a3213eae8e749c1f361eaac813083f59 (diff)
downloadmongo-acc2f4f010aee30505c0fab0c46d5faee84390d9.tar.gz
SERVER-37105 Make it clear from the stack trace whether a command is running in a transaction
-rw-r--r--src/mongo/db/service_entry_point_common.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp
index a8f0723ea35..956d4d5865b 100644
--- a/src/mongo/db/service_entry_point_common.cpp
+++ b/src/mongo/db/service_entry_point_common.cpp
@@ -444,14 +444,8 @@ void appendClusterAndOperationTime(OperationContext* opCtx,
void invokeInTransaction(OperationContext* opCtx,
CommandInvocation* invocation,
+ TransactionParticipant* txnParticipant,
rpc::ReplyBuilderInterface* replyBuilder) {
- auto txnParticipant = TransactionParticipant::get(opCtx);
- if (!txnParticipant) {
- // Run the command directly if we're not in a transaction.
- invocation->run(opCtx, replyBuilder);
- return;
- }
-
txnParticipant->unstashTransactionResources(opCtx, invocation->definition()->getName());
ScopeGuard guard = MakeGuard([&txnParticipant, opCtx]() {
txnParticipant->abortActiveUnpreparedOrStashPreparedTransaction(opCtx);
@@ -490,12 +484,16 @@ bool runCommandImpl(OperationContext* opCtx,
#endif
replyBuilder->reserveBytes(bytesToReserve);
+ auto txnParticipant = TransactionParticipant::get(opCtx);
if (!invocation->supportsWriteConcern()) {
behaviors.uassertCommandDoesNotSpecifyWriteConcern(request.body);
- invokeInTransaction(opCtx, invocation, replyBuilder);
+ if (txnParticipant) {
+ invokeInTransaction(opCtx, invocation, txnParticipant, replyBuilder);
+ } else {
+ invocation->run(opCtx, replyBuilder);
+ }
} else {
auto wcResult = uassertStatusOK(extractWriteConcern(opCtx, request.body));
- auto txnParticipant = TransactionParticipant::get(opCtx);
uassert(ErrorCodes::InvalidOptions,
"writeConcern is not allowed within a multi-statement transaction",
wcResult.usedDefault || !txnParticipant ||
@@ -525,7 +523,11 @@ bool runCommandImpl(OperationContext* opCtx,
};
try {
- invokeInTransaction(opCtx, invocation, replyBuilder);
+ if (txnParticipant) {
+ invokeInTransaction(opCtx, invocation, txnParticipant, replyBuilder);
+ } else {
+ invocation->run(opCtx, replyBuilder);
+ }
} catch (const DBException&) {
waitForWriteConcern(*extraFieldsBuilder);
throw;