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

SERVER-22287 check heartbeat message instead of logs for inconsistent replica set id error

This commit is contained in:
Benety Goh 2016-02-05 17:06:03 -05:00
parent 87bc474120
commit 38cd69968a

View File

@ -362,7 +362,6 @@ TEST_F(ReplCoordHBV1Test, ArbiterRecordsCommittedOpTimeFromHeartbeatMetadata) {
test(olderOpTime, committedOpTime);
}
/*
TEST_F(ReplCoordHBV1Test, IgnoreTheContentsOfMetadataWhenItsReplicaSetIdDoesNotMatchOurs) {
// Tests that a secondary node will not update its committed optime from the heartbeat metadata
// if the replica set ID is inconsistent with the existing configuration.
@ -380,50 +379,69 @@ TEST_F(ReplCoordHBV1Test, IgnoreTheContentsOfMetadataWhenItsReplicaSetIdDoesNotM
auto rsConfig = getReplCoord()->getConfig();
// Prepare heartbeat response.
OID unexpectedId = OID::gen();
OpTime opTime{Timestamp{10, 10}, 10};
ReplicationExecutor::ResponseStatus heartbeatResponse(ErrorCodes::InternalError,
"not initialized");
{
ReplSetHeartbeatResponse hbResp;
hbResp.setSetName(rsConfig.getReplSetName());
hbResp.setState(MemberState::RS_PRIMARY);
hbResp.setConfigVersion(rsConfig.getConfigVersion());
BSONObjBuilder responseBuilder;
responseBuilder << "ok" << 1;
hbResp.addToBSON(&responseBuilder, true);
rpc::ReplSetMetadata metadata(
opTime.getTerm(), opTime, opTime, rsConfig.getConfigVersion(), unexpectedId, 1, -1);
BSONObjBuilder metadataBuilder;
metadata.writeToMetadata(&metadataBuilder);
heartbeatResponse = makeResponseStatus(responseBuilder.obj(), metadataBuilder.obj());
}
// process heartbeat
enterNetwork();
auto net = getNet();
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
log() << request.target.toString() << " processing " << request.cmdObj;
ASSERT_EQUALS(host2, request.target);
ReplSetHeartbeatResponse hbResp;
hbResp.setSetName(rsConfig.getReplSetName());
hbResp.setState(MemberState::RS_PRIMARY);
hbResp.setConfigVersion(rsConfig.getConfigVersion());
BSONObjBuilder responseBuilder;
responseBuilder << "ok" << 1;
hbResp.addToBSON(&responseBuilder, true);
OID unexpectedId = OID::gen();
OpTime opTime{Timestamp{10, 10}, 10};
rpc::ReplSetMetadata metadata(
opTime.getTerm(), opTime, opTime, rsConfig.getConfigVersion(), unexpectedId, 1, -1);
BSONObjBuilder metadataBuilder;
metadata.writeToMetadata(&metadataBuilder);
net->scheduleResponse(
noi, net->now(), makeResponseStatus(responseBuilder.obj(), metadataBuilder.obj()));
startCapturingLogMessages();
net->runReadyNetworkOperations();
stopCapturingLogMessages();
while (net->hasReadyRequests()) {
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
if (request.target == host2 &&
request.cmdObj.firstElement().fieldNameStringData() == "replSetHeartbeat") {
log() << request.target.toString() << " processing " << request.cmdObj;
net->scheduleResponse(noi, net->now(), heartbeatResponse);
} else {
log() << "blackholing request to " << request.target.toString() << ": "
<< request.cmdObj;
net->blackHole(noi);
}
net->runReadyNetworkOperations();
}
exitNetwork();
ASSERT_NOT_EQUALS(opTime, getReplCoord()->getLastCommittedOpTime());
ASSERT_NOT_EQUALS(opTime.getTerm(), getTopoCoord().getTerm());
ASSERT_EQUALS(1,
countLogLinesContaining(
str::stream()
<< "Error in heartbeat request to node2:12345; InvalidReplicaSetConfig: "
"replica set IDs do not match, ours: " << rsConfig.getReplicaSetId()
<< "; remote node's: " << unexpectedId));
BSONObjBuilder statusBuilder;
ASSERT_OK(getReplCoord()->processReplSetGetStatus(&statusBuilder));
auto statusObj = statusBuilder.obj();
unittest::log() << "replica set status = " << statusObj;
ASSERT_EQ(mongo::Array, statusObj["members"].type());
auto members = statusObj["members"].Array();
ASSERT_EQ(2U, members.size());
ASSERT_TRUE(members[1].isABSONObj());
auto member = members[1].Obj();
ASSERT_EQ(host2, HostAndPort(member["name"].String()));
ASSERT_EQ(MemberState(MemberState::RS_DOWN).toString(),
MemberState(member["state"].numberInt()).toString());
ASSERT_EQ(member["lastHeartbeatMessage"].String(),
std::string(str::stream()
<< "replica set IDs do not match, ours: " << rsConfig.getReplicaSetId()
<< "; remote node's: " << unexpectedId));
}
*/
} // namespace
} // namespace repl