summaryrefslogtreecommitdiff
path: root/src/mongo/db/session.cpp
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2019-03-27 17:18:47 -0400
committerTess Avitabile <tess.avitabile@mongodb.com>2019-03-29 16:31:06 -0400
commit7ea6e5dc1b7ab547dc45211d59eae19ecbda068e (patch)
tree61c3e41536bd6bab90b8d9c672c79fec15fde90c /src/mongo/db/session.cpp
parent75bb4ccaec68d6ce691ced12cb97529509310e52 (diff)
downloadmongo-7ea6e5dc1b7ab547dc45211d59eae19ecbda068e.tar.gz
SERVER-40298 Track transaction size
Diffstat (limited to 'src/mongo/db/session.cpp')
-rw-r--r--src/mongo/db/session.cpp41
1 files changed, 23 insertions, 18 deletions
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<stdx::mutex> 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<stdx::mutex> 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));