From 6a2caa88fbef9ead75ea5216fa8d2798eaaa14ec Mon Sep 17 00:00:00 2001 From: Pavi Vetriselvan Date: Wed, 4 Nov 2020 20:25:57 -0500 Subject: SERVER-51263 rename ismaster_metrics files to hello_metrics --- src/mongo/db/repl/replication_coordinator_impl.cpp | 2 +- src/mongo/db/repl/replication_info.cpp | 2 +- src/mongo/db/service_entry_point_common.cpp | 2 +- src/mongo/s/commands/strategy.cpp | 2 +- src/mongo/s/mongos_topology_coordinator.h | 2 +- src/mongo/transport/SConscript | 2 +- src/mongo/transport/hello_metrics.cpp | 134 +++++++++++++++++++++ src/mongo/transport/hello_metrics.h | 107 ++++++++++++++++ src/mongo/transport/ismaster_metrics.cpp | 134 --------------------- src/mongo/transport/ismaster_metrics.h | 107 ---------------- src/mongo/transport/service_entry_point_impl.cpp | 2 +- 11 files changed, 248 insertions(+), 248 deletions(-) create mode 100644 src/mongo/transport/hello_metrics.cpp create mode 100644 src/mongo/transport/hello_metrics.h delete mode 100644 src/mongo/transport/ismaster_metrics.cpp delete mode 100644 src/mongo/transport/ismaster_metrics.h diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 4b0dcc7bf47..93955ee2b86 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -102,7 +102,7 @@ #include "mongo/platform/mutex.h" #include "mongo/rpc/metadata/oplog_query_metadata.h" #include "mongo/rpc/metadata/repl_set_metadata.h" -#include "mongo/transport/ismaster_metrics.h" +#include "mongo/transport/hello_metrics.h" #include "mongo/util/assert_util.h" #include "mongo/util/fail_point.h" #include "mongo/util/scopeguard.h" diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index b53fdc76b60..9744d05399b 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -61,7 +61,7 @@ #include "mongo/executor/network_interface.h" #include "mongo/logv2/log.h" #include "mongo/rpc/metadata/client_metadata.h" -#include "mongo/transport/ismaster_metrics.h" +#include "mongo/transport/hello_metrics.h" #include "mongo/util/decimal_counter.h" #include "mongo/util/fail_point.h" diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index 90daed815be..2cc05fc5080 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -98,7 +98,7 @@ #include "mongo/rpc/metadata/tracking_metadata.h" #include "mongo/rpc/op_msg.h" #include "mongo/rpc/reply_builder_interface.h" -#include "mongo/transport/ismaster_metrics.h" +#include "mongo/transport/hello_metrics.h" #include "mongo/transport/session.h" #include "mongo/util/duration.h" #include "mongo/util/fail_point.h" diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index 6cd8f17287d..12559d00c9f 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -84,7 +84,7 @@ #include "mongo/s/shard_invalidated_for_targeting_exception.h" #include "mongo/s/stale_exception.h" #include "mongo/s/transaction_router.h" -#include "mongo/transport/ismaster_metrics.h" +#include "mongo/transport/hello_metrics.h" #include "mongo/transport/session.h" #include "mongo/util/fail_point.h" #include "mongo/util/scopeguard.h" diff --git a/src/mongo/s/mongos_topology_coordinator.h b/src/mongo/s/mongos_topology_coordinator.h index bb04306f33d..208605d1e5f 100644 --- a/src/mongo/s/mongos_topology_coordinator.h +++ b/src/mongo/s/mongos_topology_coordinator.h @@ -33,7 +33,7 @@ #include "mongo/platform/mutex.h" #include "mongo/rpc/topology_version_gen.h" #include "mongo/s/mongos_is_master_response.h" -#include "mongo/transport/ismaster_metrics.h" +#include "mongo/transport/hello_metrics.h" #include "mongo/util/concurrency/with_lock.h" #include diff --git a/src/mongo/transport/SConscript b/src/mongo/transport/SConscript index ee4c644a084..1783a1cd9b8 100644 --- a/src/mongo/transport/SConscript +++ b/src/mongo/transport/SConscript @@ -7,7 +7,7 @@ env = env.Clone() env.Library( target='transport_layer_common', source=[ - 'ismaster_metrics.cpp', + 'hello_metrics.cpp', 'session.cpp', 'transport_layer.cpp', ], diff --git a/src/mongo/transport/hello_metrics.cpp b/src/mongo/transport/hello_metrics.cpp new file mode 100644 index 00000000000..786ed73bd99 --- /dev/null +++ b/src/mongo/transport/hello_metrics.cpp @@ -0,0 +1,134 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ +#include "mongo/transport/hello_metrics.h" + +namespace mongo { +namespace { +const auto HelloMetricsDecoration = ServiceContext::declareDecoration(); +const auto InExhaustHelloDecoration = transport::Session::declareDecoration(); +} // namespace + +HelloMetrics* HelloMetrics::get(ServiceContext* service) { + return &HelloMetricsDecoration(service); +} + +HelloMetrics* HelloMetrics::get(OperationContext* opCtx) { + return get(opCtx->getServiceContext()); +} + +size_t HelloMetrics::getNumExhaustIsMaster() const { + return _exhaustIsMasterConnections.load(); +} + +void HelloMetrics::incrementNumExhaustIsMaster() { + _exhaustIsMasterConnections.fetchAndAdd(1); +} + +void HelloMetrics::decrementNumExhaustIsMaster() { + _exhaustIsMasterConnections.fetchAndSubtract(1); +} + +size_t HelloMetrics::getNumExhaustHello() const { + return _exhaustHelloConnections.load(); +} + +void HelloMetrics::incrementNumExhaustHello() { + _exhaustHelloConnections.fetchAndAdd(1); +} + +void HelloMetrics::decrementNumExhaustHello() { + _exhaustHelloConnections.fetchAndSubtract(1); +} + +size_t HelloMetrics::getNumAwaitingTopologyChanges() const { + return _connectionsAwaitingTopologyChanges.load(); +} + +void HelloMetrics::incrementNumAwaitingTopologyChanges() { + _connectionsAwaitingTopologyChanges.fetchAndAdd(1); +} + +void HelloMetrics::decrementNumAwaitingTopologyChanges() { + _connectionsAwaitingTopologyChanges.fetchAndSubtract(1); +} + +void HelloMetrics::resetNumAwaitingTopologyChanges() { + _connectionsAwaitingTopologyChanges.store(0); +} + +InExhaustHello* InExhaustHello::get(transport::Session* session) { + return &InExhaustHelloDecoration(session); +} + +InExhaustHello::~InExhaustHello() { + if (_inExhaustIsMaster) { + HelloMetrics::get(getGlobalServiceContext())->decrementNumExhaustIsMaster(); + } + if (_inExhaustHello) { + HelloMetrics::get(getGlobalServiceContext())->decrementNumExhaustHello(); + } +} + +bool InExhaustHello::getInExhaustIsMaster() const { + return _inExhaustIsMaster; +} + +bool InExhaustHello::getInExhaustHello() const { + return _inExhaustHello; +} + +void InExhaustHello::setInExhaust(bool inExhaust, StringData commandName) { + bool isHello = (commandName == "hello"_sd); + + // Transition out of exhaust hello if setting inExhaust to false or if + // the isMaster command is used. + if (_inExhaustHello && (!inExhaust || !isHello)) { + HelloMetrics::get(getGlobalServiceContext())->decrementNumExhaustHello(); + _inExhaustHello = false; + } + + // Transition out of exhaust isMaster if setting inExhaust to false or if + // the hello command is used. + if (_inExhaustIsMaster && (!inExhaust || isHello)) { + HelloMetrics::get(getGlobalServiceContext())->decrementNumExhaustIsMaster(); + _inExhaustIsMaster = false; + } + + if (inExhaust) { + if (isHello && !_inExhaustHello) { + HelloMetrics::get(getGlobalServiceContext())->incrementNumExhaustHello(); + _inExhaustHello = inExhaust; + } else if (!isHello && !_inExhaustIsMaster) { + HelloMetrics::get(getGlobalServiceContext())->incrementNumExhaustIsMaster(); + _inExhaustIsMaster = inExhaust; + } + } +} + +} // namespace mongo diff --git a/src/mongo/transport/hello_metrics.h b/src/mongo/transport/hello_metrics.h new file mode 100644 index 00000000000..6d6acf49e2b --- /dev/null +++ b/src/mongo/transport/hello_metrics.h @@ -0,0 +1,107 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include "mongo/db/operation_context.h" +#include "mongo/db/service_context.h" +#include "mongo/platform/atomic_word.h" + +namespace mongo { + +/** + * A decoration on the Session object used to track exhaust metrics. We are + * tracking metrics for "hello" and "isMaster/ismaster" separately while we + * support both commands. This allows us insight into which command is being + * used until we decide to remove support for isMaster completely. + */ +class InExhaustHello { +public: + InExhaustHello() = default; + + InExhaustHello(const InExhaustHello&) = delete; + InExhaustHello& operator=(const InExhaustHello&) = delete; + InExhaustHello(InExhaustHello&&) = delete; + InExhaustHello& operator=(InExhaustHello&&) = delete; + + static InExhaustHello* get(transport::Session* session); + void setInExhaust(bool inExhaust, StringData commandName); + bool getInExhaustIsMaster() const; + bool getInExhaustHello() const; + ~InExhaustHello(); + +private: + bool _inExhaustIsMaster = false; + bool _inExhaustHello = false; +}; + +/** + * Container for awaitable hello and isMaster statistics. We are tracking + * metrics for "hello" and "isMaster/ismaster" separately while we support + * both commands. This allows us insight into which command is being used + * until we decide to remove support for isMaster completely. + */ +class HelloMetrics { + HelloMetrics(const HelloMetrics&) = delete; + HelloMetrics& operator=(const HelloMetrics&) = delete; + HelloMetrics(HelloMetrics&&) = delete; + HelloMetrics& operator=(HelloMetrics&&) = delete; + +public: + HelloMetrics() = default; + + static HelloMetrics* get(ServiceContext* service); + static HelloMetrics* get(OperationContext* opCtx); + + size_t getNumExhaustIsMaster() const; + size_t getNumExhaustHello() const; + + size_t getNumAwaitingTopologyChanges() const; + void incrementNumAwaitingTopologyChanges(); + void decrementNumAwaitingTopologyChanges(); + + void resetNumAwaitingTopologyChanges(); + friend InExhaustHello; + +private: + void incrementNumExhaustIsMaster(); + void decrementNumExhaustIsMaster(); + + void incrementNumExhaustHello(); + void decrementNumExhaustHello(); + + // The number of clients currently waiting in isMaster for a topology change. + AtomicWord _connectionsAwaitingTopologyChanges{0}; + // The number of connections whose last request was an isMaster with exhaustAllowed. + AtomicWord _exhaustIsMasterConnections{0}; + // The number of connections whose last request was a hello with exhaustAllowed. + AtomicWord _exhaustHelloConnections{0}; +}; + +} // namespace mongo diff --git a/src/mongo/transport/ismaster_metrics.cpp b/src/mongo/transport/ismaster_metrics.cpp deleted file mode 100644 index b443fc06d00..00000000000 --- a/src/mongo/transport/ismaster_metrics.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/** - * Copyright (C) 2020-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ -#include "mongo/transport/ismaster_metrics.h" - -namespace mongo { -namespace { -const auto HelloMetricsDecoration = ServiceContext::declareDecoration(); -const auto InExhaustHelloDecoration = transport::Session::declareDecoration(); -} // namespace - -HelloMetrics* HelloMetrics::get(ServiceContext* service) { - return &HelloMetricsDecoration(service); -} - -HelloMetrics* HelloMetrics::get(OperationContext* opCtx) { - return get(opCtx->getServiceContext()); -} - -size_t HelloMetrics::getNumExhaustIsMaster() const { - return _exhaustIsMasterConnections.load(); -} - -void HelloMetrics::incrementNumExhaustIsMaster() { - _exhaustIsMasterConnections.fetchAndAdd(1); -} - -void HelloMetrics::decrementNumExhaustIsMaster() { - _exhaustIsMasterConnections.fetchAndSubtract(1); -} - -size_t HelloMetrics::getNumExhaustHello() const { - return _exhaustHelloConnections.load(); -} - -void HelloMetrics::incrementNumExhaustHello() { - _exhaustHelloConnections.fetchAndAdd(1); -} - -void HelloMetrics::decrementNumExhaustHello() { - _exhaustHelloConnections.fetchAndSubtract(1); -} - -size_t HelloMetrics::getNumAwaitingTopologyChanges() const { - return _connectionsAwaitingTopologyChanges.load(); -} - -void HelloMetrics::incrementNumAwaitingTopologyChanges() { - _connectionsAwaitingTopologyChanges.fetchAndAdd(1); -} - -void HelloMetrics::decrementNumAwaitingTopologyChanges() { - _connectionsAwaitingTopologyChanges.fetchAndSubtract(1); -} - -void HelloMetrics::resetNumAwaitingTopologyChanges() { - _connectionsAwaitingTopologyChanges.store(0); -} - -InExhaustHello* InExhaustHello::get(transport::Session* session) { - return &InExhaustHelloDecoration(session); -} - -InExhaustHello::~InExhaustHello() { - if (_inExhaustIsMaster) { - HelloMetrics::get(getGlobalServiceContext())->decrementNumExhaustIsMaster(); - } - if (_inExhaustHello) { - HelloMetrics::get(getGlobalServiceContext())->decrementNumExhaustHello(); - } -} - -bool InExhaustHello::getInExhaustIsMaster() const { - return _inExhaustIsMaster; -} - -bool InExhaustHello::getInExhaustHello() const { - return _inExhaustHello; -} - -void InExhaustHello::setInExhaust(bool inExhaust, StringData commandName) { - bool isHello = (commandName == "hello"_sd); - - // Transition out of exhaust hello if setting inExhaust to false or if - // the isMaster command is used. - if (_inExhaustHello && (!inExhaust || !isHello)) { - HelloMetrics::get(getGlobalServiceContext())->decrementNumExhaustHello(); - _inExhaustHello = false; - } - - // Transition out of exhaust isMaster if setting inExhaust to false or if - // the hello command is used. - if (_inExhaustIsMaster && (!inExhaust || isHello)) { - HelloMetrics::get(getGlobalServiceContext())->decrementNumExhaustIsMaster(); - _inExhaustIsMaster = false; - } - - if (inExhaust) { - if (isHello && !_inExhaustHello) { - HelloMetrics::get(getGlobalServiceContext())->incrementNumExhaustHello(); - _inExhaustHello = inExhaust; - } else if (!isHello && !_inExhaustIsMaster) { - HelloMetrics::get(getGlobalServiceContext())->incrementNumExhaustIsMaster(); - _inExhaustIsMaster = inExhaust; - } - } -} - -} // namespace mongo diff --git a/src/mongo/transport/ismaster_metrics.h b/src/mongo/transport/ismaster_metrics.h deleted file mode 100644 index 6d6acf49e2b..00000000000 --- a/src/mongo/transport/ismaster_metrics.h +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Copyright (C) 2020-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include "mongo/db/operation_context.h" -#include "mongo/db/service_context.h" -#include "mongo/platform/atomic_word.h" - -namespace mongo { - -/** - * A decoration on the Session object used to track exhaust metrics. We are - * tracking metrics for "hello" and "isMaster/ismaster" separately while we - * support both commands. This allows us insight into which command is being - * used until we decide to remove support for isMaster completely. - */ -class InExhaustHello { -public: - InExhaustHello() = default; - - InExhaustHello(const InExhaustHello&) = delete; - InExhaustHello& operator=(const InExhaustHello&) = delete; - InExhaustHello(InExhaustHello&&) = delete; - InExhaustHello& operator=(InExhaustHello&&) = delete; - - static InExhaustHello* get(transport::Session* session); - void setInExhaust(bool inExhaust, StringData commandName); - bool getInExhaustIsMaster() const; - bool getInExhaustHello() const; - ~InExhaustHello(); - -private: - bool _inExhaustIsMaster = false; - bool _inExhaustHello = false; -}; - -/** - * Container for awaitable hello and isMaster statistics. We are tracking - * metrics for "hello" and "isMaster/ismaster" separately while we support - * both commands. This allows us insight into which command is being used - * until we decide to remove support for isMaster completely. - */ -class HelloMetrics { - HelloMetrics(const HelloMetrics&) = delete; - HelloMetrics& operator=(const HelloMetrics&) = delete; - HelloMetrics(HelloMetrics&&) = delete; - HelloMetrics& operator=(HelloMetrics&&) = delete; - -public: - HelloMetrics() = default; - - static HelloMetrics* get(ServiceContext* service); - static HelloMetrics* get(OperationContext* opCtx); - - size_t getNumExhaustIsMaster() const; - size_t getNumExhaustHello() const; - - size_t getNumAwaitingTopologyChanges() const; - void incrementNumAwaitingTopologyChanges(); - void decrementNumAwaitingTopologyChanges(); - - void resetNumAwaitingTopologyChanges(); - friend InExhaustHello; - -private: - void incrementNumExhaustIsMaster(); - void decrementNumExhaustIsMaster(); - - void incrementNumExhaustHello(); - void decrementNumExhaustHello(); - - // The number of clients currently waiting in isMaster for a topology change. - AtomicWord _connectionsAwaitingTopologyChanges{0}; - // The number of connections whose last request was an isMaster with exhaustAllowed. - AtomicWord _exhaustIsMasterConnections{0}; - // The number of connections whose last request was a hello with exhaustAllowed. - AtomicWord _exhaustHelloConnections{0}; -}; - -} // namespace mongo diff --git a/src/mongo/transport/service_entry_point_impl.cpp b/src/mongo/transport/service_entry_point_impl.cpp index c5876f8a4d7..83bbe73c43a 100644 --- a/src/mongo/transport/service_entry_point_impl.cpp +++ b/src/mongo/transport/service_entry_point_impl.cpp @@ -38,7 +38,7 @@ #include "mongo/db/auth/restriction_environment.h" #include "mongo/db/service_context.h" #include "mongo/logv2/log.h" -#include "mongo/transport/ismaster_metrics.h" +#include "mongo/transport/hello_metrics.h" #include "mongo/transport/service_state_machine.h" #include "mongo/transport/session.h" #include "mongo/util/processinfo.h" -- cgit v1.2.1