From 7ea6e5dc1b7ab547dc45211d59eae19ecbda068e Mon Sep 17 00:00:00 2001 From: Tess Avitabile Date: Wed, 27 Mar 2019 17:18:47 -0400 Subject: SERVER-40298 Track transaction size --- src/mongo/db/session.cpp | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'src/mongo/db/session.cpp') diff --git a/src/mongo/db/session.cpp b/src/mongo/db/session.cpp index 47727848aae..d30ba490fae 100644 --- a/src/mongo/db/session.cpp +++ b/src/mongo/db/session.cpp @@ -1074,23 +1074,24 @@ void Session::commitTransaction(OperationContext* opCtx) { void Session::_commitTransaction(stdx::unique_lock lk, OperationContext* opCtx) { invariant(_txnState == MultiDocumentTransactionState::kInProgress); - const bool isMultiDocumentTransaction = _txnState == MultiDocumentTransactionState::kInProgress; - if (isMultiDocumentTransaction) { - // We need to unlock the session to run the opObserver onTransactionCommit, which calls back - // into the session. - lk.unlock(); - auto opObserver = opCtx->getServiceContext()->getOpObserver(); - invariant(opObserver); - opObserver->onTransactionCommit(opCtx); - lk.lock(); - // It's possible some other thread aborted the transaction (e.g. through killSession) while - // the opObserver was running. If that happened, the commit should be reported as failed. - uassert(ErrorCodes::NoSuchTransaction, - str::stream() << "Transaction " << opCtx->getTxnNumber() - << " aborted while attempting to commit", - _txnState == MultiDocumentTransactionState::kInProgress && - _activeTxnNumber == opCtx->getTxnNumber()); - } + const size_t operationCount = _transactionOperations.size(); + const size_t oplogOperationBytes = _transactionOperationBytes; + + // We need to unlock the session to run the opObserver onTransactionCommit, which calls back + // into the session. + lk.unlock(); + auto opObserver = opCtx->getServiceContext()->getOpObserver(); + invariant(opObserver); + opObserver->onTransactionCommit(opCtx); + lk.lock(); + + // It's possible some other thread aborted the transaction (e.g. through killSession) while the + // opObserver was running. If that happened, the commit should be reported as failed. + uassert(ErrorCodes::NoSuchTransaction, + str::stream() << "Transaction " << opCtx->getTxnNumber() + << " aborted while attempting to commit", + _txnState == MultiDocumentTransactionState::kInProgress && + _activeTxnNumber == opCtx->getTxnNumber()); _txnState = MultiDocumentTransactionState::kCommitting; bool committed = false; ON_BLOCK_EXIT([this, &committed, opCtx]() { @@ -1158,7 +1159,11 @@ void Session::_commitTransaction(stdx::unique_lock lk, OperationCon // inactive. ServerTransactionsMetrics::get(opCtx)->incrementTotalCommitted(); ServerTransactionsMetrics::get(opCtx)->decrementCurrentOpen(); - ServerTransactionsMetrics::get(getGlobalServiceContext())->decrementCurrentActive(); + ServerTransactionsMetrics::get(opCtx)->decrementCurrentActive(); + ServerTransactionsMetrics::get(opCtx)->updateLastTransaction( + operationCount, + oplogOperationBytes, + opCtx->getWriteConcern().usedDefault ? BSONObj() : opCtx->getWriteConcern().toBSON()); auto curTime = curTimeMicros64(); Top::get(getGlobalServiceContext()) .incrementGlobalTransactionLatencyStats(_singleTransactionStats.getDuration(curTime)); -- cgit v1.2.1