From f831517ed6ee7e0b866229d45d2149bf23dece60 Mon Sep 17 00:00:00 2001 From: Huayu Ouyang Date: Thu, 24 Sep 2020 21:10:10 +0000 Subject: SERVER-50418-2 Rename IsMasterMetrics to HelloMetrics and InExhaustIsMaster to InExhaustHello --- src/mongo/db/repl/replication_coordinator_impl.cpp | 10 ++-- src/mongo/db/repl/replication_info.cpp | 9 ++-- src/mongo/db/service_entry_point_common.cpp | 4 +- src/mongo/s/commands/cluster_is_master_cmd.cpp | 5 +- src/mongo/s/commands/strategy.cpp | 2 +- src/mongo/s/mongos_topology_coordinator.cpp | 6 +-- src/mongo/transport/ismaster_metrics.cpp | 54 +++++++++++----------- src/mongo/transport/ismaster_metrics.h | 46 ++++++++++-------- src/mongo/transport/service_entry_point_impl.cpp | 7 ++- 9 files changed, 73 insertions(+), 70 deletions(-) diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index d2339838892..7112d853dc7 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -2248,7 +2248,7 @@ std::shared_ptr ReplicationCoordinatorImpl::awaitIsMaste invariant(deadline); const TopologyVersion topologyVersion = _topCoord->getTopologyVersion(); - IsMasterMetrics::get(opCtx)->incrementNumAwaitingTopologyChanges(); + HelloMetrics::get(opCtx)->incrementNumAwaitingTopologyChanges(); lk.unlock(); if (MONGO_unlikely(waitForIsMasterResponse.shouldFail())) { @@ -2282,7 +2282,7 @@ std::shared_ptr ReplicationCoordinatorImpl::awaitIsMaste // Return an IsMasterResponse with the current topology version on timeout when waiting for // a topology change. stdx::lock_guard lk(_mutex); - IsMasterMetrics::get(opCtx)->decrementNumAwaitingTopologyChanges(); + HelloMetrics::get(opCtx)->decrementNumAwaitingTopologyChanges(); // A topology change has not occured within the deadline so horizonString is still a good // indicator of whether we have a valid config. const bool hasValidConfig = horizonString != boost::none; @@ -3926,7 +3926,7 @@ void ReplicationCoordinatorImpl::_errorOnPromisesIfHorizonChanged(WithLock lk, "Received a reconfig that changed the horizon mappings."}); } _sniToValidConfigPromiseMap.clear(); - IsMasterMetrics::get(opCtx)->resetNumAwaitingTopologyChanges(); + HelloMetrics::get(opCtx)->resetNumAwaitingTopologyChanges(); } if (oldIndex >= 0 && newIndex >= 0) { @@ -3940,7 +3940,7 @@ void ReplicationCoordinatorImpl::_errorOnPromisesIfHorizonChanged(WithLock lk, "Received a reconfig that changed the horizon mappings."}); } _createHorizonTopologyChangePromiseMapping(lk); - IsMasterMetrics::get(opCtx)->resetNumAwaitingTopologyChanges(); + HelloMetrics::get(opCtx)->resetNumAwaitingTopologyChanges(); } } } @@ -3987,7 +3987,7 @@ void ReplicationCoordinatorImpl::_fulfillTopologyChangePromise(WithLock lock) { } _sniToValidConfigPromiseMap.clear(); } - IsMasterMetrics::get(getGlobalServiceContext())->resetNumAwaitingTopologyChanges(); + HelloMetrics::get(getGlobalServiceContext())->resetNumAwaitingTopologyChanges(); if (_inQuiesceMode) { // No more isMaster requests will wait for a topology change, so clear _horizonToPromiseMap. diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index cc01efbdc54..5b82d9303ca 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -136,8 +136,8 @@ TopologyVersion appendReplicationInfo(OperationContext* opCtx, // maxAwaitTimeMS. invariant(maxAwaitTimeMS); - IsMasterMetrics::get(opCtx)->incrementNumAwaitingTopologyChanges(); - ON_BLOCK_EXIT([&] { IsMasterMetrics::get(opCtx)->decrementNumAwaitingTopologyChanges(); }); + HelloMetrics::get(opCtx)->incrementNumAwaitingTopologyChanges(); + ON_BLOCK_EXIT([&] { HelloMetrics::get(opCtx)->decrementNumAwaitingTopologyChanges(); }); if (MONGO_unlikely(hangWaitingForIsMasterResponseOnStandalone.shouldFail())) { // Used in tests that wait for this failpoint to be entered to guarantee that the // request is waiting and metrics have been updated. @@ -471,9 +471,8 @@ public: maxAwaitTimeMSField); invariant(clientTopologyVersion); - InExhaustIsMaster::get(opCtx->getClient()->session().get()) - ->setInExhaustIsMaster(true /* inExhaust */, - cmdObj.firstElementFieldNameStringData()); + InExhaustHello::get(opCtx->getClient()->session().get()) + ->setInExhaust(true /* inExhaust */, getName()); if (clientTopologyVersion->getProcessId() == currentTopologyVersion.getProcessId() && clientTopologyVersion->getCounter() == currentTopologyVersion.getCounter()) { diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index bea822092d3..61e7cb46911 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -1452,8 +1452,8 @@ DbResponse receivedCommands(OperationContext* opCtx, if (session) { if (!opCtx->isExhaust() || (c->getName() != "hello"_sd && c->getName() != "isMaster"_sd)) { - InExhaustIsMaster::get(session.get()) - ->setInExhaustIsMaster(false, request.getCommandName()); + InExhaustHello::get(session.get()) + ->setInExhaust(false, request.getCommandName()); } } diff --git a/src/mongo/s/commands/cluster_is_master_cmd.cpp b/src/mongo/s/commands/cluster_is_master_cmd.cpp index 08917ebc0e5..532f29c7e04 100644 --- a/src/mongo/s/commands/cluster_is_master_cmd.cpp +++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp @@ -205,9 +205,8 @@ public: maxAwaitTimeMSField); invariant(clientTopologyVersion); - InExhaustIsMaster::get(opCtx->getClient()->session().get()) - ->setInExhaustIsMaster(true /* inExhaust */, - cmdObj.firstElementFieldNameStringData()); + InExhaustHello::get(opCtx->getClient()->session().get()) + ->setInExhaust(true /* inExhaust */, getName()); if (clientTopologyVersion->getProcessId() == currentMongosTopologyVersion.getProcessId() && diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index 3f4c0107662..d2b88b8c78f 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -317,7 +317,7 @@ void runCommand(OperationContext* opCtx, if (session) { if (!opCtx->isExhaust() || (command->getName() != "hello"_sd && command->getName() != "isMaster"_sd)) { - InExhaustIsMaster::get(session.get())->setInExhaustIsMaster(false, commandName); + InExhaustHello::get(session.get())->setInExhaust(false, commandName); } } diff --git a/src/mongo/s/mongos_topology_coordinator.cpp b/src/mongo/s/mongos_topology_coordinator.cpp index d1c27a5a3ac..e65733734ac 100644 --- a/src/mongo/s/mongos_topology_coordinator.cpp +++ b/src/mongo/s/mongos_topology_coordinator.cpp @@ -150,7 +150,7 @@ std::shared_ptr MongosTopologyCoordinator::awaitIs // deadline must also be not none. invariant(deadline); - IsMasterMetrics::get(opCtx)->incrementNumAwaitingTopologyChanges(); + HelloMetrics::get(opCtx)->incrementNumAwaitingTopologyChanges(); lk.unlock(); if (MONGO_unlikely(waitForIsMasterResponse.shouldFail())) { @@ -179,7 +179,7 @@ std::shared_ptr MongosTopologyCoordinator::awaitIs // Return a MongosIsMasterResponse with the current topology version on timeout when // waiting for a topology change. stdx::lock_guard lk(_mutex); - IsMasterMetrics::get(opCtx)->decrementNumAwaitingTopologyChanges(); + HelloMetrics::get(opCtx)->decrementNumAwaitingTopologyChanges(); return _makeIsMasterResponse(lk); } @@ -205,7 +205,7 @@ void MongosTopologyCoordinator::enterQuiesceModeAndWait(OperationContext* opCtx, // Reset counter to 0 since we will respond to all waiting isMaster requests with an error. // All new isMaster requests will immediately fail with ShutdownInProgress. - IsMasterMetrics::get(getGlobalServiceContext())->resetNumAwaitingTopologyChanges(); + HelloMetrics::get(getGlobalServiceContext())->resetNumAwaitingTopologyChanges(); } if (MONGO_unlikely(hangDuringQuiesceMode.shouldFail())) { diff --git a/src/mongo/transport/ismaster_metrics.cpp b/src/mongo/transport/ismaster_metrics.cpp index c1a4d421b73..b443fc06d00 100644 --- a/src/mongo/transport/ismaster_metrics.cpp +++ b/src/mongo/transport/ismaster_metrics.cpp @@ -30,102 +30,102 @@ namespace mongo { namespace { -const auto IsMasterMetricsDecoration = ServiceContext::declareDecoration(); -const auto InExhaustIsMasterDecoration = transport::Session::declareDecoration(); +const auto HelloMetricsDecoration = ServiceContext::declareDecoration(); +const auto InExhaustHelloDecoration = transport::Session::declareDecoration(); } // namespace -IsMasterMetrics* IsMasterMetrics::get(ServiceContext* service) { - return &IsMasterMetricsDecoration(service); +HelloMetrics* HelloMetrics::get(ServiceContext* service) { + return &HelloMetricsDecoration(service); } -IsMasterMetrics* IsMasterMetrics::get(OperationContext* opCtx) { +HelloMetrics* HelloMetrics::get(OperationContext* opCtx) { return get(opCtx->getServiceContext()); } -size_t IsMasterMetrics::getNumExhaustIsMaster() const { +size_t HelloMetrics::getNumExhaustIsMaster() const { return _exhaustIsMasterConnections.load(); } -void IsMasterMetrics::incrementNumExhaustIsMaster() { +void HelloMetrics::incrementNumExhaustIsMaster() { _exhaustIsMasterConnections.fetchAndAdd(1); } -void IsMasterMetrics::decrementNumExhaustIsMaster() { +void HelloMetrics::decrementNumExhaustIsMaster() { _exhaustIsMasterConnections.fetchAndSubtract(1); } -size_t IsMasterMetrics::getNumExhaustHello() const { +size_t HelloMetrics::getNumExhaustHello() const { return _exhaustHelloConnections.load(); } -void IsMasterMetrics::incrementNumExhaustHello() { +void HelloMetrics::incrementNumExhaustHello() { _exhaustHelloConnections.fetchAndAdd(1); } -void IsMasterMetrics::decrementNumExhaustHello() { +void HelloMetrics::decrementNumExhaustHello() { _exhaustHelloConnections.fetchAndSubtract(1); } -size_t IsMasterMetrics::getNumAwaitingTopologyChanges() const { +size_t HelloMetrics::getNumAwaitingTopologyChanges() const { return _connectionsAwaitingTopologyChanges.load(); } -void IsMasterMetrics::incrementNumAwaitingTopologyChanges() { +void HelloMetrics::incrementNumAwaitingTopologyChanges() { _connectionsAwaitingTopologyChanges.fetchAndAdd(1); } -void IsMasterMetrics::decrementNumAwaitingTopologyChanges() { +void HelloMetrics::decrementNumAwaitingTopologyChanges() { _connectionsAwaitingTopologyChanges.fetchAndSubtract(1); } -void IsMasterMetrics::resetNumAwaitingTopologyChanges() { +void HelloMetrics::resetNumAwaitingTopologyChanges() { _connectionsAwaitingTopologyChanges.store(0); } -InExhaustIsMaster* InExhaustIsMaster::get(transport::Session* session) { - return &InExhaustIsMasterDecoration(session); +InExhaustHello* InExhaustHello::get(transport::Session* session) { + return &InExhaustHelloDecoration(session); } -InExhaustIsMaster::~InExhaustIsMaster() { +InExhaustHello::~InExhaustHello() { if (_inExhaustIsMaster) { - IsMasterMetrics::get(getGlobalServiceContext())->decrementNumExhaustIsMaster(); + HelloMetrics::get(getGlobalServiceContext())->decrementNumExhaustIsMaster(); } if (_inExhaustHello) { - IsMasterMetrics::get(getGlobalServiceContext())->decrementNumExhaustHello(); + HelloMetrics::get(getGlobalServiceContext())->decrementNumExhaustHello(); } } -bool InExhaustIsMaster::getInExhaustIsMaster() const { +bool InExhaustHello::getInExhaustIsMaster() const { return _inExhaustIsMaster; } -bool InExhaustIsMaster::getInExhaustHello() const { +bool InExhaustHello::getInExhaustHello() const { return _inExhaustHello; } -void InExhaustIsMaster::setInExhaustIsMaster(bool inExhaust, StringData commandName) { +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)) { - IsMasterMetrics::get(getGlobalServiceContext())->decrementNumExhaustHello(); + 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)) { - IsMasterMetrics::get(getGlobalServiceContext())->decrementNumExhaustIsMaster(); + HelloMetrics::get(getGlobalServiceContext())->decrementNumExhaustIsMaster(); _inExhaustIsMaster = false; } if (inExhaust) { if (isHello && !_inExhaustHello) { - IsMasterMetrics::get(getGlobalServiceContext())->incrementNumExhaustHello(); + HelloMetrics::get(getGlobalServiceContext())->incrementNumExhaustHello(); _inExhaustHello = inExhaust; } else if (!isHello && !_inExhaustIsMaster) { - IsMasterMetrics::get(getGlobalServiceContext())->incrementNumExhaustIsMaster(); + HelloMetrics::get(getGlobalServiceContext())->incrementNumExhaustIsMaster(); _inExhaustIsMaster = inExhaust; } } diff --git a/src/mongo/transport/ismaster_metrics.h b/src/mongo/transport/ismaster_metrics.h index ed4d1a369bd..6d6acf49e2b 100644 --- a/src/mongo/transport/ismaster_metrics.h +++ b/src/mongo/transport/ismaster_metrics.h @@ -36,22 +36,25 @@ namespace mongo { /** - * A decoration on the Session object used to track exhaust isMaster metrics. + * 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 InExhaustIsMaster { +class InExhaustHello { public: - InExhaustIsMaster() = default; + InExhaustHello() = default; - InExhaustIsMaster(const InExhaustIsMaster&) = delete; - InExhaustIsMaster& operator=(const InExhaustIsMaster&) = delete; - InExhaustIsMaster(InExhaustIsMaster&&) = delete; - InExhaustIsMaster& operator=(InExhaustIsMaster&&) = delete; + InExhaustHello(const InExhaustHello&) = delete; + InExhaustHello& operator=(const InExhaustHello&) = delete; + InExhaustHello(InExhaustHello&&) = delete; + InExhaustHello& operator=(InExhaustHello&&) = delete; - static InExhaustIsMaster* get(transport::Session* session); - void setInExhaustIsMaster(bool inExhaust, StringData commandName); + static InExhaustHello* get(transport::Session* session); + void setInExhaust(bool inExhaust, StringData commandName); bool getInExhaustIsMaster() const; bool getInExhaustHello() const; - ~InExhaustIsMaster(); + ~InExhaustHello(); private: bool _inExhaustIsMaster = false; @@ -59,19 +62,22 @@ private: }; /** - * Container for awaitable isMaster statistics. + * 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 IsMasterMetrics { - IsMasterMetrics(const IsMasterMetrics&) = delete; - IsMasterMetrics& operator=(const IsMasterMetrics&) = delete; - IsMasterMetrics(IsMasterMetrics&&) = delete; - IsMasterMetrics& operator=(IsMasterMetrics&&) = delete; +class HelloMetrics { + HelloMetrics(const HelloMetrics&) = delete; + HelloMetrics& operator=(const HelloMetrics&) = delete; + HelloMetrics(HelloMetrics&&) = delete; + HelloMetrics& operator=(HelloMetrics&&) = delete; public: - IsMasterMetrics() = default; + HelloMetrics() = default; - static IsMasterMetrics* get(ServiceContext* service); - static IsMasterMetrics* get(OperationContext* opCtx); + static HelloMetrics* get(ServiceContext* service); + static HelloMetrics* get(OperationContext* opCtx); size_t getNumExhaustIsMaster() const; size_t getNumExhaustHello() const; @@ -81,7 +87,7 @@ public: void decrementNumAwaitingTopologyChanges(); void resetNumAwaitingTopologyChanges(); - friend InExhaustIsMaster; + friend InExhaustHello; private: void incrementNumExhaustIsMaster(); diff --git a/src/mongo/transport/service_entry_point_impl.cpp b/src/mongo/transport/service_entry_point_impl.cpp index 75dc8f593dc..c5876f8a4d7 100644 --- a/src/mongo/transport/service_entry_point_impl.cpp +++ b/src/mongo/transport/service_entry_point_impl.cpp @@ -270,11 +270,10 @@ void ServiceEntryPointImpl::appendStats(BSONObjBuilder* bob) const { if (auto sc = getGlobalServiceContext()) { bob->append("active", static_cast(sc->getActiveClientOperations())); bob->append("exhaustIsMaster", - static_cast(IsMasterMetrics::get(sc)->getNumExhaustIsMaster())); - bob->append("exhaustHello", - static_cast(IsMasterMetrics::get(sc)->getNumExhaustHello())); + static_cast(HelloMetrics::get(sc)->getNumExhaustIsMaster())); + bob->append("exhaustHello", static_cast(HelloMetrics::get(sc)->getNumExhaustHello())); bob->append("awaitingTopologyChanges", - static_cast(IsMasterMetrics::get(sc)->getNumAwaitingTopologyChanges())); + static_cast(HelloMetrics::get(sc)->getNumAwaitingTopologyChanges())); } if (_adminInternalPool) { -- cgit v1.2.1