summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/single_transaction_coordinator_stats.h
diff options
context:
space:
mode:
authorLamont Nelson <lamont.nelson@mongodb.com>2019-09-05 18:32:19 +0000
committerevergreen <evergreen@mongodb.com>2019-09-05 18:32:19 +0000
commitb46eb782c4730c8df589a56550c29c3f3585904a (patch)
tree908a3dffce58c449a9d241f193c99e1e6ec28bee /src/mongo/db/s/single_transaction_coordinator_stats.h
parent174736c49e4a284d12c2d31a3f9c8bf341a35c65 (diff)
downloadmongo-b46eb782c4730c8df589a56550c29c3f3585904a.tar.gz
SERVER-42809 report metrics for the transaction coordinators in curop command
Diffstat (limited to 'src/mongo/db/s/single_transaction_coordinator_stats.h')
-rw-r--r--src/mongo/db/s/single_transaction_coordinator_stats.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/mongo/db/s/single_transaction_coordinator_stats.h b/src/mongo/db/s/single_transaction_coordinator_stats.h
index 05c75d7c076..1856bf9b054 100644
--- a/src/mongo/db/s/single_transaction_coordinator_stats.h
+++ b/src/mongo/db/s/single_transaction_coordinator_stats.h
@@ -29,6 +29,8 @@
#pragma once
+#include "mongo/db/client.h"
+#include "mongo/rpc/metadata/client_metadata_ismaster.h"
#include "mongo/util/tick_source.h"
#include "mongo/util/time_support.h"
@@ -43,6 +45,25 @@ class SingleTransactionCoordinatorStats {
public:
SingleTransactionCoordinatorStats() = default;
+ struct LastClientInfo {
+ std::string clientHostAndPort;
+ long long connectionId;
+ BSONObj clientMetadata;
+ std::string appName;
+
+ void update(Client* client) {
+ if (client->hasRemote()) {
+ clientHostAndPort = client->getRemote().toString();
+ }
+ connectionId = client->getConnectionId();
+ if (const auto& metadata =
+ ClientMetadataIsMasterState::get(client).getClientMetadata()) {
+ clientMetadata = metadata.get().getDocument();
+ appName = metadata.get().getApplicationName().toString();
+ }
+ }
+ };
+
//
// Setters
//
@@ -238,6 +259,29 @@ public:
Microseconds getDeletingCoordinatorDocDuration(TickSource* tickSource,
TickSource::Tick curTick) const;
+ /**
+ * Reports the time duration for each step in the two-phase commit and stores them as a
+ * sub-document of the provided parent BSONObjBuilder. The metrics are stored under key
+ * "stepDurations" in the parent document.
+ */
+ void reportMetrics(BSONObjBuilder& parent,
+ TickSource* tickSource,
+ TickSource::Tick curTick) const;
+
+ /**
+ * Reports information about the last client to interact with this transaction.
+ */
+ void reportLastClient(BSONObjBuilder& parent) const;
+
+ /**
+ * Updates the LastClientInfo object stored in this SingleTransactionStats instance with the
+ * given Client's information.
+ */
+ void updateLastClientInfo(Client* client) {
+ invariant(client);
+ _lastClientInfo.update(client);
+ }
+
private:
Date_t _createWallClockTime;
TickSource::Tick _createTime{0};
@@ -261,6 +305,8 @@ private:
Date_t _endWallClockTime;
TickSource::Tick _endTime{0};
+
+ LastClientInfo _lastClientInfo;
};
} // namespace mongo