summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/replication_info.cpp
diff options
context:
space:
mode:
authorJason Chan <jason.chan@mongodb.com>2020-02-21 22:41:38 +0000
committerevergreen <evergreen@mongodb.com>2020-02-21 22:41:38 +0000
commitdb649073af2b6dac30b5d207ffa484f7d8cdc2b2 (patch)
treef93ea76d161cf3732eeaefefecea5a9788c22063 /src/mongo/db/repl/replication_info.cpp
parent1315b6fdd3ade546c37364bcd4b0ba224adb7f58 (diff)
downloadmongo-db649073af2b6dac30b5d207ffa484f7d8cdc2b2.tar.gz
SERVER-44522 serverStatus metrics for awaitable isMaster
Diffstat (limited to 'src/mongo/db/repl/replication_info.cpp')
-rw-r--r--src/mongo/db/repl/replication_info.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp
index d5c183c365f..fd8ce22e8d0 100644
--- a/src/mongo/db/repl/replication_info.cpp
+++ b/src/mongo/db/repl/replication_info.cpp
@@ -63,13 +63,18 @@
#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/client_metadata.h"
#include "mongo/rpc/metadata/client_metadata_ismaster.h"
+#include "mongo/transport/ismaster_metrics.h"
#include "mongo/util/decimal_counter.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/map_util.h"
namespace mongo {
+// Hangs in the beginning of each isMaster command when set.
MONGO_FAIL_POINT_DEFINE(waitInIsMaster);
+// Awaitable isMaster requests with the proper topologyVersions will sleep for maxAwaitTimeMS on
+// standalones. This failpoint will hang right before doing this sleep when set.
+MONGO_FAIL_POINT_DEFINE(hangWaitingForIsMasterResponseOnStandalone);
using std::list;
using std::string;
@@ -121,6 +126,15 @@ TopologyVersion appendReplicationInfo(OperationContext* opCtx,
// The topologyVersion never changes on a running standalone process, so just sleep for
// maxAwaitTimeMS.
invariant(maxAwaitTimeMS);
+
+ IsMasterMetrics::get(opCtx)->incrementNumAwaitingTopologyChanges();
+ ON_BLOCK_EXIT([&] { IsMasterMetrics::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.
+ LOGV2(31462, "Hanging due to hangWaitingForIsMasterResponseOnStandalone failpoint.");
+ hangWaitingForIsMasterResponseOnStandalone.pauseWhileSet(opCtx);
+ }
opCtx->sleepFor(Milliseconds(*maxAwaitTimeMS));
}
@@ -499,6 +513,9 @@ public:
maxAwaitTimeMSField);
invariant(clientTopologyVersion);
+ InExhaustIsMaster::get(opCtx->getClient()->session().get())
+ ->setInExhaustIsMaster(true /* inExhaustIsMaster */);
+
if (clientTopologyVersion->getProcessId() == currentTopologyVersion.getProcessId() &&
clientTopologyVersion->getCounter() == currentTopologyVersion.getCounter()) {
// Indicate that an exhaust message should be generated and the previous BSONObj