diff options
Diffstat (limited to 'src/mongo/db/repl/isself.cpp')
-rw-r--r-- | src/mongo/db/repl/isself.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/mongo/db/repl/isself.cpp b/src/mongo/db/repl/isself.cpp index 243a1c065f0..a9f776e5f74 100644 --- a/src/mongo/db/repl/isself.cpp +++ b/src/mongo/db/repl/isself.cpp @@ -163,10 +163,17 @@ std::vector<std::string> getAddrsForHost(const std::string& iporhost, } // namespace -bool isSelf(const HostAndPort& hostAndPort, ServiceContext* const ctx) { +bool isSelf(const HostAndPort& hostAndPort, ServiceContext* const ctx, Milliseconds timeout) { + if (isSelfFastPath(hostAndPort)) { + return true; + } + return isSelfSlowPath(hostAndPort, ctx, timeout); +} + +bool isSelfFastPath(const HostAndPort& hostAndPort) { if (MONGO_unlikely(failIsSelfCheck.shouldFail())) { LOGV2(356490, - "failIsSelfCheck failpoint activated, returning false from isSelf", + "failIsSelfCheck failpoint activated, returning false from isSelfFastPath", "hostAndPort"_attr = hostAndPort); return false; } @@ -222,12 +229,24 @@ bool isSelf(const HostAndPort& hostAndPort, ServiceContext* const ctx) { } } } + return false; +} +bool isSelfSlowPath(const HostAndPort& hostAndPort, + ServiceContext* const ctx, + Milliseconds timeout) { ctx->waitForStartupComplete(); + if (MONGO_unlikely(failIsSelfCheck.shouldFail())) { + LOGV2(6605000, + "failIsSelfCheck failpoint activated, returning false from isSelfSlowPath", + "hostAndPort"_attr = hostAndPort); + return false; + } try { DBClientConnection conn; - conn.setSoTimeout(30); // 30 second timeout + double timeoutSeconds = static_cast<double>(durationCount<Milliseconds>(timeout)) / 1000.0; + conn.setSoTimeout(timeoutSeconds); // We need to avoid the isMaster call triggered by a normal connect, which would // cause a deadlock. 'isSelf' is called by the Replication Coordinator when validating |