summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisha Tyulenev <misha@mongodb.com>2019-03-20 17:01:32 -0400
committerMisha Tyulenev <misha@mongodb.com>2019-03-20 17:01:32 -0400
commit1144316212453346cb17ae0992542b192755ae04 (patch)
tree098f8412431dfa1bd2e48677a5ec31edb42a3c3b
parent2f9c6b9a80c8d86cdc68be3a421e44b45dfd03d0 (diff)
downloadmongo-1144316212453346cb17ae0992542b192755ae04.tar.gz
SERVER-39932 do not checkout session if retriable writes are not used
-rw-r--r--src/mongo/db/service_entry_point_mongod.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp
index ec8bc6e75ae..128c3ff3368 100644
--- a/src/mongo/db/service_entry_point_mongod.cpp
+++ b/src/mongo/db/service_entry_point_mongod.cpp
@@ -633,9 +633,11 @@ void execCommandDatabase(OperationContext* opCtx,
// Session ids are forwarded in requests, so commands that require roundtrips between
// servers may result in a deadlock when a server tries to check out a session it is already
// using to service an earlier operation in the command's chain. To avoid this, only check
- // out sessions for commands that require them (i.e. write commands).
- OperationContextSession sessionTxnState(
- opCtx, cmdWhitelist.find(command->getName()) != cmdWhitelist.cend());
+ // out sessions with provided txnNumber for commands that require them (i.e. write
+ // commands).
+ bool checkoutSession =
+ opCtx->getTxnNumber() && (cmdWhitelist.find(command->getName()) != cmdWhitelist.cend());
+ OperationContextSession sessionTxnState(opCtx, checkoutSession);
ImpersonationSessionGuard guard(opCtx);
uassertStatusOK(Command::checkAuthorization(command, opCtx, request));