diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2019-01-29 13:43:16 -0500 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2019-01-29 17:12:05 -0500 |
commit | 941c4fbab21029e3bbe577d953250116cd0e8533 (patch) | |
tree | ef7f69b2cacc081a16b4da1b58c327f29ae0b8b4 /src/mongo | |
parent | 7380d6e9ad0a90f6c5758b52d166d4069dd5a502 (diff) | |
download | mongo-941c4fbab21029e3bbe577d953250116cd0e8533.tar.gz |
SERVER-39267 Guard opWriteConcernCounters behind flag
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/stats/server_write_concern_metrics.cpp | 46 | ||||
-rw-r--r-- | src/mongo/db/stats/server_write_concern_metrics.h | 15 |
2 files changed, 48 insertions, 13 deletions
diff --git a/src/mongo/db/stats/server_write_concern_metrics.cpp b/src/mongo/db/stats/server_write_concern_metrics.cpp index 3bcf1fe99af..da8e74c9011 100644 --- a/src/mongo/db/stats/server_write_concern_metrics.cpp +++ b/src/mongo/db/stats/server_write_concern_metrics.cpp @@ -34,9 +34,16 @@ #include "mongo/db/commands/server_status.h" #include "mongo/db/jsobj.h" #include "mongo/db/operation_context.h" +#include "mongo/db/server_parameters.h" #include "mongo/db/service_context.h" namespace mongo { + +// opWriteConcernCounters are not tracked unless 'reportOpWriteConcernCountersInServerStatus' is +// true. This is false by default because the mutex acquisition impacts performance when SSL is +// disabled. (When SSL is enabled, other mutexes dominate.) +MONGO_EXPORT_STARTUP_SERVER_PARAMETER(reportOpWriteConcernCountersInServerStatus, bool, false); + namespace { const auto ServerWriteConcernMetricsDecoration = ServiceContext::declareDecoration<ServerWriteConcernMetrics>(); @@ -50,7 +57,41 @@ ServerWriteConcernMetrics* ServerWriteConcernMetrics::get(OperationContext* opCt return get(opCtx->getServiceContext()); } +void ServerWriteConcernMetrics::recordWriteConcernForInserts( + const WriteConcernOptions& writeConcernOptions, size_t numInserts) { + if (!reportOpWriteConcernCountersInServerStatus) { + return; + } + + stdx::lock_guard<stdx::mutex> lg(_mutex); + _insertMetrics.recordWriteConcern(writeConcernOptions, numInserts); +} + +void ServerWriteConcernMetrics::recordWriteConcernForUpdate( + const WriteConcernOptions& writeConcernOptions) { + if (!reportOpWriteConcernCountersInServerStatus) { + return; + } + + stdx::lock_guard<stdx::mutex> lg(_mutex); + _updateMetrics.recordWriteConcern(writeConcernOptions); +} + +void ServerWriteConcernMetrics::recordWriteConcernForDelete( + const WriteConcernOptions& writeConcernOptions) { + if (!reportOpWriteConcernCountersInServerStatus) { + return; + } + + stdx::lock_guard<stdx::mutex> lg(_mutex); + _deleteMetrics.recordWriteConcern(writeConcernOptions); +} + BSONObj ServerWriteConcernMetrics::toBSON() const { + if (!reportOpWriteConcernCountersInServerStatus) { + return BSONObj(); + } + stdx::lock_guard<stdx::mutex> lg(_mutex); BSONObjBuilder builder; @@ -117,7 +158,10 @@ public: ~OpWriteConcernCountersSSS() override = default; bool includeByDefault() const override { - return true; + // When 'reportOpWriteConcernCountersInServerStatus' is false, do not include this section + // unless requested by the user. Even if the user requests the section, it will not be + // included because an empty BSONObj is generated for the section. + return reportOpWriteConcernCountersInServerStatus; } BSONObj generateSection(OperationContext* opCtx, diff --git a/src/mongo/db/stats/server_write_concern_metrics.h b/src/mongo/db/stats/server_write_concern_metrics.h index c7a17dcc5d7..9a9525d1b30 100644 --- a/src/mongo/db/stats/server_write_concern_metrics.h +++ b/src/mongo/db/stats/server_write_concern_metrics.h @@ -53,10 +53,7 @@ public: * 'writeConcernOptions'. */ void recordWriteConcernForInserts(const WriteConcernOptions& writeConcernOptions, - size_t numInserts) { - stdx::lock_guard<stdx::mutex> lg(_mutex); - _insertMetrics.recordWriteConcern(writeConcernOptions, numInserts); - } + size_t numInserts); /** * Updates the insert metrics according to the 'w' value of 'writeConcernOptions'. @@ -68,18 +65,12 @@ public: /** * Updates the update metrics according to the 'w' value of 'writeConcernOptions'. */ - void recordWriteConcernForUpdate(const WriteConcernOptions& writeConcernOptions) { - stdx::lock_guard<stdx::mutex> lg(_mutex); - _updateMetrics.recordWriteConcern(writeConcernOptions); - } + void recordWriteConcernForUpdate(const WriteConcernOptions& writeConcernOptions); /** * Updates the delete metrics according to the 'w' value of 'writeConcernOptions'. */ - void recordWriteConcernForDelete(const WriteConcernOptions& writeConcernOptions) { - stdx::lock_guard<stdx::mutex> lg(_mutex); - _deleteMetrics.recordWriteConcern(writeConcernOptions); - } + void recordWriteConcernForDelete(const WriteConcernOptions& writeConcernOptions); BSONObj toBSON() const; |