diff options
author | jinichu <jinnybyun@gmail.com> | 2018-06-22 13:56:58 -0400 |
---|---|---|
committer | jinichu <jinnybyun@gmail.com> | 2018-08-06 17:29:27 -0400 |
commit | ac675fa326a0d721734823aed20e31797287af5e (patch) | |
tree | 662aa5ebf9d4859294093dca0036adfb6d4c1849 /src/mongo/db/session.cpp | |
parent | 3defcfc4e4f1eed21540bea7521356a278858704 (diff) | |
download | mongo-ac675fa326a0d721734823aed20e31797287af5e.tar.gz |
SERVER-35308 Added timeActiveMicros field to SingleTransactionStats to measure total active time
(cherry picked from commit cfb0b9ff7ca1a20c3c37edd2baf6e5c509c65aca)
Diffstat (limited to 'src/mongo/db/session.cpp')
-rw-r--r-- | src/mongo/db/session.cpp | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/mongo/db/session.cpp b/src/mongo/db/session.cpp index 3442d74724e..ba636e7f2b7 100644 --- a/src/mongo/db/session.cpp +++ b/src/mongo/db/session.cpp @@ -712,6 +712,10 @@ void Session::stashTransactionResources(OperationContext* opCtx) { return; } + if (_singleTransactionStats->isActive()) { + _singleTransactionStats->setInactive(curTimeMicros64()); + } + invariant(!_txnResourceStash); _txnResourceStash = TxnResources(opCtx); } @@ -761,9 +765,12 @@ void Session::unstashTransactionResources(OperationContext* opCtx, const std::st uassert(ErrorCodes::InvalidOptions, "Only the first command in a transaction may specify a readConcern", readConcernArgs.isEmpty()); - _txnResourceStash->release(opCtx); _txnResourceStash = boost::none; + // Set the starting active time for this transaction. + if (_txnState == MultiDocumentTransactionState::kInProgress) { + _singleTransactionStats->setActive(curTimeMicros64()); + } return; } @@ -774,6 +781,9 @@ void Session::unstashTransactionResources(OperationContext* opCtx, const std::st } opCtx->setWriteUnitOfWork(std::make_unique<WriteUnitOfWork>(opCtx)); + // Set the starting active time for this transaction. + _singleTransactionStats->setActive(curTimeMicros64()); + // If maxTransactionLockRequestTimeoutMillis is set, then we will ensure no // future lock request waits longer than maxTransactionLockRequestTimeoutMillis // to acquire a lock. This is to avoid deadlocks and minimize non-transaction @@ -857,7 +867,11 @@ void Session::_abortTransaction(WithLock wl) { _txnState = MultiDocumentTransactionState::kAborted; _speculativeTransactionReadOpTime = repl::OpTime(); if (isMultiDocumentTransaction) { - _singleTransactionStats->setEndTime(curTimeMicros64()); + auto curTime = curTimeMicros64(); + _singleTransactionStats->setEndTime(curTime); + if (_singleTransactionStats->isActive()) { + _singleTransactionStats->setInactive(curTime); + } } } @@ -881,6 +895,7 @@ void Session::_setActiveTxn(WithLock wl, TxnNumber txnNumber) { _activeTxnCommittedStatements.clear(); _hasIncompleteHistory = false; _txnState = MultiDocumentTransactionState::kNone; + _singleTransactionStats = boost::none; _speculativeTransactionReadOpTime = repl::OpTime(); _multikeyPathInfo.clear(); } @@ -964,8 +979,13 @@ void Session::_commitTransaction(stdx::unique_lock<stdx::mutex> lk, OperationCon // Make sure the transaction didn't change because of chunk migration. if (opCtx->getTxnNumber() == _activeTxnNumber) { _txnState = MultiDocumentTransactionState::kAborted; - // After the transaction has been aborted, we must update the end time. - _singleTransactionStats->setEndTime(curTimeMicros64()); + // After the transaction has been aborted, we must update the end time and mark it + // as inactive. + auto curTime = curTimeMicros64(); + _singleTransactionStats->setEndTime(curTime); + if (_singleTransactionStats->isActive()) { + _singleTransactionStats->setInactive(curTime); + } } } // We must clear the recovery unit and locker so any post-transaction writes can run without @@ -990,9 +1010,12 @@ void Session::_commitTransaction(stdx::unique_lock<stdx::mutex> lk, OperationCon clientInfo.setLastOp(_speculativeTransactionReadOpTime); } _txnState = MultiDocumentTransactionState::kCommitted; - // After the transaction has been committed, we must update the end time. - if (isMultiDocumentTransaction) { - _singleTransactionStats->setEndTime(curTimeMicros64()); + // After the transaction has been committed, we must update the end time and mark it as + // inactive. + auto curTime = curTimeMicros64(); + _singleTransactionStats->setEndTime(curTime); + if (_singleTransactionStats->isActive()) { + _singleTransactionStats->setInactive(curTime); } } |