diff options
Diffstat (limited to 'src/mongo/db/repl/isself.cpp')
| -rw-r--r-- | src/mongo/db/repl/isself.cpp | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/mongo/db/repl/isself.cpp b/src/mongo/db/repl/isself.cpp index 243a1c065f0..1e0ec7dfab7 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,18 +229,30 @@ 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 - - // 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 - // a replica set configuration document, but the 'isMaster' command requires a lock on the - // replication coordinator to execute. As such we call we call 'connectSocketOnly', which - // does not call 'isMaster'. + double timeoutSeconds = static_cast<double>(durationCount<Milliseconds>(timeout)) / 1000.0; + conn.setSoTimeout(timeoutSeconds); + + // We need to avoid the "hello" call triggered by a normal connect, which would cause a + // deadlock. 'isSelf' is called by the Replication Coordinator when validating a replica set + // configuration document, but the "hello" command requires a lock on the replication + // coordinator to execute. As such we call we call 'connectSocketOnly', which does not call + // "hello". auto connectSocketResult = conn.connectSocketOnly(hostAndPort, boost::none); if (!connectSocketResult.isOK()) { LOGV2(4834700, |
