summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/noPassthrough/server_transaction_metrics_last_committed_transaction.js7
-rw-r--r--src/mongo/db/ftdc/ftdc_server.cpp5
-rw-r--r--src/mongo/db/server_transactions_metrics.cpp11
-rw-r--r--src/mongo/db/server_transactions_metrics.h3
4 files changed, 20 insertions, 6 deletions
diff --git a/jstests/noPassthrough/server_transaction_metrics_last_committed_transaction.js b/jstests/noPassthrough/server_transaction_metrics_last_committed_transaction.js
index 7f5faa9e4f8..077dca4e25a 100644
--- a/jstests/noPassthrough/server_transaction_metrics_last_committed_transaction.js
+++ b/jstests/noPassthrough/server_transaction_metrics_last_committed_transaction.js
@@ -56,6 +56,13 @@
assert.commandWorked(session.commitTransaction_forTesting());
checkLastCommittedTransaction(1, {});
+ // Check that we are able to exclude 'lastCommittedTransaction'. FTDC uses this to filter out
+ // the section as it frequently triggers scheme changes.
+ let filteredRes = assert.commandWorked(
+ primary.adminCommand({serverStatus: 1, transactions: {includeLastCommitted: false}}));
+ assert(!filteredRes.transactions.hasOwnProperty("lastCommittedTransaction"),
+ () => tojson(filteredRes));
+
// Run a transaction with multiple write operations.
session.startTransaction();
assert.commandWorked(sessionColl.insert({}));
diff --git a/src/mongo/db/ftdc/ftdc_server.cpp b/src/mongo/db/ftdc/ftdc_server.cpp
index a46a0106262..0bb8f311a84 100644
--- a/src/mongo/db/ftdc/ftdc_server.cpp
+++ b/src/mongo/db/ftdc/ftdc_server.cpp
@@ -299,8 +299,9 @@ void startFTDC(boost::filesystem::path& path,
"serverStatus",
"serverStatus",
"",
- BSON("serverStatus" << 1 << "tcMalloc" << true << "sharding" << false << "timing"
- << false)));
+ BSON("serverStatus" << 1 << "tcMalloc" << true << "sharding" << false << "timing" << false
+ << "transactions"
+ << BSON("includeLastCommitted" << false))));
registerCollectors(controller.get());
diff --git a/src/mongo/db/server_transactions_metrics.cpp b/src/mongo/db/server_transactions_metrics.cpp
index da5f2b8a112..e96222170d7 100644
--- a/src/mongo/db/server_transactions_metrics.cpp
+++ b/src/mongo/db/server_transactions_metrics.cpp
@@ -125,7 +125,7 @@ void ServerTransactionsMetrics::updateLastTransaction(size_t operationCount,
_lastCommittedTransaction->setWriteConcern(std::move(writeConcern));
}
-void ServerTransactionsMetrics::updateStats(TransactionsStats* stats) {
+void ServerTransactionsMetrics::updateStats(TransactionsStats* stats, bool includeLastCommitted) {
stats->setCurrentActive(_currentActive.load());
stats->setCurrentInactive(_currentInactive.load());
stats->setCurrentOpen(_currentOpen.load());
@@ -134,7 +134,7 @@ void ServerTransactionsMetrics::updateStats(TransactionsStats* stats) {
stats->setTotalStarted(_totalStarted.load());
stdx::lock_guard<stdx::mutex> lg(_mutex);
- if (_lastCommittedTransaction) {
+ if (_lastCommittedTransaction && includeLastCommitted) {
stats->setLastCommittedTransaction(*_lastCommittedTransaction);
}
}
@@ -153,12 +153,17 @@ public:
const BSONElement& configElement) const {
TransactionsStats stats;
+ bool includeLastCommitted = true;
+ if (configElement.type() == BSONType::Object) {
+ includeLastCommitted = configElement.Obj()["includeLastCommitted"].trueValue();
+ }
+
// Retryable writes and multi-document transactions metrics are both included in the same
// serverStatus section because both utilize similar internal machinery for tracking their
// lifecycle within a session. Both are assigned transaction numbers, and so both are often
// referred to as “transactions”.
RetryableWritesStats::get(opCtx)->updateStats(&stats);
- ServerTransactionsMetrics::get(opCtx)->updateStats(&stats);
+ ServerTransactionsMetrics::get(opCtx)->updateStats(&stats, includeLastCommitted);
return stats.toBSON();
}
diff --git a/src/mongo/db/server_transactions_metrics.h b/src/mongo/db/server_transactions_metrics.h
index 02f397cde9e..c2d1270877f 100644
--- a/src/mongo/db/server_transactions_metrics.h
+++ b/src/mongo/db/server_transactions_metrics.h
@@ -75,8 +75,9 @@ public:
/**
* Appends the accumulated stats to a transactions stats object.
+ * Include the 'lastCommittedTransactions' field if 'includeLastCommitted' is true.
*/
- void updateStats(TransactionsStats* stats);
+ void updateStats(TransactionsStats* stats, bool includeLastCommitted);
private:
// The number of multi-document transactions currently active.