diff options
author | Xuerui Fa <xuerui.fa@mongodb.com> | 2020-01-27 18:17:01 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-02-05 22:41:37 +0000 |
commit | b0c5c0baa85fba563c80ee416cecc22e9ffbf53a (patch) | |
tree | 7b58a9cfa80c94b384b97333708e8a43923b1b33 /src/mongo/db/repl/oplog_applier_impl.cpp | |
parent | 84940076a90c3938decb6a28219f7102307404bd (diff) | |
download | mongo-b0c5c0baa85fba563c80ee416cecc22e9ffbf53a.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/repl/oplog_applier_impl.cpp')
-rw-r--r-- | src/mongo/db/repl/oplog_applier_impl.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/mongo/db/repl/oplog_applier_impl.cpp b/src/mongo/db/repl/oplog_applier_impl.cpp index 8b7d7ba3c41..1ac70f2a05e 100644 --- a/src/mongo/db/repl/oplog_applier_impl.cpp +++ b/src/mongo/db/repl/oplog_applier_impl.cpp @@ -48,6 +48,7 @@ #include "mongo/platform/basic.h" #include "mongo/util/fail_point.h" #include "mongo/util/log.h" +#include "mongo/util/log_with_sampling.h" #include "third_party/murmurhash3/MurmurHash3.h" namespace mongo { @@ -96,17 +97,21 @@ NamespaceStringOrUUID getNsOrUUID(const NamespaceString& nss, const OplogEntry& * Used for logging a report of ops that take longer than "slowMS" to apply. This is called * right before returning from applyOplogEntryOrGroupedInserts, and it returns the same status. */ -Status finishAndLogApply(ClockSource* clockSource, +Status finishAndLogApply(OperationContext* opCtx, + ClockSource* clockSource, Status finalStatus, Date_t applyStartTime, const OplogEntryOrGroupedInserts& entryOrGroupedInserts) { if (finalStatus.isOK()) { auto applyEndTime = clockSource->now(); - auto diffMS = durationCount<Milliseconds>(applyEndTime - applyStartTime); + auto opDuration = durationCount<Milliseconds>(applyEndTime - applyStartTime); - // This op was slow to apply, so we should log a report of it. - if (diffMS > serverGlobalParams.slowMS) { + if (shouldLogSlowOpWithSampling(opCtx, + MONGO_LOG_DEFAULT_COMPONENT, + Milliseconds(opDuration), + Milliseconds(serverGlobalParams.slowMS)) + .first) { StringBuilder s; s << "applied op: "; @@ -118,7 +123,7 @@ Status finishAndLogApply(ClockSource* clockSource, } s << redact(entryOrGroupedInserts.toBSON()); - s << ", took " << diffMS << "ms"; + s << ", took " << opDuration << "ms"; log() << s.str(); } @@ -971,7 +976,7 @@ Status applyOplogEntryOrGroupedInserts(OperationContext* opCtx, throw; } }); - return finishAndLogApply(clockSource, status, applyStartTime, entryOrGroupedInserts); + return finishAndLogApply(opCtx, clockSource, status, applyStartTime, entryOrGroupedInserts); } else if (opType == OpTypeEnum::kCommand) { auto status = writeConflictRetry(opCtx, "applyOplogEntryOrGroupedInserts_command", nss.ns(), [&] { @@ -980,7 +985,7 @@ Status applyOplogEntryOrGroupedInserts(OperationContext* opCtx, incrementOpsAppliedStats(); return status; }); - return finishAndLogApply(clockSource, status, applyStartTime, entryOrGroupedInserts); + return finishAndLogApply(opCtx, clockSource, status, applyStartTime, entryOrGroupedInserts); } MONGO_UNREACHABLE; |