diff options
author | Sanika Phanse <sanika.phanse@mongodb.com> | 2022-03-18 21:40:06 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-18 22:45:37 +0000 |
commit | 8da816728d4cb62d4da80e8e3be360f22d0579a7 (patch) | |
tree | df1e60ffeffd0cc47f6c45e7dea059b47ce90734 /src/mongo/db/transaction_api.cpp | |
parent | 7d928fd2c25088c8f45ca6f5fbc9e6f92937fb26 (diff) | |
download | mongo-8da816728d4cb62d4da80e8e3be360f22d0579a7.tar.gz |
SERVER-61783 Use the session pool with the internal transaction API
Diffstat (limited to 'src/mongo/db/transaction_api.cpp')
-rw-r--r-- | src/mongo/db/transaction_api.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/mongo/db/transaction_api.cpp b/src/mongo/db/transaction_api.cpp index fccf1e0b6ab..c4e9cf28d4c 100644 --- a/src/mongo/db/transaction_api.cpp +++ b/src/mongo/db/transaction_api.cpp @@ -37,6 +37,7 @@ #include "mongo/db/client.h" #include "mongo/db/commands/txn_cmds_gen.h" #include "mongo/db/error_labels.h" +#include "mongo/db/internal_session_pool.h" #include "mongo/db/logical_session_id_helpers.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" @@ -569,14 +570,21 @@ void Transaction::_primeTransaction(OperationContext* opCtx) { auto clientInMultiDocumentTransaction = opCtx->inMultiDocumentTransaction(); if (!clientSession) { - // TODO SERVER-61783: Integrate session pool. - _setSessionInfo( - lg, makeLogicalSessionId(opCtx), 0 /* txnNumber */, {true} /* startTransaction */); + const auto acquiredSession = + InternalSessionPool::get(opCtx)->acquireStandaloneSession(opCtx); + _acquiredSessionFromPool = true; + _setSessionInfo(lg, + acquiredSession.getSessionId(), + acquiredSession.getTxnNumber(), + {true} /* startTransaction */); _execContext = ExecutionContext::kOwnSession; } else if (!clientTxnNumber) { + const auto acquiredSession = + InternalSessionPool::get(opCtx)->acquireChildSession(opCtx, *clientSession); + _acquiredSessionFromPool = true; _setSessionInfo(lg, - makeLogicalSessionIdWithTxnUUID(*clientSession), - 0 /* txnNumber */, + acquiredSession.getSessionId(), + acquiredSession.getTxnNumber(), {true} /* startTransaction */); _execContext = ExecutionContext::kClientSession; } else if (!clientInMultiDocumentTransaction) { @@ -625,5 +633,13 @@ LogicalTime Transaction::getOperationTime() const { return _lastOperationTime; } +Transaction::~Transaction() { + if (_acquiredSessionFromPool) { + InternalSessionPool::get(_service)->release( + {*_sessionInfo.getSessionId(), *_sessionInfo.getTxnNumber()}); + _acquiredSessionFromPool = false; + } +} + } // namespace details } // namespace mongo::txn_api |