diff options
author | Jason Chan <jason.chan@mongodb.com> | 2018-11-21 10:20:44 -0500 |
---|---|---|
committer | Jason Chan <jason.chan@mongodb.com> | 2018-11-21 10:23:07 -0500 |
commit | 88c46ca0364f3f6481320a6bcaff709b564ebaa3 (patch) | |
tree | 4ea663b8500793b4abab15560eddcb8d19f1883c /src/mongo/db/single_transaction_stats.cpp | |
parent | f8de654b888ef3b9a9f210499b0b8f5d727dfffd (diff) | |
download | mongo-88c46ca0364f3f6481320a6bcaff709b564ebaa3.tar.gz |
SERVER-38189 check prepareStartTime before logging slow transaction info
Diffstat (limited to 'src/mongo/db/single_transaction_stats.cpp')
-rw-r--r-- | src/mongo/db/single_transaction_stats.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/mongo/db/single_transaction_stats.cpp b/src/mongo/db/single_transaction_stats.cpp index 0660752e41e..e0137d63148 100644 --- a/src/mongo/db/single_transaction_stats.cpp +++ b/src/mongo/db/single_transaction_stats.cpp @@ -55,13 +55,16 @@ Microseconds SingleTransactionStats::getDuration(TickSource* tickSource, Microseconds SingleTransactionStats::getPreparedDuration(TickSource* tickSource, TickSource::Tick curTick) const { invariant(_startTime > 0); - invariant(_preparedStartTime > 0); - - // If the transaction hasn't ended yet, we return how long it has currently been running for. - if (_endTime == 0) { - return tickSource->ticksTo<Microseconds>(curTick - _preparedStartTime); + if (_preparedStartTime != boost::none) { + // If the transaction hasn't ended yet, we return how long it has currently been running + // for. + invariant(_preparedStartTime.get() > 0); + if (_endTime == 0) { + return tickSource->ticksTo<Microseconds>(curTick - _preparedStartTime.get()); + } + return tickSource->ticksTo<Microseconds>(_endTime - _preparedStartTime.get()); } - return tickSource->ticksTo<Microseconds>(_endTime - _preparedStartTime); + return Microseconds(0); } void SingleTransactionStats::setPreparedStartTime(TickSource::Tick time) { @@ -140,7 +143,7 @@ void SingleTransactionStats::report(BSONObjBuilder* builder, builder->append("timeActiveMicros", timeActive); builder->append("timeInactiveMicros", timeInactive); - if (_preparedStartTime > 0) { + if (_preparedStartTime != boost::none) { auto timePrepared = durationCount<Microseconds>(getPreparedDuration(tickSource, curTick)); builder->append("timePreparedMicros", timePrepared); } |