summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2020-01-09 14:22:56 +0000
committerevergreen <evergreen@mongodb.com>2020-01-09 14:22:56 +0000
commit681bdb25525951fa298d339dd4b2ac50c95b05e8 (patch)
tree419dde9be86ff069e97fcd59d6096143c2e82b1f
parent02657b811d5da15abf2158ac75126115d6954106 (diff)
downloadmongo-681bdb25525951fa298d339dd4b2ac50c95b05e8.tar.gz
SERVER-45396 Fix the 'me' field in isMaster responses when using splithorizon
(cherry picked from commit a1a1e4f0c14ab71a5fc8bc7913af25571089b65f)
-rw-r--r--jstests/ssl/repl_ssl_split_horizon.js23
-rw-r--r--src/mongo/db/repl/topology_coordinator.cpp2
2 files changed, 22 insertions, 3 deletions
diff --git a/jstests/ssl/repl_ssl_split_horizon.js b/jstests/ssl/repl_ssl_split_horizon.js
index 19e2648df6f..fe4f4272098 100644
--- a/jstests/ssl/repl_ssl_split_horizon.js
+++ b/jstests/ssl/repl_ssl_split_horizon.js
@@ -108,6 +108,11 @@ replTest.initiate(config);
var checkExpectedHorizon = function(url, memberIndex, expectedHostname) {
// Run isMaster in the shell and check that we get the expected hostname back
+ const assertion = (memberIndex === "me")
+ ? ("assert(db.runCommand({isMaster: 1})['me'] == '" + expectedHostname + "')")
+ : ("assert(db.runCommand({isMaster: 1})['hosts'][" + memberIndex + "] == '" +
+ expectedHostname + "')");
+
var argv = [
'env',
"HOSTALIASES=" + hostsFile,
@@ -115,8 +120,7 @@ var checkExpectedHorizon = function(url, memberIndex, expectedHostname) {
'./mongo',
url,
'--eval',
- ("assert(db.runCommand({isMaster: 1})['hosts'][" + memberIndex + "] == '" +
- expectedHostname + "')")
+ assertion
];
return runMongoProgram(...argv);
};
@@ -127,6 +131,9 @@ jsTestLog(`URL without horizon: ${defaultURL}`);
assert.eq(checkExpectedHorizon(defaultURL, 0, node0localHostname),
0,
"localhost does not return horizon");
+assert.eq(checkExpectedHorizon(defaultURL, "me", node0localHostname),
+ 0,
+ "localhost does not return horizon");
assert.eq(checkExpectedHorizon(defaultURL, 1, node1localHostname),
0,
"localhost does not return horizon");
@@ -137,6 +144,9 @@ jsTestLog(`URL with horizon: ${horizonURL}`);
assert.eq(checkExpectedHorizon(horizonURL, 0, node0horizonHostname),
0,
"does not return horizon as expected");
+assert.eq(checkExpectedHorizon(horizonURL, "me", node0horizonHostname),
+ 0,
+ "does not return horizon as expected");
assert.eq(checkExpectedHorizon(horizonURL, 1, node1horizonHostname),
0,
"does not return horizon as expected");
@@ -148,6 +158,9 @@ jsTestLog(`URL with horizon: ${horizonMissingURL}`);
assert.eq(checkExpectedHorizon(horizonMissingURL, 0, node0localHostname),
0,
"does not return localhost as expected");
+assert.eq(checkExpectedHorizon(horizonMissingURL, "me", node0localHostname),
+ 0,
+ "does not return localhost as expected");
assert.eq(checkExpectedHorizon(horizonMissingURL, 1, node1localHostname),
0,
"does not return localhost as expected");
@@ -166,6 +179,9 @@ jsTestLog(`URL with horizon: ${horizonMissingURL}`);
assert.eq(checkExpectedHorizon(horizonMissingURL, 0, node0horizonMissingHostname),
0,
"does not return horizon as expected");
+assert.eq(checkExpectedHorizon(horizonMissingURL, "me", node0horizonMissingHostname),
+ 0,
+ "does not return horizon as expected");
assert.eq(checkExpectedHorizon(horizonMissingURL, 1, node1horizonMissingHostname),
0,
"does not return horizon as expected");
@@ -187,6 +203,9 @@ jsTestLog(`URL with horizon using different port: ${horizonDifferentPortURL}`);
assert.eq(checkExpectedHorizon(horizonDifferentPortURL, 0, node0horizonHostnameDifferentPort),
0,
"does not return horizon as expected");
+assert.eq(checkExpectedHorizon(horizonDifferentPortURL, "me", node0horizonHostnameDifferentPort),
+ 0,
+ "does not return horizon as expected");
assert.eq(checkExpectedHorizon(horizonDifferentPortURL, 1, node1horizonHostnameDifferentPort),
0,
"does not return horizon as expected");
diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp
index 8dd4927061b..8325303d6e0 100644
--- a/src/mongo/db/repl/topology_coordinator.cpp
+++ b/src/mongo/db/repl/topology_coordinator.cpp
@@ -1759,7 +1759,7 @@ void TopologyCoordinator::fillIsMasterForReplSet(IsMasterResponse* const respons
response->addTag(tagKey, tagConfig.getTagValue(*tag));
}
}
- response->setMe(selfConfig.getHostAndPort());
+ response->setMe(selfConfig.getHostAndPort(horizon));
if (_iAmPrimary()) {
response->setElectionId(_electionId);
}