0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-45396 Fix the 'me' field in isMaster responses when using splithorizon

This commit is contained in:
Tess Avitabile 2020-01-08 20:41:41 +00:00 committed by evergreen
parent d205919f8a
commit a1a1e4f0c1
2 changed files with 22 additions and 3 deletions

View File

@ -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");

View File

@ -1777,7 +1777,7 @@ void TopologyCoordinator::fillIsMasterForReplSet(std::shared_ptr<IsMasterRespons
response->addTag(tagKey, tagConfig.getTagValue(*tag));
}
}
response->setMe(selfConfig.getHostAndPort());
response->setMe(selfConfig.getHostAndPort(horizonString));
if (_iAmPrimary()) {
response->setElectionId(_electionId);
}