diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2018-10-10 21:10:05 -0400 |
---|---|---|
committer | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2018-10-24 20:19:20 -0400 |
commit | 248601a6473fc7364e5d790a357acbace2a42f7a (patch) | |
tree | ca3b954d14757df9c41802038ff9086c6ab66037 /src/mongo/db/initialize_operation_session_info.cpp | |
parent | 887cc3f6db2a15d94e8ae2195d8183f16337d926 (diff) | |
download | mongo-248601a6473fc7364e5d790a357acbace2a42f7a.tar.gz |
SERVER-37179 Pass the reference of OperationSessionInfoFromClient around.
Diffstat (limited to 'src/mongo/db/initialize_operation_session_info.cpp')
-rw-r--r-- | src/mongo/db/initialize_operation_session_info.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/mongo/db/initialize_operation_session_info.cpp b/src/mongo/db/initialize_operation_session_info.cpp index a7f4b003499..e513126f173 100644 --- a/src/mongo/db/initialize_operation_session_info.cpp +++ b/src/mongo/db/initialize_operation_session_info.cpp @@ -40,12 +40,11 @@ namespace mongo { -boost::optional<OperationSessionInfoFromClient> initializeOperationSessionInfo( - OperationContext* opCtx, - const BSONObj& requestBody, - bool requiresAuth, - bool isReplSetMemberOrMongos, - bool supportsDocLocking) { +OperationSessionInfoFromClient initializeOperationSessionInfo(OperationContext* opCtx, + const BSONObj& requestBody, + bool requiresAuth, + bool isReplSetMemberOrMongos, + bool supportsDocLocking) { auto osi = OperationSessionInfoFromClient::parse("OperationSessionInfo"_sd, requestBody); if (opCtx->getClient()->isInDirectClient()) { @@ -61,7 +60,7 @@ boost::optional<OperationSessionInfoFromClient> initializeOperationSessionInfo( !osi.getAutocommit()); uassert( 50889, "It is illegal to provide a txnNumber for this command", !osi.getTxnNumber()); - return boost::none; + return {}; } { @@ -71,7 +70,7 @@ boost::optional<OperationSessionInfoFromClient> initializeOperationSessionInfo( AuthorizationSession* authSession = AuthorizationSession::get(opCtx->getClient()); if (authSession && authSession->isUsingLocalhostBypass() && !authSession->isAuthenticated()) { - return boost::none; + return {}; } } @@ -82,7 +81,7 @@ boost::optional<OperationSessionInfoFromClient> initializeOperationSessionInfo( if (!lsc) { // Ignore session information if the logical session cache has not been set up, e.g. on // the embedded version of mongod. - return boost::none; + return {}; } opCtx->setLogicalSessionId(makeLogicalSessionId(osi.getSessionId().get(), opCtx)); @@ -133,6 +132,22 @@ boost::optional<OperationSessionInfoFromClient> initializeOperationSessionInfo( osi.getStartTransaction().value()); } + // Populate the session info for doTxn command. + if (requestBody.firstElementFieldName() == "doTxn"_sd) { + uassert(ErrorCodes::InvalidOptions, + "doTxn can only be run with a transaction number.", + osi.getTxnNumber()); + uassert(ErrorCodes::OperationNotSupportedInTransaction, + "doTxn can not be run in a transaction", + !osi.getAutocommit()); + // 'autocommit' and 'startTransaction' are populated for 'doTxn' to get the oplog + // entry generation behavior used for multi-document transactions. The 'doTxn' + // command still logically behaves as a commit. + osi.setAutocommit(false); + osi.setStartTransaction(true); + } + + return osi; } |