summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Caimano <ben.caimano@10gen.com>2020-07-09 21:28:35 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-07-13 15:09:04 +0000
commitdbc867c4cfdadac4503658060c0a17a7cc249bbc (patch)
tree2351b0fb1e12b504365cd9f7cfe3ca470e6ba295
parentc957403d177c8b83c3d3693b29d7af73f34ffdfc (diff)
downloadmongo-dbc867c4cfdadac4503658060c0a17a7cc249bbc.tar.gz
SERVER-47892 DiagnosticInfo should use Client to acquire timestamps
-rw-r--r--src/mongo/util/diagnostic_info.cpp24
-rw-r--r--src/mongo/util/diagnostic_info.h4
-rw-r--r--src/mongo/util/diagnostic_info_test.cpp6
3 files changed, 22 insertions, 12 deletions
diff --git a/src/mongo/util/diagnostic_info.cpp b/src/mongo/util/diagnostic_info.cpp
index 22e7287ae9b..49076e76c91 100644
--- a/src/mongo/util/diagnostic_info.cpp
+++ b/src/mongo/util/diagnostic_info.cpp
@@ -187,9 +187,7 @@ MONGO_INITIALIZER_GENERAL(DiagnosticInfo, (/* NO PREREQS */), ("FinalizeDiagnost
class DiagnosticListener : public latch_detail::DiagnosticListener {
void onContendedLock(const Identity& id) override {
if (auto client = Client::getCurrent()) {
- auto& handle = getDiagnosticInfoHandle(client);
- stdx::lock_guard<stdx::mutex> lk(handle.mutex);
- handle.list.emplace_front(DiagnosticInfo::capture(id.name()));
+ DiagnosticInfo::capture(client, id.name());
if (currentOpSpawnsThreadWaitingForLatch.shouldFail() &&
(id.name() == kBlockedOpMutexName)) {
@@ -229,9 +227,7 @@ MONGO_INITIALIZER(InterruptibleWaitListener)(InitializerContext* context) {
void addInfo(const StringData& name) {
if (auto client = Client::getCurrent()) {
- auto& handle = getDiagnosticInfoHandle(client);
- stdx::lock_guard<stdx::mutex> lk(handle.mutex);
- handle.list.emplace_front(DiagnosticInfo::capture(name));
+ DiagnosticInfo::capture(client, name);
if (currentOpSpawnsThreadWaitingForLatch.shouldFail() &&
(name == kBlockedOpInterruptibleName)) {
@@ -278,13 +274,23 @@ std::string DiagnosticInfo::toString() const {
_captureName.toString(), _timestamp.toString(), _backtrace.data.size());
}
-DiagnosticInfo DiagnosticInfo::capture(const StringData& captureName, Options options) {
+const DiagnosticInfo& DiagnosticInfo::capture(Client* client,
+ const StringData& captureName,
+ Options options) noexcept {
+ auto currentTime = client->getServiceContext()->getFastClockSource()->now();
+
// Since we don't have a fast enough backtrace implementation at the moment, the Backtrace is
// always empty. If SERVER-44091 happens, this should branch on options.shouldTakeBacktrace
auto backtrace = Backtrace{};
- auto currentTime = getGlobalServiceContext()->getFastClockSource()->now();
- return DiagnosticInfo(currentTime, captureName, std::move(backtrace));
+ auto info = DiagnosticInfo(currentTime, captureName, std::move(backtrace));
+
+ auto& handle = getDiagnosticInfoHandle(client);
+
+ stdx::lock_guard<stdx::mutex> lk(handle.mutex);
+ handle.list.emplace_front(std::move(info));
+
+ return handle.list.front();
}
DiagnosticInfo::BlockedOpGuard::~BlockedOpGuard() {
diff --git a/src/mongo/util/diagnostic_info.h b/src/mongo/util/diagnostic_info.h
index 2b457fc50fe..dc6b3fbde2c 100644
--- a/src/mongo/util/diagnostic_info.h
+++ b/src/mongo/util/diagnostic_info.h
@@ -85,7 +85,9 @@ public:
/**
* Captures the diagnostic information based on the caller's context.
*/
- static DiagnosticInfo capture(const StringData& captureName, Options options = Options{});
+ static const DiagnosticInfo& capture(Client* client,
+ const StringData& captureName,
+ Options options = Options{}) noexcept;
/**
* This function checks the FailPoint currentOpSpawnsThreadWaitingForLatch and potentially
diff --git a/src/mongo/util/diagnostic_info_test.cpp b/src/mongo/util/diagnostic_info_test.cpp
index f8514525084..365f37ae9c1 100644
--- a/src/mongo/util/diagnostic_info_test.cpp
+++ b/src/mongo/util/diagnostic_info_test.cpp
@@ -47,8 +47,10 @@ TEST(DiagnosticInfo, BasicSingleThread) {
serviceContext->setFastClockSource(std::move(clockSource));
setGlobalServiceContext(std::move(serviceContext));
+ ThreadClient tc("DiagnosticInfoTest", getGlobalServiceContext());
+
// take the initial diagnostic info
- DiagnosticInfo capture1 = DiagnosticInfo::capture("capture1"_sd);
+ DiagnosticInfo capture1 = DiagnosticInfo::capture(tc.get(), "capture1"_sd);
ASSERT_EQ(capture1.getCaptureName(), "capture1");
// mock time advancing and check that the current time is greater than capture1's timestamp
@@ -56,7 +58,7 @@ TEST(DiagnosticInfo, BasicSingleThread) {
ASSERT_LT(capture1.getTimestamp(), clockSourcePointer->now());
// take a second diagnostic capture and compare its fields to the first
- DiagnosticInfo capture2 = DiagnosticInfo::capture("capture2"_sd);
+ DiagnosticInfo capture2 = DiagnosticInfo::capture(tc.get(), "capture2"_sd);
ASSERT_LT(capture1.getTimestamp(), capture2.getTimestamp());
ASSERT_EQ(capture2.getCaptureName(), "capture2");
ASSERT_NE(capture2, capture1);