diff options
author | Matt Diener <matt.diener@mongodb.com> | 2022-10-12 20:19:44 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-10-12 21:06:32 +0000 |
commit | 02a79726b9109458d4eb37b010d58faf7332929b (patch) | |
tree | 03b789383d087ea67e627f8201e8f75b99a9e18e /src/mongo/util | |
parent | 112d7ad9e8eab0c0f8839a98d78b712b2eff9cbd (diff) | |
download | mongo-02a79726b9109458d4eb37b010d58faf7332929b.tar.gz |
SERVER-70264 make slowMS and sampleRate atomic
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/log_with_sampling.h | 2 | ||||
-rw-r--r-- | src/mongo/util/log_with_sampling_test.cpp | 7 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/mongo/util/log_with_sampling.h b/src/mongo/util/log_with_sampling.h index eb95aec5040..e3407c26e07 100644 --- a/src/mongo/util/log_with_sampling.h +++ b/src/mongo/util/log_with_sampling.h @@ -50,7 +50,7 @@ inline std::pair<bool, bool> shouldLogSlowOpWithSampling(OperationContext* opCtx const auto client = opCtx->getClient(); const bool shouldSample = - client->getPrng().nextCanonicalDouble() < serverGlobalParams.sampleRate; + client->getPrng().nextCanonicalDouble() < serverGlobalParams.sampleRate.load(); // Log the transaction if we should sample and its duration is greater than or equal to the // slowMS command threshold. diff --git a/src/mongo/util/log_with_sampling_test.cpp b/src/mongo/util/log_with_sampling_test.cpp index 88b3aebe91e..4a184485f95 100644 --- a/src/mongo/util/log_with_sampling_test.cpp +++ b/src/mongo/util/log_with_sampling_test.cpp @@ -65,9 +65,10 @@ auto scenario(bool debugLogEnabled, bool slowOp, bool forceSample) { auto loggedSeverityGuard = unittest::MinimumLoggedSeverityGuard( component, debugLogEnabled ? logv2::LogSeverity::Debug(1) : logv2::LogSeverity::Info()); - ScopeGuard sampleRateGuard( - [savedRate = serverGlobalParams.sampleRate] { serverGlobalParams.sampleRate = savedRate; }); - serverGlobalParams.sampleRate = forceSample ? 1.0 : 0.0; + ScopeGuard sampleRateGuard([savedRate = serverGlobalParams.sampleRate.load()] { + serverGlobalParams.sampleRate.store(savedRate); + }); + serverGlobalParams.sampleRate.store(forceSample ? 1.0 : 0.0); return shouldLogSlowOpWithSampling( opCtx.get(), component, Milliseconds{slowOp ? 11 : 9}, Milliseconds{10}); |