summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/isself.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-14 14:26:38 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-14 14:26:38 -0300
commit294bc6ecabf14c09c9bc8644704921dcf97cb44e (patch)
tree279b1e0bab53901a1647ac63c1c724f0f789a663 /src/mongo/db/repl/isself.cpp
parent70be7c27a251621187a1de533462ae2bb1e3bd39 (diff)
parent1e917fd798aa25b7066d4b414b51184f13d5a092 (diff)
Update upstream source from tag 'upstream/6.0.10'debian/6.0.10-1
Update to upstream version '6.0.10' with Debian dir 2d176fa254eee97b139f712fec5709641335a8c3
Diffstat (limited to 'src/mongo/db/repl/isself.cpp')
-rw-r--r--src/mongo/db/repl/isself.cpp37
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,