summaryrefslogtreecommitdiff
path: root/src/mongo/db/transaction_participant.cpp
diff options
context:
space:
mode:
authorXuerui Fa <xuerui.fa@mongodb.com>2020-02-07 15:19:58 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-07 22:53:35 +0000
commitfd1e712a1407181e1105b4767205a42bbf463bbd (patch)
treece8f422421c628d557d52e6aabed8ab7776819fd /src/mongo/db/transaction_participant.cpp
parentb11d1174d98481c497d26728d0fa21e54192b712 (diff)
downloadmongo-fd1e712a1407181e1105b4767205a42bbf463bbd.tar.gz
SERVER-43069: Condition logging for slow ops on sample rate
create mode 100644 src/mongo/util/log_with_sampling.h create mode 100644 src/mongo/util/log_with_sampling_test.cpp
Diffstat (limited to 'src/mongo/db/transaction_participant.cpp')
-rw-r--r--src/mongo/db/transaction_participant.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp
index 4dd7905add3..7687b9a5d86 100644
--- a/src/mongo/db/transaction_participant.cpp
+++ b/src/mongo/db/transaction_participant.cpp
@@ -65,6 +65,7 @@
#include "mongo/db/transaction_participant_gen.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
+#include "mongo/util/log_with_sampling.h"
#include "mongo/util/net/socket_utils.h"
namespace mongo {
@@ -1884,11 +1885,15 @@ void TransactionParticipant::Participant::_logSlowTransaction(
// Only log multi-document transactions.
if (!o().txnState.isInRetryableWriteMode()) {
const auto tickSource = opCtx->getServiceContext()->getTickSource();
- // Log the transaction if log message verbosity for transaction component is >= 1 or its
- // duration is longer than the slowMS command threshold.
- if (shouldLog(logger::LogComponent::kTransaction, logger::LogSeverity::Debug(1)) ||
+ const auto opDuration = duration_cast<Milliseconds>(
o().transactionMetricsObserver.getSingleTransactionStats().getDuration(
- tickSource, tickSource->getTicks()) > Milliseconds(serverGlobalParams.slowMS)) {
+ tickSource, tickSource->getTicks()));
+
+ if (shouldLogSlowOpWithSampling(opCtx,
+ logger::LogComponent::kTransaction,
+ opDuration,
+ Milliseconds(serverGlobalParams.slowMS))
+ .first) {
log(logger::LogComponent::kTransaction)
<< "transaction "
<< _transactionInfoForLog(opCtx, lockStats, terminationCause, readConcernArgs);