diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2019-08-07 18:09:06 -0400 |
---|---|---|
committer | Jack Mulrow <jack.mulrow@mongodb.com> | 2019-08-19 17:11:07 -0400 |
commit | 4d59f45f85919ddaffa260fb76d1e7dbd8950edf (patch) | |
tree | 8919cc5bb5b8f2833ad87bdb0024808b775bd100 /src/mongo/s/transaction_router.h | |
parent | cab4fe1d5699c87a6e766783d3184a4846b2d08c (diff) | |
download | mongo-4d59f45f85919ddaffa260fb76d1e7dbd8950edf.tar.gz |
SERVER-41376 Track time transactions on mongos are active and inactive and include in slow txn logging
Diffstat (limited to 'src/mongo/s/transaction_router.h')
-rw-r--r-- | src/mongo/s/transaction_router.h | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/mongo/s/transaction_router.h b/src/mongo/s/transaction_router.h index 3f1e45d5fa3..10879068894 100644 --- a/src/mongo/s/transaction_router.h +++ b/src/mongo/s/transaction_router.h @@ -134,23 +134,59 @@ public: */ Microseconds getCommitDuration(TickSource* tickSource, TickSource::Tick curTicks) const; + /** + * Returns the total active time of the transaction, given the current time value. A + * transaction is active when there is a running operation that is part of the transaction. + */ + Microseconds getTimeActiveMicros(TickSource* tickSource, TickSource::Tick curTicks) const; + + /** + * Returns the total inactive time of the transaction, given the current time value. A + * transaction is inactive when it is idly waiting for a new operation to occur. + */ + Microseconds getTimeInactiveMicros(TickSource* tickSource, TickSource::Tick curTicks) const; + + /** + * Marks the transaction as active and sets the start of the transaction's active time and + * overall start time the first time it is called. + * + * This method is a no-op if the transaction is currently active or has already ended. + */ + void trySetActive(OperationContext* opCtx, TickSource::Tick curTicks); + + /** + * Marks the transaction as inactive and sets the total active time of the transaction. The + * total active time will only be set if the transaction was active prior to this call. + * + * This method is a no-op if the transaction is not currently active or has already ended. + */ + void trySetInactive(TickSource* tickSource, TickSource::Tick curTicks); + // The start time of the transaction in millisecond resolution. Used only for diagnostics // reporting. Date_t startWallClockTime; // The start time of the transaction. Note that tick values should only ever be used to - // measure distance from other tick values, not for reporting absolute wall clock time. + // measure distance from other tick values, not for reporting absolute wall clock time. A + // value of zero means the transaction hasn't started yet. TickSource::Tick startTime{0}; // The start time of the transaction commit in millisecond resolution. Used only for // diagnostics reporting. Date_t commitStartWallClockTime; - // When commit was started. + // When commit was started. A value of zero means the commit hasn't started yet. TickSource::Tick commitStartTime{0}; - // The end time of the transaction. + // The end time of the transaction. A value of zero means the transaction hasn't ended yet. TickSource::Tick endTime{0}; + + // The total amount of active time spent by the transaction. + Microseconds timeActiveMicros = Microseconds{0}; + + // The time at which the transaction was last marked as active. The transaction is + // considered active if this value is not equal to 0. + TickSource::Tick lastTimeActiveStart{0}; }; enum class TransactionActions { kStart, kContinue, kCommit }; @@ -260,6 +296,11 @@ public: TransactionActions action); /** + * Updates transaction diagnostics when the transaction's session is checked in. + */ + void stash(OperationContext* opCtx); + + /** * Attaches the required transaction related fields for a request to be sent to the given * shard. * @@ -517,6 +558,11 @@ public: void _onNonRetryableCommitError(OperationContext* opCtx, Status commitStatus); /** + * Updates relevent metrics when a transaction is continued. + */ + void _onContinue(OperationContext* opCtx); + + /** * The first time this method is called it marks the transaction as over in the router's * diagnostics and will log transaction information if its duration is over the global * slowMS threshold or the transaction log componenet verbosity >= 1. Only meant to be |