summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/repl/check_quorum_for_config_change.cpp9
-rw-r--r--src/mongo/db/repl/check_quorum_for_config_change_test.cpp86
-rw-r--r--src/mongo/db/repl/member_data.h6
-rw-r--r--src/mongo/db/repl/oplog.h1
-rw-r--r--src/mongo/db/repl/repl_set_heartbeat_response.cpp75
-rw-r--r--src/mongo/db/repl/repl_set_heartbeat_response.h82
-rw-r--r--src/mongo/db/repl/repl_set_heartbeat_response_test.cpp293
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_test.cpp44
-rw-r--r--src/mongo/db/repl/topology_coordinator.cpp24
-rw-r--r--src/mongo/db/repl/topology_coordinator.h5
-rw-r--r--src/mongo/db/repl/topology_coordinator_v1_test.cpp60
11 files changed, 29 insertions, 656 deletions
diff --git a/src/mongo/db/repl/check_quorum_for_config_change.cpp b/src/mongo/db/repl/check_quorum_for_config_change.cpp
index 1c4bbaa6c68..403f7f8303a 100644
--- a/src/mongo/db/repl/check_quorum_for_config_change.cpp
+++ b/src/mongo/db/repl/check_quorum_for_config_change.cpp
@@ -238,15 +238,6 @@ void QuorumChecker::_tabulateHeartbeatResponse(const RemoteCommandRequest& reque
}
}
- const bool isInitialConfig = _rsConfig->getConfigVersion() == 1;
- if (isInitialConfig && hbResp.hasData()) {
- std::string message = str::stream() << "'" << request.target.toString()
- << "' has data already, cannot initiate set.";
- _vetoStatus = Status(ErrorCodes::CannotInitializeNodeWithData, message);
- warning() << message;
- return;
- }
-
for (int i = 0; i < _rsConfig->getNumMembers(); ++i) {
const MemberConfig& memberConfig = _rsConfig->getMemberAt(i);
if (memberConfig.getHostAndPort() != request.target) {
diff --git a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp
index 9df73af6b08..3a32a837ff9 100644
--- a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp
+++ b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp
@@ -381,11 +381,14 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetNameMismatch) {
ASSERT(seenHosts.insert(request.target).second) << "Already saw "
<< request.target.toString();
if (request.target == HostAndPort("h4", 1)) {
- getNet()->scheduleResponse(noi,
- startDate + Milliseconds(10),
- (RemoteCommandResponse(BSON("ok" << 0 << "mismatch" << true),
- BSONObj(),
- Milliseconds(8))));
+ getNet()->scheduleResponse(
+ noi,
+ startDate + Milliseconds(10),
+ (RemoteCommandResponse(
+ BSON("ok" << 0 << "code" << ErrorCodes::InconsistentReplicaSetNames << "errmsg"
+ << "replica set name doesn't match."),
+ BSONObj(),
+ Milliseconds(8))));
} else {
getNet()->scheduleResponse(
noi,
@@ -621,66 +624,6 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToInitializedNodeOnlyOneRespo
ASSERT_REASON_CONTAINS(status, "h5:1");
}
-TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToNodeWithData) {
- // In this test, "we" are host "h3:1". Only node "h5" responds before the test completes,
- // and quorum check fails because "h5" declares that it has data already.
-
- const ReplSetConfig rsConfig =
- assertMakeRSConfig(BSON("_id"
- << "rs0"
- << "version"
- << 1
- << "protocolVersion"
- << 1
- << "members"
- << BSON_ARRAY(BSON("_id" << 1 << "host"
- << "h1:1")
- << BSON("_id" << 2 << "host"
- << "h2:1")
- << BSON("_id" << 3 << "host"
- << "h3:1")
- << BSON("_id" << 4 << "host"
- << "h4:1")
- << BSON("_id" << 5 << "host"
- << "h5:1"))));
- const int myConfigIndex = 2;
- const BSONObj hbRequest = makeHeartbeatRequest(rsConfig, myConfigIndex);
-
- startQuorumCheck(rsConfig, myConfigIndex);
- const Date_t startDate = getNet()->now();
- const int numCommandsExpected = rsConfig.getNumMembers() - 1;
- stdx::unordered_set<HostAndPort> seenHosts;
- getNet()->enterNetwork();
- for (int i = 0; i < numCommandsExpected; ++i) {
- const NetworkInterfaceMock::NetworkOperationIterator noi = getNet()->getNextReadyRequest();
- const RemoteCommandRequest& request = noi->getRequest();
- ASSERT_EQUALS("admin", request.dbname);
- ASSERT_BSONOBJ_EQ(hbRequest, request.cmdObj);
- ASSERT(seenHosts.insert(request.target).second) << "Already saw "
- << request.target.toString();
- ReplSetHeartbeatResponse hbResp;
- hbResp.setConfigVersion(0);
- hbResp.noteHasData();
- if (request.target == HostAndPort("h5", 1)) {
- getNet()->scheduleResponse(
- noi,
- startDate + Milliseconds(10),
- (RemoteCommandResponse(hbResp.toBSON(false), BSONObj(), Milliseconds(8))));
- } else {
- getNet()->blackHole(noi);
- }
- }
- getNet()->runUntil(startDate + Milliseconds(10));
- getNet()->exitNetwork();
- Status status = waitForQuorumCheck();
- ASSERT_EQUALS(ErrorCodes::CannotInitializeNodeWithData, status);
- ASSERT_REASON_CONTAINS(status, "has data already");
- ASSERT_NOT_REASON_CONTAINS(status, "h1:1");
- ASSERT_NOT_REASON_CONTAINS(status, "h2:1");
- ASSERT_NOT_REASON_CONTAINS(status, "h3:1");
- ASSERT_NOT_REASON_CONTAINS(status, "h4:1");
- ASSERT_REASON_CONTAINS(status, "h5:1");
-}
TEST_F(CheckQuorumForReconfig, QuorumCheckVetoedDueToHigherConfigVersion) {
// In this test, "we" are host "h3:1". The request to "h2" does not arrive before the end
// of the test, and the request to "h1" comes back indicating a higher config version.
@@ -772,11 +715,14 @@ TEST_F(CheckQuorumForReconfig, QuorumCheckVetoedDueToIncompatibleSetName) {
ASSERT(seenHosts.insert(request.target).second) << "Already saw "
<< request.target.toString();
if (request.target == HostAndPort("h2", 1)) {
- getNet()->scheduleResponse(noi,
- startDate + Milliseconds(10),
- (RemoteCommandResponse(BSON("ok" << 0 << "mismatch" << true),
- BSONObj(),
- Milliseconds(8))));
+ getNet()->scheduleResponse(
+ noi,
+ startDate + Milliseconds(10),
+ (RemoteCommandResponse(
+ BSON("ok" << 0 << "code" << ErrorCodes::InconsistentReplicaSetNames << "errmsg"
+ << "replica set name doesn't match."),
+ BSONObj(),
+ Milliseconds(8))));
} else {
getNet()->scheduleResponse(
noi, startDate + Milliseconds(10), {ErrorCodes::NoSuchKey, "No response"});
diff --git a/src/mongo/db/repl/member_data.h b/src/mongo/db/repl/member_data.h
index ab484a64469..1892a11699c 100644
--- a/src/mongo/db/repl/member_data.h
+++ b/src/mongo/db/repl/member_data.h
@@ -89,12 +89,6 @@ public:
return _lastResponse.getTerm();
}
- // Returns true if the last heartbeat data explicilty stated that the node
- // is not electable.
- bool isUnelectable() const {
- return _lastResponse.hasIsElectable() && !_lastResponse.isElectable();
- }
-
// Was this member up for the last heartbeat?
bool up() const {
return _health > 0;
diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h
index ef96a304626..b209b695fa3 100644
--- a/src/mongo/db/repl/oplog.h
+++ b/src/mongo/db/repl/oplog.h
@@ -91,7 +91,6 @@ void createOplog(OperationContext* opCtx, const std::string& oplogCollectionName
/*
* Shortcut for above function using oplogCollectionName = _oplogCollectionName,
- * and replEnabled = replCoord::isReplSet();
*/
void createOplog(OperationContext* opCtx);
diff --git a/src/mongo/db/repl/repl_set_heartbeat_response.cpp b/src/mongo/db/repl/repl_set_heartbeat_response.cpp
index 6aae6929de6..fa08f5d2aa0 100644
--- a/src/mongo/db/repl/repl_set_heartbeat_response.cpp
+++ b/src/mongo/db/repl/repl_set_heartbeat_response.cpp
@@ -50,13 +50,8 @@ namespace {
const std::string kConfigFieldName = "config";
const std::string kConfigVersionFieldName = "v";
const std::string kElectionTimeFieldName = "electionTime";
-const std::string kHasDataFieldName = "hasData";
-const std::string kHasStateDisagreementFieldName = "stateDisagreement";
const std::string kHbMessageFieldName = "hbmsg";
-const std::string kIsElectableFieldName = "e";
-const std::string kIsReplSetFieldName = "rs";
const std::string kMemberStateFieldName = "state";
-const std::string kMismatchFieldName = "mismatch";
const std::string kOkFieldName = "ok";
const std::string kDurableOpTimeFieldName = "durableOpTime";
const std::string kAppliedOpTimeFieldName = "opTime";
@@ -64,22 +59,12 @@ const std::string kPrimaryIdFieldName = "primaryId";
const std::string kReplSetFieldName = "set";
const std::string kSyncSourceFieldName = "syncingTo";
const std::string kTermFieldName = "term";
-const std::string kTimeFieldName = "time";
const std::string kTimestampFieldName = "ts";
} // namespace
void ReplSetHeartbeatResponse::addToBSON(BSONObjBuilder* builder, bool isProtocolVersionV1) const {
- if (_mismatch) {
- *builder << kOkFieldName << 0.0;
- *builder << kMismatchFieldName << _mismatch;
- return;
- }
-
builder->append(kOkFieldName, 1.0);
- if (_timeSet) {
- *builder << kTimeFieldName << durationCount<Seconds>(_time);
- }
if (_electionTimeSet) {
builder->appendDate(kElectionTimeFieldName,
Date_t::fromMillisSinceEpoch(_electionTime.asLL()));
@@ -87,15 +72,6 @@ void ReplSetHeartbeatResponse::addToBSON(BSONObjBuilder* builder, bool isProtoco
if (_configSet) {
*builder << kConfigFieldName << _config.toBSON();
}
- if (_electableSet) {
- *builder << kIsElectableFieldName << _electable;
- }
- if (_isReplSet) {
- *builder << "rs" << _isReplSet;
- }
- if (_stateDisagreement) {
- *builder << kHasStateDisagreementFieldName << _stateDisagreement;
- }
if (_stateSet) {
builder->appendIntOrLL(kMemberStateFieldName, _state.s);
}
@@ -109,9 +85,6 @@ void ReplSetHeartbeatResponse::addToBSON(BSONObjBuilder* builder, bool isProtoco
if (!_syncingTo.empty()) {
*builder << kSyncSourceFieldName << _syncingTo.toString();
}
- if (_hasDataSet) {
- builder->append(kHasDataFieldName, _hasData);
- }
if (_term != -1) {
builder->append(kTermFieldName, _term);
}
@@ -138,11 +111,6 @@ BSONObj ReplSetHeartbeatResponse::toBSON(bool isProtocolVersionV1) const {
}
Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, long long term) {
- // Old versions set this even though they returned not "ok"
- _mismatch = doc[kMismatchFieldName].trueValue();
- if (_mismatch)
- return Status(ErrorCodes::InconsistentReplicaSetNames, "replica set name doesn't match.");
-
// Old versions sometimes set the replica set name ("set") but ok:0
const BSONElement replSetNameElement = doc[kReplSetFieldName];
if (replSetNameElement.eoo()) {
@@ -164,10 +132,6 @@ Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, long long term)
}
}
- const BSONElement hasDataElement = doc[kHasDataFieldName];
- _hasDataSet = !hasDataElement.eoo();
- _hasData = hasDataElement.trueValue();
-
const BSONElement electionTimeElement = doc[kElectionTimeFieldName];
if (electionTimeElement.eoo()) {
_electionTimeSet = false;
@@ -185,22 +149,6 @@ Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, long long term)
<< typeName(electionTimeElement.type()));
}
- const BSONElement timeElement = doc[kTimeFieldName];
- if (timeElement.eoo()) {
- _timeSet = false;
- } else if (timeElement.isNumber()) {
- _timeSet = true;
- _time = Seconds(timeElement.numberLong());
- } else {
- return Status(ErrorCodes::TypeMismatch,
- str::stream() << "Expected \"" << kTimeFieldName
- << "\" field in response to replSetHeartbeat "
- "command to have a numeric type, but found type "
- << typeName(timeElement.type()));
- }
-
- _isReplSet = doc[kIsReplSetFieldName].trueValue();
-
Status termStatus = bsonExtractIntegerField(doc, kTermFieldName, &_term);
if (!termStatus.isOK() && termStatus != ErrorCodes::NoSuchKey) {
return termStatus;
@@ -231,8 +179,6 @@ Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, long long term)
} else if (appliedOpTimeElement.type() == Object) {
Status status = bsonExtractOpTimeField(doc, kAppliedOpTimeFieldName, &_appliedOpTime);
_appliedOpTimeSet = true;
- // since a v1 OpTime was in the response, the member must be part of a replset
- _isReplSet = true;
} else {
return Status(ErrorCodes::TypeMismatch,
str::stream() << "Expected \"" << kAppliedOpTimeFieldName
@@ -241,14 +187,6 @@ Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, long long term)
<< typeName(appliedOpTimeElement.type()));
}
- const BSONElement electableElement = doc[kIsElectableFieldName];
- if (electableElement.eoo()) {
- _electableSet = false;
- } else {
- _electableSet = true;
- _electable = electableElement.trueValue();
- }
-
const BSONElement memberStateElement = doc[kMemberStateFieldName];
if (memberStateElement.eoo()) {
_stateSet = false;
@@ -273,9 +211,6 @@ Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, long long term)
_state = MemberState(static_cast<int>(stateInt));
}
- _stateDisagreement = doc[kHasStateDisagreementFieldName].trueValue();
-
-
// Not required for the case of uninitialized members -- they have no config
const BSONElement configVersionElement = doc[kConfigVersionFieldName];
@@ -350,16 +285,6 @@ Timestamp ReplSetHeartbeatResponse::getElectionTime() const {
return _electionTime;
}
-bool ReplSetHeartbeatResponse::isElectable() const {
- invariant(_electableSet);
- return _electable;
-}
-
-Seconds ReplSetHeartbeatResponse::getTime() const {
- invariant(_timeSet);
- return _time;
-}
-
const ReplSetConfig& ReplSetHeartbeatResponse::getConfig() const {
invariant(_configSet);
return _config;
diff --git a/src/mongo/db/repl/repl_set_heartbeat_response.h b/src/mongo/db/repl/repl_set_heartbeat_response.h
index 25e56c15179..5fe978d0d15 100644
--- a/src/mongo/db/repl/repl_set_heartbeat_response.h
+++ b/src/mongo/db/repl/repl_set_heartbeat_response.h
@@ -71,21 +71,6 @@ public:
return toBSON(true).toString();
}
- bool hasDataSet() const {
- return _hasDataSet;
- }
- bool hasData() const {
- return _hasData;
- }
- bool isMismatched() const {
- return _mismatch;
- }
- bool isReplSet() const {
- return _isReplSet;
- }
- bool isStateDisagreement() const {
- return _stateDisagreement;
- }
const std::string& getReplicaSetName() const {
return _setName;
}
@@ -97,17 +82,9 @@ public:
return _electionTimeSet;
}
Timestamp getElectionTime() const;
- bool hasIsElectable() const {
- return _electableSet;
- }
- bool isElectable() const;
const std::string& getHbMsg() const {
return _hbmsg;
}
- bool hasTime() const {
- return _timeSet;
- }
- Seconds getTime() const;
const HostAndPort& getSyncingTo() const {
return _syncingTo;
}
@@ -135,34 +112,6 @@ public:
OpTime getDurableOpTime() const;
/**
- * Sets _mismatch to true.
- */
- void noteMismatched() {
- _mismatch = true;
- }
-
- /**
- * Sets _isReplSet to true.
- */
- void noteReplSet() {
- _isReplSet = true;
- }
-
- /**
- * Sets _stateDisagreement to true.
- */
- void noteStateDisagreement() {
- _stateDisagreement = true;
- }
-
- /**
- * Sets _hasData to true, and _hasDataSet to true to indicate _hasData has been modified
- */
- void noteHasData() {
- _hasDataSet = _hasData = true;
- }
-
- /**
* Sets _setName to "name".
*/
void setSetName(std::string name) {
@@ -186,15 +135,6 @@ public:
}
/**
- * Sets _electable to "electable" and sets _electableSet to true to indicate
- * that the value of _electable has been modified.
- */
- void setElectable(bool electable) {
- _electableSet = true;
- _electable = electable;
- }
-
- /**
* Sets _hbmsg to "hbmsg".
*/
void setHbMsg(std::string hbmsg) {
@@ -202,15 +142,6 @@ public:
}
/**
- * Sets the optional "time" field of the response to "theTime", which is
- * a count of seconds since the UNIX epoch.
- */
- void setTime(Seconds theTime) {
- _timeSet = true;
- _time = theTime;
- }
-
- /**
* Sets _syncingTo to "syncingTo".
*/
void setSyncingTo(const HostAndPort& syncingTo) {
@@ -252,25 +183,12 @@ private:
bool _electionTimeSet = false;
Timestamp _electionTime;
- bool _timeSet = false;
- Seconds _time = Seconds(0); // Seconds since UNIX epoch.
-
bool _appliedOpTimeSet = false;
OpTime _appliedOpTime;
bool _durableOpTimeSet = false;
OpTime _durableOpTime;
- bool _electableSet = false;
- bool _electable = false;
-
- bool _hasDataSet = false;
- bool _hasData = false;
-
- bool _mismatch = false;
- bool _isReplSet = false;
- bool _stateDisagreement = false;
-
bool _stateSet = false;
MemberState _state;
diff --git a/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp b/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp
index 259c17379fc..943da9d0246 100644
--- a/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp
+++ b/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp
@@ -49,14 +49,9 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
ReplSetHeartbeatResponse hbResponseObjRoundTripChecker;
ASSERT_EQUALS(false, hbResponse.hasState());
ASSERT_EQUALS(false, hbResponse.hasElectionTime());
- ASSERT_EQUALS(false, hbResponse.hasIsElectable());
- ASSERT_EQUALS(false, hbResponse.hasTime());
ASSERT_EQUALS(false, hbResponse.hasDurableOpTime());
ASSERT_EQUALS(false, hbResponse.hasAppliedOpTime());
ASSERT_EQUALS(false, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(false, hbResponse.isReplSet());
- ASSERT_EQUALS(false, hbResponse.isStateDisagreement());
ASSERT_EQUALS("", hbResponse.getReplicaSetName());
ASSERT_EQUALS("", hbResponse.getHbMsg());
ASSERT_EQUALS(HostAndPort(), hbResponse.getSyncingTo());
@@ -74,14 +69,9 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
++fieldsSet;
ASSERT_EQUALS(false, hbResponse.hasState());
ASSERT_EQUALS(false, hbResponse.hasElectionTime());
- ASSERT_EQUALS(false, hbResponse.hasIsElectable());
- ASSERT_EQUALS(false, hbResponse.hasTime());
ASSERT_EQUALS(false, hbResponse.hasDurableOpTime());
ASSERT_EQUALS(false, hbResponse.hasAppliedOpTime());
ASSERT_EQUALS(false, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(false, hbResponse.isReplSet());
- ASSERT_EQUALS(false, hbResponse.isStateDisagreement());
ASSERT_EQUALS("", hbResponse.getReplicaSetName());
ASSERT_EQUALS("", hbResponse.getHbMsg());
ASSERT_EQUALS(HostAndPort(), hbResponse.getSyncingTo());
@@ -101,14 +91,9 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
++fieldsSet;
ASSERT_EQUALS(false, hbResponse.hasState());
ASSERT_EQUALS(false, hbResponse.hasElectionTime());
- ASSERT_EQUALS(false, hbResponse.hasIsElectable());
- ASSERT_EQUALS(false, hbResponse.hasTime());
ASSERT_EQUALS(false, hbResponse.hasDurableOpTime());
ASSERT_EQUALS(false, hbResponse.hasAppliedOpTime());
ASSERT_EQUALS(false, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(false, hbResponse.isReplSet());
- ASSERT_EQUALS(false, hbResponse.isStateDisagreement());
ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
ASSERT_EQUALS("", hbResponse.getHbMsg());
ASSERT_EQUALS(HostAndPort(), hbResponse.getSyncingTo());
@@ -129,14 +114,9 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
++fieldsSet;
ASSERT_EQUALS(false, hbResponse.hasState());
ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(false, hbResponse.hasIsElectable());
- ASSERT_EQUALS(false, hbResponse.hasTime());
ASSERT_EQUALS(false, hbResponse.hasDurableOpTime());
ASSERT_EQUALS(false, hbResponse.hasAppliedOpTime());
ASSERT_EQUALS(false, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(false, hbResponse.isReplSet());
- ASSERT_EQUALS(false, hbResponse.isStateDisagreement());
ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
ASSERT_EQUALS("", hbResponse.getHbMsg());
ASSERT_EQUALS(HostAndPort(), hbResponse.getSyncingTo());
@@ -159,14 +139,9 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
++fieldsSet;
ASSERT_EQUALS(false, hbResponse.hasState());
ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(false, hbResponse.hasIsElectable());
- ASSERT_EQUALS(false, hbResponse.hasTime());
ASSERT_EQUALS(true, hbResponse.hasDurableOpTime());
ASSERT_EQUALS(false, hbResponse.hasAppliedOpTime());
ASSERT_EQUALS(false, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(false, hbResponse.isReplSet());
- ASSERT_EQUALS(false, hbResponse.isStateDisagreement());
ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
ASSERT_EQUALS("", hbResponse.getHbMsg());
ASSERT_EQUALS(HostAndPort(), hbResponse.getSyncingTo());
@@ -191,14 +166,9 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
++fieldsSet;
ASSERT_EQUALS(false, hbResponse.hasState());
ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(false, hbResponse.hasIsElectable());
- ASSERT_EQUALS(false, hbResponse.hasTime());
ASSERT_EQUALS(true, hbResponse.hasDurableOpTime());
ASSERT_EQUALS(true, hbResponse.hasAppliedOpTime());
ASSERT_EQUALS(false, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(false, hbResponse.isReplSet());
- ASSERT_EQUALS(false, hbResponse.isStateDisagreement());
ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
ASSERT_EQUALS("", hbResponse.getHbMsg());
ASSERT_EQUALS(HostAndPort(), hbResponse.getSyncingTo());
@@ -220,94 +190,15 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
ASSERT_EQUALS(Status::OK(), initializeResult);
ASSERT_EQUALS(hbResponseObj.toString(), hbResponseObjRoundTripChecker.toBSON(false).toString());
- // set time
- hbResponse.setTime(Seconds(10));
- ++fieldsSet;
- ASSERT_EQUALS(false, hbResponse.hasState());
- ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(false, hbResponse.hasIsElectable());
- ASSERT_EQUALS(true, hbResponse.hasTime());
- ASSERT_EQUALS(true, hbResponse.hasDurableOpTime());
- ASSERT_EQUALS(true, hbResponse.hasAppliedOpTime());
- ASSERT_EQUALS(false, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(false, hbResponse.isReplSet());
- ASSERT_EQUALS(false, hbResponse.isStateDisagreement());
- ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
- ASSERT_EQUALS("", hbResponse.getHbMsg());
- ASSERT_EQUALS(HostAndPort(), hbResponse.getSyncingTo());
- ASSERT_EQUALS(1, hbResponse.getConfigVersion());
- ASSERT_EQUALS(Timestamp(10, 0), hbResponse.getElectionTime());
- ASSERT_EQUALS(OpTime(Timestamp(0, 10), 0), hbResponse.getDurableOpTime());
- ASSERT_EQUALS(OpTime(Timestamp(0, 50), 0), hbResponse.getAppliedOpTime());
- ASSERT_EQUALS(Seconds(10), hbResponse.getTime());
-
- hbResponseObj = hbResponse.toBSON(false);
- ASSERT_EQUALS(fieldsSet, hbResponseObj.nFields());
- ASSERT_EQUALS("rs0", hbResponseObj["set"].String());
- ASSERT_EQUALS("", hbResponseObj["hbmsg"].String());
- ASSERT_EQUALS(1, hbResponseObj["v"].Number());
- ASSERT_EQUALS(Timestamp(10, 0), hbResponseObj["electionTime"].timestamp());
- ASSERT_EQUALS(Timestamp(0, 50), hbResponseObj["opTime"].timestamp());
- ASSERT_EQUALS(Timestamp(0, 10), hbResponseObj["durableOpTime"]["ts"].timestamp());
- ASSERT_EQUALS(10, hbResponseObj["time"].numberLong());
-
- initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj, 0);
- ASSERT_EQUALS(Status::OK(), initializeResult);
- ASSERT_EQUALS(hbResponseObj.toString(), hbResponseObjRoundTripChecker.toBSON(false).toString());
-
- // set electable
- hbResponse.setElectable(true);
- ++fieldsSet;
- ASSERT_EQUALS(false, hbResponse.hasState());
- ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(true, hbResponse.hasIsElectable());
- ASSERT_EQUALS(true, hbResponse.hasTime());
- ASSERT_EQUALS(true, hbResponse.hasDurableOpTime());
- ASSERT_EQUALS(true, hbResponse.hasAppliedOpTime());
- ASSERT_EQUALS(false, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(false, hbResponse.isReplSet());
- ASSERT_EQUALS(false, hbResponse.isStateDisagreement());
- ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
- ASSERT_EQUALS("", hbResponse.getHbMsg());
- ASSERT_EQUALS(HostAndPort(), hbResponse.getSyncingTo());
- ASSERT_EQUALS(1, hbResponse.getConfigVersion());
- ASSERT_EQUALS(Timestamp(10, 0), hbResponse.getElectionTime());
- ASSERT_EQUALS(OpTime(Timestamp(0, 10), 0), hbResponse.getDurableOpTime());
- ASSERT_EQUALS(OpTime(Timestamp(0, 50), 0), hbResponse.getAppliedOpTime());
- ASSERT_EQUALS(Seconds(10), hbResponse.getTime());
- ASSERT_EQUALS(true, hbResponse.isElectable());
-
- hbResponseObj = hbResponse.toBSON(false);
- ASSERT_EQUALS(fieldsSet, hbResponseObj.nFields());
- ASSERT_EQUALS("rs0", hbResponseObj["set"].String());
- ASSERT_EQUALS("", hbResponseObj["hbmsg"].String());
- ASSERT_EQUALS(1, hbResponseObj["v"].Number());
- ASSERT_EQUALS(Timestamp(10, 0), hbResponseObj["electionTime"].timestamp());
- ASSERT_EQUALS(Timestamp(0, 50), hbResponseObj["opTime"].timestamp());
- ASSERT_EQUALS(Timestamp(0, 10), hbResponseObj["durableOpTime"]["ts"].timestamp());
- ASSERT_EQUALS(10, hbResponseObj["time"].numberLong());
- ASSERT_EQUALS(true, hbResponseObj["e"].trueValue());
-
- initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj, 0);
- ASSERT_EQUALS(Status::OK(), initializeResult);
- ASSERT_EQUALS(hbResponseObj.toString(), hbResponseObjRoundTripChecker.toBSON(false).toString());
-
// set config
ReplSetConfig config;
hbResponse.setConfig(config);
++fieldsSet;
ASSERT_EQUALS(false, hbResponse.hasState());
ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(true, hbResponse.hasIsElectable());
- ASSERT_EQUALS(true, hbResponse.hasTime());
ASSERT_EQUALS(true, hbResponse.hasDurableOpTime());
ASSERT_EQUALS(true, hbResponse.hasAppliedOpTime());
ASSERT_EQUALS(true, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(false, hbResponse.isReplSet());
- ASSERT_EQUALS(false, hbResponse.isStateDisagreement());
ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
ASSERT_EQUALS("", hbResponse.getHbMsg());
ASSERT_EQUALS(HostAndPort(), hbResponse.getSyncingTo());
@@ -315,8 +206,6 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
ASSERT_EQUALS(Timestamp(10, 0), hbResponse.getElectionTime());
ASSERT_EQUALS(OpTime(Timestamp(0, 10), 0), hbResponse.getDurableOpTime());
ASSERT_EQUALS(OpTime(Timestamp(0, 50), 0), hbResponse.getAppliedOpTime());
- ASSERT_EQUALS(Seconds(10), hbResponse.getTime());
- ASSERT_EQUALS(true, hbResponse.isElectable());
ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString());
hbResponseObj = hbResponse.toBSON(false);
@@ -327,8 +216,6 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
ASSERT_EQUALS(Timestamp(10, 0), hbResponseObj["electionTime"].timestamp());
ASSERT_EQUALS(Timestamp(0, 50), hbResponseObj["opTime"].timestamp());
ASSERT_EQUALS(Timestamp(0, 10), hbResponseObj["durableOpTime"]["ts"].timestamp());
- ASSERT_EQUALS(10, hbResponseObj["time"].numberLong());
- ASSERT_EQUALS(true, hbResponseObj["e"].trueValue());
ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString());
initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj, 0);
@@ -340,14 +227,9 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
++fieldsSet;
ASSERT_EQUALS(true, hbResponse.hasState());
ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(true, hbResponse.hasIsElectable());
- ASSERT_EQUALS(true, hbResponse.hasTime());
ASSERT_EQUALS(true, hbResponse.hasDurableOpTime());
ASSERT_EQUALS(true, hbResponse.hasAppliedOpTime());
ASSERT_EQUALS(true, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(false, hbResponse.isReplSet());
- ASSERT_EQUALS(false, hbResponse.isStateDisagreement());
ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
ASSERT_EQUALS(MemberState(MemberState::RS_SECONDARY).toString(),
hbResponse.getState().toString());
@@ -357,8 +239,6 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
ASSERT_EQUALS(Timestamp(10, 0), hbResponse.getElectionTime());
ASSERT_EQUALS(OpTime(Timestamp(0, 10), 0), hbResponse.getDurableOpTime());
ASSERT_EQUALS(OpTime(Timestamp(0, 50), 0), hbResponse.getAppliedOpTime());
- ASSERT_EQUALS(Seconds(10), hbResponse.getTime());
- ASSERT_EQUALS(true, hbResponse.isElectable());
ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString());
hbResponseObj = hbResponse.toBSON(false);
@@ -369,8 +249,6 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
ASSERT_EQUALS(Timestamp(10, 0), hbResponseObj["electionTime"].timestamp());
ASSERT_EQUALS(Timestamp(0, 50), hbResponseObj["opTime"].timestamp());
ASSERT_EQUALS(Timestamp(0, 10), hbResponseObj["durableOpTime"]["ts"].timestamp());
- ASSERT_EQUALS(10, hbResponseObj["time"].numberLong());
- ASSERT_EQUALS(true, hbResponseObj["e"].trueValue());
ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString());
ASSERT_EQUALS(2, hbResponseObj["state"].numberLong());
@@ -378,110 +256,14 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
ASSERT_EQUALS(Status::OK(), initializeResult);
ASSERT_EQUALS(hbResponseObj.toString(), hbResponseObjRoundTripChecker.toBSON(false).toString());
- // set stateDisagreement
- hbResponse.noteStateDisagreement();
- ++fieldsSet;
- ASSERT_EQUALS(true, hbResponse.hasState());
- ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(true, hbResponse.hasIsElectable());
- ASSERT_EQUALS(true, hbResponse.hasTime());
- ASSERT_EQUALS(true, hbResponse.hasDurableOpTime());
- ASSERT_EQUALS(true, hbResponse.hasAppliedOpTime());
- ASSERT_EQUALS(true, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(false, hbResponse.isReplSet());
- ASSERT_EQUALS(true, hbResponse.isStateDisagreement());
- ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
- ASSERT_EQUALS(MemberState(MemberState::RS_SECONDARY).toString(),
- hbResponse.getState().toString());
- ASSERT_EQUALS("", hbResponse.getHbMsg());
- ASSERT_EQUALS(HostAndPort(), hbResponse.getSyncingTo());
- ASSERT_EQUALS(1, hbResponse.getConfigVersion());
- ASSERT_EQUALS(Timestamp(10, 0), hbResponse.getElectionTime());
- ASSERT_EQUALS(OpTime(Timestamp(0, 10), 0), hbResponse.getDurableOpTime());
- ASSERT_EQUALS(OpTime(Timestamp(0, 50), 0), hbResponse.getAppliedOpTime());
- ASSERT_EQUALS(Seconds(10), hbResponse.getTime());
- ASSERT_EQUALS(true, hbResponse.isElectable());
- ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString());
-
- hbResponseObj = hbResponse.toBSON(false);
- ASSERT_EQUALS(fieldsSet, hbResponseObj.nFields());
- ASSERT_EQUALS("rs0", hbResponseObj["set"].String());
- ASSERT_EQUALS("", hbResponseObj["hbmsg"].String());
- ASSERT_EQUALS(1, hbResponseObj["v"].Number());
- ASSERT_EQUALS(Timestamp(10, 0), hbResponseObj["electionTime"].timestamp());
- ASSERT_EQUALS(Timestamp(0, 50), hbResponseObj["opTime"].timestamp());
- ASSERT_EQUALS(Timestamp(0, 10), hbResponseObj["durableOpTime"]["ts"].timestamp());
- ASSERT_EQUALS(10, hbResponseObj["time"].numberLong());
- ASSERT_EQUALS(true, hbResponseObj["e"].trueValue());
- ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString());
- ASSERT_EQUALS(2, hbResponseObj["state"].numberLong());
- ASSERT_EQUALS(false, hbResponseObj["mismatch"].trueValue());
- ASSERT_EQUALS(true, hbResponseObj["stateDisagreement"].trueValue());
-
- initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj, 0);
- ASSERT_EQUALS(Status::OK(), initializeResult);
- ASSERT_EQUALS(hbResponseObj.toString(), hbResponseObjRoundTripChecker.toBSON(false).toString());
-
- // set replSet
- hbResponse.noteReplSet();
- ++fieldsSet;
- ASSERT_EQUALS(true, hbResponse.hasState());
- ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(true, hbResponse.hasIsElectable());
- ASSERT_EQUALS(true, hbResponse.hasTime());
- ASSERT_EQUALS(true, hbResponse.hasDurableOpTime());
- ASSERT_EQUALS(true, hbResponse.hasAppliedOpTime());
- ASSERT_EQUALS(true, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(true, hbResponse.isReplSet());
- ASSERT_EQUALS(true, hbResponse.isStateDisagreement());
- ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
- ASSERT_EQUALS(MemberState(MemberState::RS_SECONDARY).toString(),
- hbResponse.getState().toString());
- ASSERT_EQUALS("", hbResponse.getHbMsg());
- ASSERT_EQUALS(HostAndPort(), hbResponse.getSyncingTo());
- ASSERT_EQUALS(1, hbResponse.getConfigVersion());
- ASSERT_EQUALS(Timestamp(10, 0), hbResponse.getElectionTime());
- ASSERT_EQUALS(OpTime(Timestamp(0, 10), 0), hbResponse.getDurableOpTime());
- ASSERT_EQUALS(OpTime(Timestamp(0, 50), 0), hbResponse.getAppliedOpTime());
- ASSERT_EQUALS(Seconds(10), hbResponse.getTime());
- ASSERT_EQUALS(true, hbResponse.isElectable());
- ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString());
-
- hbResponseObj = hbResponse.toBSON(false);
- ASSERT_EQUALS(fieldsSet, hbResponseObj.nFields());
- ASSERT_EQUALS("rs0", hbResponseObj["set"].String());
- ASSERT_EQUALS("", hbResponseObj["hbmsg"].String());
- ASSERT_EQUALS(1, hbResponseObj["v"].Number());
- ASSERT_EQUALS(Timestamp(10, 0), hbResponseObj["electionTime"].timestamp());
- ASSERT_EQUALS(Timestamp(0, 50), hbResponseObj["opTime"].timestamp());
- ASSERT_EQUALS(Timestamp(0, 10), hbResponseObj["durableOpTime"]["ts"].timestamp());
- ASSERT_EQUALS(10, hbResponseObj["time"].numberLong());
- ASSERT_EQUALS(true, hbResponseObj["e"].trueValue());
- ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString());
- ASSERT_EQUALS(2, hbResponseObj["state"].numberLong());
- ASSERT_EQUALS(false, hbResponseObj["mismatch"].trueValue());
- ASSERT_EQUALS(true, hbResponseObj["stateDisagreement"].trueValue());
- ASSERT_EQUALS(true, hbResponseObj["rs"].trueValue());
-
- initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj, 0);
- ASSERT_EQUALS(Status::OK(), initializeResult);
- ASSERT_EQUALS(hbResponseObj.toString(), hbResponseObjRoundTripChecker.toBSON(false).toString());
-
// set syncingTo
hbResponse.setSyncingTo(HostAndPort("syncTarget"));
++fieldsSet;
ASSERT_EQUALS(true, hbResponse.hasState());
ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(true, hbResponse.hasIsElectable());
- ASSERT_EQUALS(true, hbResponse.hasTime());
ASSERT_EQUALS(true, hbResponse.hasDurableOpTime());
ASSERT_EQUALS(true, hbResponse.hasAppliedOpTime());
ASSERT_EQUALS(true, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(true, hbResponse.isReplSet());
- ASSERT_EQUALS(true, hbResponse.isStateDisagreement());
ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
ASSERT_EQUALS(MemberState(MemberState::RS_SECONDARY).toString(),
hbResponse.getState().toString());
@@ -491,8 +273,6 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
ASSERT_EQUALS(Timestamp(10, 0), hbResponse.getElectionTime());
ASSERT_EQUALS(OpTime(Timestamp(0, 10), 0), hbResponse.getDurableOpTime());
ASSERT_EQUALS(OpTime(Timestamp(0, 50), 0), hbResponse.getAppliedOpTime());
- ASSERT_EQUALS(Seconds(10), hbResponse.getTime());
- ASSERT_EQUALS(true, hbResponse.isElectable());
ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString());
hbResponseObj = hbResponse.toBSON(false);
@@ -503,13 +283,8 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
ASSERT_EQUALS(Timestamp(10, 0), hbResponseObj["electionTime"].timestamp());
ASSERT_EQUALS(Timestamp(0, 50), hbResponseObj["opTime"].timestamp());
ASSERT_EQUALS(Timestamp(0, 10), hbResponseObj["durableOpTime"]["ts"].timestamp());
- ASSERT_EQUALS(10, hbResponseObj["time"].numberLong());
- ASSERT_EQUALS(true, hbResponseObj["e"].trueValue());
ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString());
ASSERT_EQUALS(2, hbResponseObj["state"].numberLong());
- ASSERT_EQUALS(false, hbResponseObj["mismatch"].trueValue());
- ASSERT_EQUALS(true, hbResponseObj["stateDisagreement"].trueValue());
- ASSERT_EQUALS(true, hbResponseObj["rs"].trueValue());
ASSERT_EQUALS("syncTarget:27017", hbResponseObj["syncingTo"].String());
initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj, 0);
@@ -520,14 +295,9 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
hbResponse.setHbMsg("lub dub");
ASSERT_EQUALS(true, hbResponse.hasState());
ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(true, hbResponse.hasIsElectable());
- ASSERT_EQUALS(true, hbResponse.hasTime());
ASSERT_EQUALS(true, hbResponse.hasDurableOpTime());
ASSERT_EQUALS(true, hbResponse.hasAppliedOpTime());
ASSERT_EQUALS(true, hbResponse.hasConfig());
- ASSERT_EQUALS(false, hbResponse.isMismatched());
- ASSERT_EQUALS(true, hbResponse.isReplSet());
- ASSERT_EQUALS(true, hbResponse.isStateDisagreement());
ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
ASSERT_EQUALS(MemberState(MemberState::RS_SECONDARY).toString(),
hbResponse.getState().toString());
@@ -537,8 +307,6 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
ASSERT_EQUALS(Timestamp(10, 0), hbResponse.getElectionTime());
ASSERT_EQUALS(OpTime(Timestamp(0, 10), 0), hbResponse.getDurableOpTime());
ASSERT_EQUALS(OpTime(Timestamp(0, 50), 0), hbResponse.getAppliedOpTime());
- ASSERT_EQUALS(Seconds(10), hbResponse.getTime());
- ASSERT_EQUALS(true, hbResponse.isElectable());
ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString());
hbResponseObj = hbResponse.toBSON(false);
@@ -549,53 +317,13 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) {
ASSERT_EQUALS(Timestamp(10, 0), hbResponseObj["electionTime"].timestamp());
ASSERT_EQUALS(Timestamp(0, 50), hbResponseObj["opTime"].timestamp());
ASSERT_EQUALS(Timestamp(0, 10), hbResponseObj["durableOpTime"]["ts"].timestamp());
- ASSERT_EQUALS(10, hbResponseObj["time"].numberLong());
- ASSERT_EQUALS(true, hbResponseObj["e"].trueValue());
ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString());
ASSERT_EQUALS(2, hbResponseObj["state"].numberLong());
- ASSERT_EQUALS(false, hbResponseObj["mismatch"].trueValue());
- ASSERT_EQUALS(true, hbResponseObj["stateDisagreement"].trueValue());
- ASSERT_EQUALS(true, hbResponseObj["rs"].trueValue());
ASSERT_EQUALS("syncTarget:27017", hbResponseObj["syncingTo"].String());
initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj, 0);
ASSERT_EQUALS(Status::OK(), initializeResult);
ASSERT_EQUALS(hbResponseObj.toString(), hbResponseObjRoundTripChecker.toBSON(false).toString());
-
- // set mismatched
- hbResponse.noteMismatched();
- ASSERT_EQUALS(true, hbResponse.hasState());
- ASSERT_EQUALS(true, hbResponse.hasElectionTime());
- ASSERT_EQUALS(true, hbResponse.hasIsElectable());
- ASSERT_EQUALS(true, hbResponse.hasTime());
- ASSERT_EQUALS(true, hbResponse.hasDurableOpTime());
- ASSERT_EQUALS(true, hbResponse.hasAppliedOpTime());
- ASSERT_EQUALS(true, hbResponse.hasConfig());
- ASSERT_EQUALS(true, hbResponse.isMismatched());
- ASSERT_EQUALS(true, hbResponse.isReplSet());
- ASSERT_EQUALS(true, hbResponse.isStateDisagreement());
- ASSERT_EQUALS("rs0", hbResponse.getReplicaSetName());
- ASSERT_EQUALS(MemberState(MemberState::RS_SECONDARY).toString(),
- hbResponse.getState().toString());
- ASSERT_EQUALS("lub dub", hbResponse.getHbMsg());
- ASSERT_EQUALS(HostAndPort("syncTarget"), hbResponse.getSyncingTo());
- ASSERT_EQUALS(1, hbResponse.getConfigVersion());
- ASSERT_EQUALS(Timestamp(10, 0), hbResponse.getElectionTime());
- ASSERT_EQUALS(OpTime(Timestamp(0, 10), 0), hbResponse.getDurableOpTime());
- ASSERT_EQUALS(OpTime(Timestamp(0, 50), 0), hbResponse.getAppliedOpTime());
- ASSERT_EQUALS(Seconds(10), hbResponse.getTime());
- ASSERT_EQUALS(true, hbResponse.isElectable());
- ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString());
-
- hbResponseObj = hbResponse.toBSON(false);
- ASSERT_EQUALS(2, hbResponseObj.nFields());
- ASSERT_EQUALS(true, hbResponseObj["mismatch"].trueValue());
-
- // NOTE: Does not check round-trip. Once noteMismached is set the bson will return an error
- // from initialize parsing.
- initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj, 0);
- ASSERT_NOT_EQUALS(Status::OK(), initializeResult);
- ASSERT_EQUALS(ErrorCodes::InconsistentReplicaSetNames, initializeResult.code());
}
TEST(ReplSetHeartbeatResponse, InitializeWrongElectionTimeType) {
@@ -610,18 +338,6 @@ TEST(ReplSetHeartbeatResponse, InitializeWrongElectionTimeType) {
result.reason());
}
-TEST(ReplSetHeartbeatResponse, InitializeWrongTimeType) {
- ReplSetHeartbeatResponse hbResponse;
- BSONObj initializerObj = BSON("ok" << 1.0 << "time"
- << "hello");
- Status result = hbResponse.initialize(initializerObj, 0);
- ASSERT_EQUALS(ErrorCodes::TypeMismatch, result);
- ASSERT_EQUALS(
- "Expected \"time\" field in response to replSetHeartbeat command to "
- "have a numeric type, but found type string",
- result.reason());
-}
-
TEST(ReplSetHeartbeatResponse, InitializeWrongDurableOpTimeType) {
ReplSetHeartbeatResponse hbResponse;
BSONObj initializerObj = BSON("ok" << 1.0 << "durableOpTime"
@@ -810,9 +526,8 @@ TEST(ReplSetHeartbeatResponse, InitializeBothOpTimeTypesSameResult) {
TEST(ReplSetHeartbeatResponse, NoConfigStillInitializing) {
ReplSetHeartbeatResponse hbResp;
std::string msg = "still initializing";
- Status result = hbResp.initialize(BSON("ok" << 1.0 << "rs" << true << "hbmsg" << msg), 0);
+ Status result = hbResp.initialize(BSON("ok" << 1.0 << "hbmsg" << msg), 0);
ASSERT_EQUALS(Status::OK(), result);
- ASSERT_EQUALS(true, hbResp.isReplSet());
ASSERT_EQUALS(msg, hbResp.getHbMsg());
}
@@ -825,9 +540,11 @@ TEST(ReplSetHeartbeatResponse, InvalidResponseOpTimeMissesConfigVersion) {
<< result.reason() << " doesn't contain 'v' field required error msg";
}
-TEST(ReplSetHeartbeatResponse, MismatchedRepliSetNames) {
+TEST(ReplSetHeartbeatResponse, MismatchedReplicaSetNames) {
ReplSetHeartbeatResponse hbResponse;
- BSONObj initializerObj = BSON("ok" << 0.0 << "mismatch" << true);
+ BSONObj initializerObj =
+ BSON("ok" << 0.0 << "code" << ErrorCodes::InconsistentReplicaSetNames << "errmsg"
+ << "replica set name doesn't match.");
Status result = hbResponse.initialize(initializerObj, 0);
ASSERT_EQUALS(ErrorCodes::InconsistentReplicaSetNames, result.code());
}
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
index 538f8c4693d..430f58a78e5 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
@@ -1837,8 +1837,7 @@ protected:
*/
void simulateHeartbeatResponses(OpTime optimePrimary,
OpTime optimeLagged,
- int numNodesCaughtUp,
- bool caughtUpAreElectable) {
+ int numNodesCaughtUp) {
int hbNum = 1;
while (getNet()->hasReadyRequests()) {
NetworkInterfaceMock::NetworkOperationIterator noi = getNet()->getNextReadyRequest();
@@ -1855,7 +1854,6 @@ protected:
// Catch up 'numNodesCaughtUp' nodes out of 5.
OpTime optimeResponse = (hbNum <= numNodesCaughtUp) ? optimePrimary : optimeLagged;
- bool isElectable = (hbNum <= numNodesCaughtUp) ? caughtUpAreElectable : true;
ReplSetHeartbeatResponse hbResp;
hbResp.setSetName(hbArgs.getSetName());
@@ -1863,7 +1861,6 @@ protected:
hbResp.setConfigVersion(hbArgs.getConfigVersion());
hbResp.setDurableOpTime(optimeResponse);
hbResp.setAppliedOpTime(optimeResponse);
- hbResp.setElectable(isElectable);
BSONObjBuilder respObj;
respObj << "ok" << 1;
hbResp.addToBSON(&respObj, false);
@@ -1897,41 +1894,6 @@ private:
}
};
-TEST_F(
- StepDownTestFiveNode,
- NodeReturnsExceededTimeLimitWhenStepDownIsRunAndCaughtUpMajorityExistsButWithoutElectableNode) {
- OpTime optimeLagged(Timestamp(100, 1), 1);
- OpTime optimePrimary(Timestamp(100, 2), 1);
-
- // All nodes are caught up
- getReplCoord()->setMyLastAppliedOpTime(optimePrimary);
- getReplCoord()->setMyLastDurableOpTime(optimePrimary);
- ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(1, 1, optimeLagged));
- ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(1, 2, optimeLagged));
- ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(1, 3, optimeLagged));
- ASSERT_OK(getReplCoord()->setLastAppliedOptime_forTest(1, 4, optimeLagged));
-
- simulateSuccessfulV1Election();
-
- enterNetwork();
- getNet()->runUntil(getNet()->now() + Seconds(2));
- ASSERT(getNet()->hasReadyRequests());
-
- // Make sure a majority are caught up (i.e. 3 out of 5). We catch up two secondaries since
- // the primary counts as one towards majority
- int numNodesCaughtUp = 2;
- simulateHeartbeatResponses(optimePrimary, optimeLagged, numNodesCaughtUp, false);
- getNet()->runReadyNetworkOperations();
- exitNetwork();
-
- const auto opCtx = makeOperationContext();
-
- ASSERT_TRUE(getReplCoord()->getMemberState().primary());
- auto status = getReplCoord()->stepDown(opCtx.get(), false, Milliseconds(0), Milliseconds(1000));
- ASSERT_EQUALS(ErrorCodes::ExceededTimeLimit, status);
- ASSERT_TRUE(getReplCoord()->getMemberState().primary());
-}
-
TEST_F(StepDownTestFiveNode,
NodeReturnsExceededTimeLimitWhenStepDownIsRunAndNoCaughtUpMajorityExists) {
OpTime optimeLagged(Timestamp(100, 1), 1);
@@ -1954,7 +1916,7 @@ TEST_F(StepDownTestFiveNode,
// Make sure less than a majority are caught up (i.e. 2 out of 5) We catch up one secondary
// since the primary counts as one towards majority
int numNodesCaughtUp = 1;
- simulateHeartbeatResponses(optimePrimary, optimeLagged, numNodesCaughtUp, true);
+ simulateHeartbeatResponses(optimePrimary, optimeLagged, numNodesCaughtUp);
getNet()->runReadyNetworkOperations();
exitNetwork();
@@ -1989,7 +1951,7 @@ TEST_F(
// Make sure a majority are caught up (i.e. 3 out of 5). We catch up two secondaries since
// the primary counts as one towards majority
int numNodesCaughtUp = 2;
- simulateHeartbeatResponses(optimePrimary, optimeLagged, numNodesCaughtUp, true);
+ simulateHeartbeatResponses(optimePrimary, optimeLagged, numNodesCaughtUp);
getNet()->runReadyNetworkOperations();
exitNetwork();
diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp
index 6ae6e13f147..04e043e8c9b 100644
--- a/src/mongo/db/repl/topology_coordinator.cpp
+++ b/src/mongo/db/repl/topology_coordinator.cpp
@@ -697,18 +697,10 @@ HeartbeatResponseAction TopologyCoordinator::processHeartbeatResponse(
invariant(hbStats.getLastHeartbeatStartDate() != Date_t());
const bool isUnauthorized = (hbResponse.getStatus().code() == ErrorCodes::Unauthorized) ||
(hbResponse.getStatus().code() == ErrorCodes::AuthenticationFailed);
- if (!hbResponse.isOK()) {
- if (isUnauthorized) {
- hbStats.hit(networkRoundTripTime);
- } else {
- hbStats.miss();
- }
- } else {
+ if (hbResponse.isOK() || isUnauthorized) {
hbStats.hit(networkRoundTripTime);
- // Log diagnostics.
- if (hbResponse.getValue().isStateDisagreement()) {
- LOG(1) << target << " thinks that we are down because they cannot send us heartbeats.";
- }
+ } else {
+ hbStats.miss();
}
// If a node is not PRIMARY and has no sync source, we increase the heartbeat rate in order
@@ -1984,9 +1976,6 @@ TopologyCoordinator::UnelectableReasonMask TopologyCoordinator::_getUnelectableR
if (hbData.getState() != MemberState::RS_SECONDARY) {
result |= NotSecondary;
}
- if (hbData.up() && hbData.isUnelectable()) {
- result |= RefusesToStand;
- }
invariant(result || memberConfig.isElectable());
return result;
}
@@ -2100,13 +2089,6 @@ std::string TopologyCoordinator::_getUnelectableReasonString(const UnelectableRe
hasWrittenToStream = true;
ss << "node is not a member of a valid replica set configuration";
}
- if (ur & RefusesToStand) {
- if (hasWrittenToStream) {
- ss << "; ";
- }
- hasWrittenToStream = true;
- ss << "most recent heartbeat indicates node will not stand for election";
- }
if (!hasWrittenToStream) {
severe() << "Invalid UnelectableReasonMask value 0x" << integerToHex(ur);
fassertFailed(26011);
diff --git a/src/mongo/db/repl/topology_coordinator.h b/src/mongo/db/repl/topology_coordinator.h
index 97f9f99e7b3..2c9cb11677f 100644
--- a/src/mongo/db/repl/topology_coordinator.h
+++ b/src/mongo/db/repl/topology_coordinator.h
@@ -750,9 +750,8 @@ private:
StepDownPeriodActive = 1 << 4,
NoData = 1 << 5,
NotInitialized = 1 << 6,
- RefusesToStand = 1 << 7,
- NotCloseEnoughToLatestForPriorityTakeover = 1 << 8,
- NotFreshEnoughForCatchupTakeover = 1 << 9,
+ NotCloseEnoughToLatestForPriorityTakeover = 1 << 7,
+ NotFreshEnoughForCatchupTakeover = 1 << 8,
};
// Set what type of PRIMARY this node currently is.
diff --git a/src/mongo/db/repl/topology_coordinator_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_v1_test.cpp
index 4f7f510cd64..33458bd20a2 100644
--- a/src/mongo/db/repl/topology_coordinator_v1_test.cpp
+++ b/src/mongo/db/repl/topology_coordinator_v1_test.cpp
@@ -5828,10 +5828,8 @@ TEST_F(HeartbeatResponseTestTwoRetriesV1, HeartbeatThreeNonconsecutiveFailures)
// Confirm that the topology coordinator does not mark a node down on three
// nonconsecutive heartbeat failures.
ReplSetHeartbeatResponse response;
- response.noteReplSet();
response.setSetName("rs0");
response.setState(MemberState::RS_SECONDARY);
- response.setElectable(true);
response.setConfigVersion(5);
// successful response (third response due to the two failures in setUp())
@@ -5892,32 +5890,6 @@ public:
}
};
-// TODO(dannenberg) change the name and functionality of this to match what this claims it is
-TEST_F(HeartbeatResponseHighVerbosityTestV1, UpdateHeartbeatDataOldConfig) {
- OpTime lastOpTimeApplied = OpTime(Timestamp(3, 0), 0);
-
- // request heartbeat
- std::pair<ReplSetHeartbeatArgsV1, Milliseconds> request =
- getTopoCoord().prepareHeartbeatRequestV1(now()++, "rs0", HostAndPort("host2"));
-
- ReplSetHeartbeatResponse believesWeAreDownResponse;
- believesWeAreDownResponse.noteReplSet();
- believesWeAreDownResponse.setSetName("rs0");
- believesWeAreDownResponse.setState(MemberState::RS_SECONDARY);
- believesWeAreDownResponse.setElectable(true);
- believesWeAreDownResponse.noteStateDisagreement();
- startCapturingLogMessages();
- getTopoCoord().setMyLastAppliedOpTime(lastOpTimeApplied, Date_t(), false);
- HeartbeatResponseAction action = getTopoCoord().processHeartbeatResponse(
- now()++, // Time is left.
- Milliseconds(400), // Spent 0.4 of the 0.5 second in the network.
- HostAndPort("host2"),
- StatusWith<ReplSetHeartbeatResponse>(believesWeAreDownResponse));
- stopCapturingLogMessages();
- ASSERT_NO_ACTION(action.getAction());
- ASSERT_EQUALS(1, countLogLinesContaining("host2:27017 thinks that we are down"));
-}
-
// TODO(dannenberg) figure out why this test is useful
TEST_F(HeartbeatResponseHighVerbosityTestV1, UpdateHeartbeatDataSameConfig) {
OpTime lastOpTimeApplied = OpTime(Timestamp(3, 0), 0);
@@ -5948,11 +5920,8 @@ TEST_F(HeartbeatResponseHighVerbosityTestV1, UpdateHeartbeatDataSameConfig) {
.transitional_ignore();
ReplSetHeartbeatResponse sameConfigResponse;
- sameConfigResponse.noteReplSet();
sameConfigResponse.setSetName("rs0");
sameConfigResponse.setState(MemberState::RS_SECONDARY);
- sameConfigResponse.setElectable(true);
- sameConfigResponse.noteStateDisagreement();
sameConfigResponse.setConfigVersion(2);
sameConfigResponse.setConfig(originalConfig);
startCapturingLogMessages();
@@ -5978,11 +5947,8 @@ TEST_F(HeartbeatResponseHighVerbosityTestV1,
getTopoCoord().prepareHeartbeatRequestV1(now()++, "rs0", HostAndPort("host5"));
ReplSetHeartbeatResponse memberMissingResponse;
- memberMissingResponse.noteReplSet();
memberMissingResponse.setSetName("rs0");
memberMissingResponse.setState(MemberState::RS_SECONDARY);
- memberMissingResponse.setElectable(true);
- memberMissingResponse.noteStateDisagreement();
startCapturingLogMessages();
getTopoCoord().setMyLastAppliedOpTime(lastOpTimeApplied, Date_t(), false);
HeartbeatResponseAction action = getTopoCoord().processHeartbeatResponse(
@@ -5995,32 +5961,6 @@ TEST_F(HeartbeatResponseHighVerbosityTestV1,
ASSERT_EQUALS(1, countLogLinesContaining("Could not find host5:27017 in current config"));
}
-TEST_F(HeartbeatResponseHighVerbosityTestV1,
- LogMessageAndTakeNoActionWhenReceivingAHeartbeatResponseFromANodeThatBelievesWeAreDown) {
- OpTime lastOpTimeApplied = OpTime(Timestamp(3, 0), 0);
-
- // request heartbeat
- std::pair<ReplSetHeartbeatArgsV1, Milliseconds> request =
- getTopoCoord().prepareHeartbeatRequestV1(now()++, "rs0", HostAndPort("host2"));
-
- ReplSetHeartbeatResponse believesWeAreDownResponse;
- believesWeAreDownResponse.noteReplSet();
- believesWeAreDownResponse.setSetName("rs0");
- believesWeAreDownResponse.setState(MemberState::RS_SECONDARY);
- believesWeAreDownResponse.setElectable(true);
- believesWeAreDownResponse.noteStateDisagreement();
- startCapturingLogMessages();
- getTopoCoord().setMyLastAppliedOpTime(lastOpTimeApplied, Date_t(), false);
- HeartbeatResponseAction action = getTopoCoord().processHeartbeatResponse(
- now()++, // Time is left.
- Milliseconds(400), // Spent 0.4 of the 0.5 second in the network.
- HostAndPort("host2"),
- StatusWith<ReplSetHeartbeatResponse>(believesWeAreDownResponse));
- stopCapturingLogMessages();
- ASSERT_NO_ACTION(action.getAction());
- ASSERT_EQUALS(1, countLogLinesContaining("host2:27017 thinks that we are down"));
-}
-
} // namespace
} // namespace repl
} // namespace mongo