diff options
author | Matthew Russotto <matthew.russotto@10gen.com> | 2017-11-28 10:44:24 -0500 |
---|---|---|
committer | Matthew Russotto <matthew.russotto@10gen.com> | 2017-11-28 15:59:13 -0500 |
commit | a25df7d03ac286f28eadebdd361802ad522e74e9 (patch) | |
tree | 567f75f4898eaf9e6fcbcd5f10c1ccdcf00754f9 /src/mongo/db/repl | |
parent | 26b42901e302db19cfbdbf3726b7be6fb624f4f5 (diff) | |
download | mongo-a25df7d03ac286f28eadebdd361802ad522e74e9.tar.gz |
SERVER-30626 Replace class TopologyCoordinator::Role with enum class for simplicity.
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_elect_test.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_test.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/topology_coordinator.cpp | 89 | ||||
-rw-r--r-- | src/mongo/db/repl/topology_coordinator.h | 37 | ||||
-rw-r--r-- | src/mongo/db/repl/topology_coordinator_test.cpp | 168 | ||||
-rw-r--r-- | src/mongo/db/repl/topology_coordinator_v1_test.cpp | 132 |
8 files changed, 213 insertions, 253 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index e092ba30d31..d34e4bff65e 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -882,7 +882,7 @@ Status ReplicationCoordinatorImpl::setFollowerMode(const MemberState& newState) if (newState == _topCoord->getMemberState()) { return Status::OK(); } - if (_topCoord->getRole() == TopologyCoordinator::Role::leader) { + if (_topCoord->getRole() == TopologyCoordinator::Role::kLeader) { return Status(ErrorCodes::NotSecondary, "Cannot set follower mode when node is currently the leader"); } @@ -2159,7 +2159,7 @@ Status ReplicationCoordinatorImpl::setMaintenanceMode(bool activate) { } stdx::unique_lock<stdx::mutex> lk(_mutex); - if (_topCoord->getRole() == TopologyCoordinator::Role::candidate) { + if (_topCoord->getRole() == TopologyCoordinator::Role::kCandidate) { return Status(ErrorCodes::NotSecondary, "currently running for election"); } @@ -2173,7 +2173,7 @@ Status ReplicationCoordinatorImpl::setMaintenanceMode(bool activate) { << " other maintenance mode tasks in progress" << rsLog; _topCoord->adjustMaintenanceCountBy(1); } else if (curMaintenanceCalls > 0) { - invariant(_topCoord->getRole() == TopologyCoordinator::Role::follower); + invariant(_topCoord->getRole() == TopologyCoordinator::Role::kFollower); _topCoord->adjustMaintenanceCountBy(-1); @@ -2567,7 +2567,7 @@ ReplicationCoordinatorImpl::_updateMemberStateFromTopologyCoordinator_inlock( const MemberState newState = _topCoord->getMemberState(); if (newState == _memberState) { - if (_topCoord->getRole() == TopologyCoordinator::Role::candidate) { + if (_topCoord->getRole() == TopologyCoordinator::Role::kCandidate) { invariant(_rsConfig.getNumMembers() == 1 && _selfIndex == 0 && _rsConfig.getMemberAt(0).isElectable()); if (isV1ElectionProtocol()) { @@ -2614,7 +2614,7 @@ ReplicationCoordinatorImpl::_updateMemberStateFromTopologyCoordinator_inlock( _canServeNonLocalReads.store(1U); } - if (newState.secondary() && _topCoord->getRole() == TopologyCoordinator::Role::candidate) { + if (newState.secondary() && _topCoord->getRole() == TopologyCoordinator::Role::kCandidate) { // When transitioning to SECONDARY, the only way for _topCoord to report the candidate // role is if the configuration represents a single-node replica set. In that case, the // overriding requirement is to elect this singleton node primary. @@ -3747,7 +3747,7 @@ void ReplicationCoordinatorImpl::setIndexPrefetchConfig( } executor::TaskExecutor::EventHandle ReplicationCoordinatorImpl::_cancelElectionIfNeeded_inlock() { - if (_topCoord->getRole() != TopologyCoordinator::Role::candidate) { + if (_topCoord->getRole() != TopologyCoordinator::Role::kCandidate) { return {}; } if (isV1ElectionProtocol()) { diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_test.cpp index 0025f70464b..b7b871cd89f 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_elect_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_elect_test.cpp @@ -562,12 +562,12 @@ TEST_F(ReplCoordElectTest, NodeCancelsElectionUponReceivingANewConfigDuringFresh getReplCoord()->setMyLastDurableOpTime(OpTime(Timestamp(100, 0), 0)); simulateEnoughHeartbeatsForAllNodesUp(); simulateFreshEnoughForElectability(); - ASSERT(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // Advance to freshness checker request phase. NetworkInterfaceMock* net = getNet(); net->enterNetwork(); - while (TopologyCoordinator::Role::candidate != getTopoCoord().getRole()) { + while (TopologyCoordinator::Role::kCandidate != getTopoCoord().getRole()) { net->runUntil(net->now() + Seconds(1)); if (!net->hasReadyRequests()) { continue; @@ -575,7 +575,7 @@ TEST_F(ReplCoordElectTest, NodeCancelsElectionUponReceivingANewConfigDuringFresh net->blackHole(net->getNextReadyRequest()); } net->exitNetwork(); - ASSERT(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // Submit a reconfig and confirm it cancels the election. ReplicationCoordinatorImpl::ReplSetReconfigArgs config = { @@ -597,7 +597,7 @@ TEST_F(ReplCoordElectTest, NodeCancelsElectionUponReceivingANewConfigDuringFresh net->enterNetwork(); net->runReadyNetworkOperations(); net->exitNetwork(); - ASSERT(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(ReplCoordElectTest, NodeCancelsElectionUponReceivingANewConfigDuringElectionPhase) { @@ -621,7 +621,7 @@ TEST_F(ReplCoordElectTest, NodeCancelsElectionUponReceivingANewConfigDuringElect getReplCoord()->setMyLastDurableOpTime(OpTime(Timestamp(100, 0), 0)); simulateEnoughHeartbeatsForAllNodesUp(); simulateFreshEnoughForElectability(); - ASSERT(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // Submit a reconfig and confirm it cancels the election. ReplicationCoordinatorImpl::ReplSetReconfigArgs config = { @@ -643,7 +643,7 @@ TEST_F(ReplCoordElectTest, NodeCancelsElectionUponReceivingANewConfigDuringElect getNet()->enterNetwork(); getNet()->runReadyNetworkOperations(); getNet()->exitNetwork(); - ASSERT(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } } // namespace diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp index 0fd15751fec..3e9efff0f9e 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp @@ -1913,7 +1913,7 @@ TEST_F(ReplCoordTest, NodeCancelsElectionUponReceivingANewConfigDuringDryRun) { // Advance to dry run vote request phase. NetworkInterfaceMock* net = getNet(); net->enterNetwork(); - while (TopologyCoordinator::Role::candidate != getTopoCoord().getRole()) { + while (TopologyCoordinator::Role::kCandidate != getTopoCoord().getRole()) { net->runUntil(net->now() + Seconds(1)); if (!net->hasReadyRequests()) { continue; @@ -1925,7 +1925,7 @@ TEST_F(ReplCoordTest, NodeCancelsElectionUponReceivingANewConfigDuringDryRun) { } } net->exitNetwork(); - ASSERT(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // Submit a reconfig and confirm it cancels the election. ReplicationCoordinatorImpl::ReplSetReconfigArgs config = { @@ -1947,7 +1947,7 @@ TEST_F(ReplCoordTest, NodeCancelsElectionUponReceivingANewConfigDuringDryRun) { net->enterNetwork(); net->runReadyNetworkOperations(); net->exitNetwork(); - ASSERT(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(ReplCoordTest, NodeCancelsElectionUponReceivingANewConfigDuringVotePhase) { @@ -1971,7 +1971,7 @@ TEST_F(ReplCoordTest, NodeCancelsElectionUponReceivingANewConfigDuringVotePhase) getReplCoord()->setMyLastDurableOpTime(OpTime(Timestamp(100, 0), 0)); simulateEnoughHeartbeatsForAllNodesUp(); simulateSuccessfulDryRun(); - ASSERT(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // Submit a reconfig and confirm it cancels the election. ReplicationCoordinatorImpl::ReplSetReconfigArgs config = { @@ -1993,7 +1993,7 @@ TEST_F(ReplCoordTest, NodeCancelsElectionUponReceivingANewConfigDuringVotePhase) getNet()->enterNetwork(); getNet()->runReadyNetworkOperations(); getNet()->exitNetwork(); - ASSERT(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } class PrimaryCatchUpTest : public ReplCoordTest { diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index a7201c03d32..c8058823ab8 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -2583,7 +2583,7 @@ TEST_F(ReplCoordTest, DoNotAllowSettingMaintenanceModeWhileConductingAnElection) .transitional_ignore(); // Can't modify maintenance mode when running for election (before and after dry run). - ASSERT_EQUALS(TopologyCoordinator::Role::follower, getTopoCoord().getRole()); + ASSERT_EQUALS(TopologyCoordinator::Role::kFollower, getTopoCoord().getRole()); auto net = this->getNet(); net->enterNetwork(); auto when = getReplCoord()->getElectionTimeout_forTest(); @@ -2596,14 +2596,14 @@ TEST_F(ReplCoordTest, DoNotAllowSettingMaintenanceModeWhileConductingAnElection) } ASSERT_EQUALS(when, net->now()); net->exitNetwork(); - ASSERT_EQUALS(TopologyCoordinator::Role::candidate, getTopoCoord().getRole()); + ASSERT_EQUALS(TopologyCoordinator::Role::kCandidate, getTopoCoord().getRole()); Status status = getReplCoord()->setMaintenanceMode(false); ASSERT_EQUALS(ErrorCodes::NotSecondary, status); status = getReplCoord()->setMaintenanceMode(true); ASSERT_EQUALS(ErrorCodes::NotSecondary, status); simulateSuccessfulDryRun(); - ASSERT_EQUALS(TopologyCoordinator::Role::candidate, getTopoCoord().getRole()); + ASSERT_EQUALS(TopologyCoordinator::Role::kCandidate, getTopoCoord().getRole()); status = getReplCoord()->setMaintenanceMode(false); ASSERT_EQUALS(ErrorCodes::NotSecondary, status); status = getReplCoord()->setMaintenanceMode(true); diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp index ffca19a4949..4779e3f897f 100644 --- a/src/mongo/db/repl/topology_coordinator.cpp +++ b/src/mongo/db/repl/topology_coordinator.cpp @@ -74,25 +74,13 @@ MONGO_FP_DECLARE(disableMaxSyncSourceLagSecs); constexpr Milliseconds TopologyCoordinator::PingStats::UninitializedPing; -namespace { -constexpr int kLeaderValue = 0; -constexpr int kFollowerValue = 1; -constexpr int kCandidateValue = 2; -} // namespace - -const TopologyCoordinator::Role TopologyCoordinator::Role::leader(kLeaderValue); -const TopologyCoordinator::Role TopologyCoordinator::Role::follower(kFollowerValue); -const TopologyCoordinator::Role TopologyCoordinator::Role::candidate(kCandidateValue); - -TopologyCoordinator::Role::Role(int value) : _value(value) {} - -std::string TopologyCoordinator::Role::toString() const { - switch (_value) { - case kLeaderValue: +std::string TopologyCoordinator::roleToString(TopologyCoordinator::Role role) { + switch (role) { + case TopologyCoordinator::Role::kLeader: return "leader"; - case kFollowerValue: + case TopologyCoordinator::Role::kFollower: return "follower"; - case kCandidateValue: + case TopologyCoordinator::Role::kCandidate: return "candidate"; } invariant(false); @@ -101,7 +89,7 @@ std::string TopologyCoordinator::Role::toString() const { TopologyCoordinator::~TopologyCoordinator() {} std::ostream& operator<<(std::ostream& os, TopologyCoordinator::Role role) { - return os << role.toString(); + return os << TopologyCoordinator::roleToString(role); } std::ostream& operator<<(std::ostream& os, @@ -175,7 +163,7 @@ void TopologyCoordinator::PingStats::miss() { } TopologyCoordinator::TopologyCoordinator(Options options) - : _role(Role::follower), + : _role(Role::kFollower), _term(OpTime::kUninitializedTerm), _currentPrimaryIndex(-1), _forceSyncSourceIndex(-1), @@ -1570,9 +1558,9 @@ Status TopologyCoordinator::checkShouldStandForElection(Date_t now) const { if (_currentPrimaryIndex != -1) { return {ErrorCodes::NodeNotElectable, "Not standing for election since there is a Primary"}; } - invariant(_role != Role::leader); + invariant(_role != Role::kLeader); - if (_role == Role::candidate) { + if (_role == Role::kCandidate) { return {ErrorCodes::NodeNotElectable, "Not standing for election again; already candidate"}; } @@ -1709,7 +1697,7 @@ bool TopologyCoordinator::_amIFreshEnoughForCatchupTakeover() const { } bool TopologyCoordinator::_iAmPrimary() const { - if (_role == Role::leader) { + if (_role == Role::kLeader) { invariant(_currentPrimaryIndex == _selfIndex); invariant(_leaderMode != LeaderMode::kNotLeader); return true; @@ -1804,15 +1792,15 @@ void TopologyCoordinator::changeMemberState_forTest(const MemberState& newMember return; switch (newMemberState.s) { case MemberState::RS_PRIMARY: - _role = Role::candidate; + _role = Role::kCandidate; processWinElection(OID(), electionTime); - invariant(_role == Role::leader); + invariant(_role == Role::kLeader); break; case MemberState::RS_SECONDARY: case MemberState::RS_ROLLBACK: case MemberState::RS_RECOVERING: case MemberState::RS_STARTUP2: - _role = Role::follower; + _role = Role::kFollower; _followerMode = newMemberState.s; if (_currentPrimaryIndex == _selfIndex) { _currentPrimaryIndex = -1; @@ -2185,10 +2173,10 @@ void TopologyCoordinator::fillIsMasterForReplSet(IsMasterResponse* response) { StatusWith<TopologyCoordinator::PrepareFreezeResponseResult> TopologyCoordinator::prepareFreezeResponse(Date_t now, int secs, BSONObjBuilder* response) { - if (_role != TopologyCoordinator::Role::follower) { + if (_role != TopologyCoordinator::Role::kFollower) { std::string msg = str::stream() << "cannot freeze node when primary or running for election. state: " - << (_role == TopologyCoordinator::Role::leader ? "Primary" : "Running-Election"); + << (_role == TopologyCoordinator::Role::kLeader ? "Primary" : "Running-Election"); log() << msg; return Status(ErrorCodes::NotSecondary, msg); } @@ -2203,7 +2191,7 @@ TopologyCoordinator::prepareFreezeResponse(Date_t now, int secs, BSONObjBuilder* // we're electable, we're not in maintenance mode, and we are currently in followerMode // SECONDARY, we must transition to candidate now that our stepdown period // is no longer active, in leiu of heartbeats. - _role = Role::candidate; + _role = Role::kCandidate; return PrepareFreezeResponseResult::kElectSelf; } } else { @@ -2226,7 +2214,7 @@ bool TopologyCoordinator::becomeCandidateIfStepdownPeriodOverAndSingleNodeSet(Da // If the new config describes a one-node replica set, we're the one member, // we're electable, we're not in maintenance mode, and we are currently in followerMode // SECONDARY, we must transition to candidate, in leiu of heartbeats. - _role = Role::candidate; + _role = Role::kCandidate; return true; } return false; @@ -2303,7 +2291,7 @@ void TopologyCoordinator::_updateHeartbeatDataForReconfig(const ReplSetConfig& n // This function installs a new config object and recreates MemberData objects // that reflect the new config. void TopologyCoordinator::updateConfig(const ReplSetConfig& newConfig, int selfIndex, Date_t now) { - invariant(_role != Role::candidate); + invariant(_role != Role::kCandidate); invariant(selfIndex < newConfig.getNumMembers()); // Reset term on startup and upgrade/downgrade of protocol version. @@ -2323,7 +2311,7 @@ void TopologyCoordinator::updateConfig(const ReplSetConfig& newConfig, int selfI _selfIndex = selfIndex; _forceSyncSourceIndex = -1; - if (_role == Role::leader) { + if (_role == Role::kLeader) { if (_selfIndex == -1) { log() << "Could not remain primary because no longer a member of the replica set"; } else if (!_selfConfig().isElectable()) { @@ -2333,18 +2321,18 @@ void TopologyCoordinator::updateConfig(const ReplSetConfig& newConfig, int selfI _currentPrimaryIndex = _selfIndex; return; } - _role = Role::follower; + _role = Role::kFollower; _setLeaderMode(LeaderMode::kNotLeader); } - // By this point we know we are in Role::follower + // By this point we know we are in Role::kFollower _currentPrimaryIndex = -1; // force secondaries to re-detect who the primary is if (_isElectableNodeInSingleNodeReplicaSet()) { // If the new config describes a one-node replica set, we're the one member, // we're electable, we're not in maintenance mode and we are currently in followerMode // SECONDARY, we must transition to candidate, in leiu of heartbeats. - _role = Role::candidate; + _role = Role::kCandidate; } } std::string TopologyCoordinator::_getHbmsg(Date_t now) const { @@ -2592,7 +2580,7 @@ std::vector<HostAndPort> TopologyCoordinator::getMaybeUpHostAndPorts() const { } bool TopologyCoordinator::voteForMyself(Date_t now) { - if (_role != Role::candidate) { + if (_role != Role::kCandidate) { return false; } int selfId = _selfConfig().getId(); @@ -2664,7 +2652,7 @@ MemberState TopologyCoordinator::getMemberState() const { } } - if (_role == Role::leader) { + if (_role == Role::kLeader) { invariant(_currentPrimaryIndex == _selfIndex); invariant(_leaderMode != LeaderMode::kNotLeader); return MemberState::RS_PRIMARY; @@ -2685,15 +2673,15 @@ bool TopologyCoordinator::canAcceptWrites() const { } void TopologyCoordinator::setElectionInfo(OID electionId, Timestamp electionOpTime) { - invariant(_role == Role::leader); + invariant(_role == Role::kLeader); _electionTime = electionOpTime; _electionId = electionId; } void TopologyCoordinator::processWinElection(OID electionId, Timestamp electionOpTime) { - invariant(_role == Role::candidate); + invariant(_role == Role::kCandidate); invariant(_leaderMode == LeaderMode::kNotLeader); - _role = Role::leader; + _role = Role::kLeader; _setLeaderMode(LeaderMode::kLeaderElect); setElectionInfo(electionId, electionOpTime); _currentPrimaryIndex = _selfIndex; @@ -2705,12 +2693,12 @@ void TopologyCoordinator::processWinElection(OID electionId, Timestamp electionO } void TopologyCoordinator::processLoseElection() { - invariant(_role == Role::candidate); + invariant(_role == Role::kCandidate); invariant(_leaderMode == LeaderMode::kNotLeader); const HostAndPort syncSourceAddress = getSyncSourceAddress(); _electionTime = Timestamp(0, 0); _electionId = OID(); - _role = Role::follower; + _role = Role::kFollower; // Clear voteLease time, if we voted for ourselves in this election. // This will allow us to vote for others. @@ -2722,7 +2710,8 @@ void TopologyCoordinator::processLoseElection() { bool TopologyCoordinator::attemptStepDown( long long termAtStart, Date_t now, Date_t waitUntil, Date_t stepDownUntil, bool force) { - if (_role != Role::leader || _leaderMode == LeaderMode::kSteppingDown || _term != termAtStart) { + if (_role != Role::kLeader || _leaderMode == LeaderMode::kSteppingDown || + _term != termAtStart) { uasserted(ErrorCodes::PrimarySteppedDown, "While waiting for secondaries to catch up before stepping down, " "this node decided to step down for other reasons"); @@ -2800,7 +2789,7 @@ bool TopologyCoordinator::isSafeToStepDown() { } void TopologyCoordinator::setFollowerMode(MemberState::MS newMode) { - invariant(_role == Role::follower); + invariant(_role == Role::kFollower); switch (newMode) { case MemberState::RS_RECOVERING: case MemberState::RS_ROLLBACK: @@ -2821,7 +2810,7 @@ void TopologyCoordinator::setFollowerMode(MemberState::MS newMode) { // heartbeats that would normally change the role to candidate. if (_isElectableNodeInSingleNodeReplicaSet()) { - _role = Role::candidate; + _role = Role::kCandidate; } } @@ -2857,12 +2846,12 @@ void TopologyCoordinator::finishUnconditionalStepDown() { } void TopologyCoordinator::_stepDownSelfAndReplaceWith(int newPrimary) { - invariant(_role == Role::leader); + invariant(_role == Role::kLeader); invariant(_selfIndex != -1); invariant(_selfIndex != newPrimary); invariant(_selfIndex == _currentPrimaryIndex); _currentPrimaryIndex = newPrimary; - _role = Role::follower; + _role = Role::kFollower; _setLeaderMode(LeaderMode::kNotLeader); } @@ -2955,7 +2944,7 @@ Status TopologyCoordinator::completeTransitionToPrimary(const OpTime& firstOpTim } void TopologyCoordinator::adjustMaintenanceCountBy(int inc) { - invariant(_role == Role::follower); + invariant(_role == Role::kFollower); _maintenanceModeCalls += inc; invariant(_maintenanceModeCalls >= 0); } @@ -3209,11 +3198,11 @@ void TopologyCoordinator::setPrimaryIndex(long long primaryIndex) { Status TopologyCoordinator::becomeCandidateIfElectable(const Date_t now, StartElectionReason reason) { - if (_role == Role::leader) { + if (_role == Role::kLeader) { return {ErrorCodes::NodeNotElectable, "Not standing for election again; already primary"}; } - if (_role == Role::candidate) { + if (_role == Role::kCandidate) { return {ErrorCodes::NodeNotElectable, "Not standing for election again; already candidate"}; } @@ -3225,7 +3214,7 @@ Status TopologyCoordinator::becomeCandidateIfElectable(const Date_t now, } // All checks passed, become a candidate and start election proceedings. - _role = Role::candidate; + _role = Role::kCandidate; return Status::OK(); } diff --git a/src/mongo/db/repl/topology_coordinator.h b/src/mongo/db/repl/topology_coordinator.h index eca071e590a..34ca9906d05 100644 --- a/src/mongo/db/repl/topology_coordinator.h +++ b/src/mongo/db/repl/topology_coordinator.h @@ -72,39 +72,7 @@ public: * map to the follower role, and MemberState::RS_SECONDARY maps to either * follower or candidate roles, e.g. */ - class Role { - public: - /** - * Constant indicating leader role. - */ - static const Role leader; - - /** - * Constant indicating follower role. - */ - static const Role follower; - - /** - * Constant indicating candidate role - */ - static const Role candidate; - - Role() {} - - bool operator==(Role other) const { - return _value == other._value; - } - bool operator!=(Role other) const { - return _value != other._value; - } - - std::string toString() const; - - private: - explicit Role(int value); - - int _value; - }; + enum class Role { kLeader = 0, kFollower = 1, kCandidate = 2 }; struct Options { // A sync source is re-evaluated after it lags behind further than this amount. @@ -782,6 +750,9 @@ public: // Returns _electionId. Only used in unittests. OID getElectionId() const; + // Returns the name for a role. Only used in unittests. + static std::string roleToString(TopologyCoordinator::Role role); + private: typedef int UnelectableReasonMask; class PingStats; diff --git a/src/mongo/db/repl/topology_coordinator_test.cpp b/src/mongo/db/repl/topology_coordinator_test.cpp index 034aaabda89..9f738b17d5a 100644 --- a/src/mongo/db/repl/topology_coordinator_test.cpp +++ b/src/mongo/db/repl/topology_coordinator_test.cpp @@ -2411,7 +2411,7 @@ public: _target, makeStatusWith<ReplSetHeartbeatResponse>()); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::NoAction, upAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Time of first request for this heartbeat period @@ -2431,7 +2431,7 @@ public: StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::ExceededTimeLimit, "Took too long")); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because the heartbeat failed without timing out, we expect to retry immediately. ASSERT_EQUALS(_firstRequestDate + Seconds(4), action.getNextHeartbeatStartDate()); @@ -2488,7 +2488,7 @@ public: target(), StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::NodeNotFound, "Bad DNS?")); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because the first retry failed without timing out, we expect to retry immediately. ASSERT_EQUALS(firstRequestDate() + Milliseconds(4500), action.getNextHeartbeatStartDate()); @@ -2678,7 +2678,7 @@ TEST_F(HeartbeatResponseTestOneRetry, ReconfigWhenHeartbeatResponseContainsAConf target(), StatusWith<ReplSetHeartbeatResponse>(reconfigResponse)); ASSERT_EQUALS(HeartbeatResponseAction::Reconfig, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(firstRequestDate() + Milliseconds(6500), action.getNextHeartbeatStartDate()); } @@ -2736,12 +2736,12 @@ TEST_F(HeartbeatResponseTestOneRetry, StepDownSelfWhenRemoteNodeWasElectedMoreRe ASSERT_EQUALS(0, action.getPrimaryConfigIndex()); ASSERT_EQUALS(firstRequestDate() + Milliseconds(6500), action.getNextHeartbeatStartDate()); // Doesn't actually do the stepdown until stepDownIfPending is called - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); getTopoCoord().prepareForUnconditionalStepDown(); getTopoCoord().finishUnconditionalStepDown(); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(1, getCurrentPrimaryIndex()); } @@ -2774,7 +2774,7 @@ TEST_F(HeartbeatResponseTestOneRetry, target(), StatusWith<ReplSetHeartbeatResponse>(startElectionResponse)); ASSERT_EQUALS(HeartbeatResponseAction::StartElection, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(firstRequestDate() + Milliseconds(6500), action.getNextHeartbeatStartDate()); } @@ -2796,7 +2796,7 @@ TEST_F(HeartbeatResponseTestTwoRetries, NodeDoesNotRetryHeartbeatsAfterFailingTw target(), StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::NodeNotFound, "Bad DNS?")); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because this is the second retry, rather than retry again, we expect to wait for the // heartbeat interval of 2 seconds to elapse. ASSERT_EQUALS(firstRequestDate() + Milliseconds(6800), action.getNextHeartbeatStartDate()); @@ -2852,7 +2852,7 @@ TEST_F(HeartbeatResponseTestTwoRetries, ReconfigWhenHeartbeatResponseContainsACo target(), StatusWith<ReplSetHeartbeatResponse>(reconfigResponse)); ASSERT_EQUALS(HeartbeatResponseAction::Reconfig, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(firstRequestDate() + Milliseconds(6500), action.getNextHeartbeatStartDate()); } @@ -2910,12 +2910,12 @@ TEST_F(HeartbeatResponseTestTwoRetries, StepDownSelfWhenRemoteNodeWasElectedMore ASSERT_EQUALS(0, action.getPrimaryConfigIndex()); ASSERT_EQUALS(firstRequestDate() + Milliseconds(7000), action.getNextHeartbeatStartDate()); // Doesn't actually do the stepdown until stepDownIfPending is called - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); getTopoCoord().prepareForUnconditionalStepDown(); getTopoCoord().finishUnconditionalStepDown(); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(1, getCurrentPrimaryIndex()); } @@ -2948,7 +2948,7 @@ TEST_F(HeartbeatResponseTestTwoRetries, target(), StatusWith<ReplSetHeartbeatResponse>(startElectionResponse)); ASSERT_EQUALS(HeartbeatResponseAction::StartElection, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(firstRequestDate() + Milliseconds(7000), action.getNextHeartbeatStartDate()); } @@ -2974,7 +2974,7 @@ TEST_F(HeartbeatResponseTest, NodeDoesNotRetryHeartbeatIfTheFirstFailureTakesThe StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::ExceededTimeLimit, "Took too long")); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because the heartbeat timed out, we'll retry in 2 seconds. ASSERT_EQUALS(firstRequestDate + Milliseconds(7000), action.getNextHeartbeatStartDate()); } @@ -2991,7 +2991,7 @@ TEST_F(HeartbeatResponseTestOneRetry, StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::ExceededTimeLimit, "Took too long")); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because the heartbeat timed out, we'll retry in 2 seconds. ASSERT_EQUALS(firstRequestDate() + Milliseconds(7010), action.getNextHeartbeatStartDate()); } @@ -3015,7 +3015,7 @@ TEST_F(HeartbeatResponseTestTwoRetries, StatusWith<ReplSetHeartbeatResponse>(response)); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because the heartbeat succeeded, we'll retry in 2 seconds. ASSERT_EQUALS(firstRequestDate() + Milliseconds(6500), action.getNextHeartbeatStartDate()); @@ -3030,7 +3030,7 @@ TEST_F(HeartbeatResponseTestTwoRetries, StatusWith<ReplSetHeartbeatResponse>(Status{ErrorCodes::HostUnreachable, ""})); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Ensure a third nonconsecutive heartbeat failure did not cause the node to be marked down BSONObjBuilder statusBuilder; @@ -3059,7 +3059,7 @@ TEST_F(HeartbeatResponseTest, UpdatePrimaryIndexWhenAHeartbeatMakesNodeAwareOfAN HostAndPort("host2"), "rs0", MemberState::RS_PRIMARY, election, election); ASSERT_EQUALS(1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTest, @@ -3080,7 +3080,7 @@ TEST_F(HeartbeatResponseTest, // second primary does not change primary index ASSERT_EQUALS(1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTest, @@ -3101,7 +3101,7 @@ TEST_F(HeartbeatResponseTest, // second primary does not change primary index ASSERT_EQUALS(1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTest, @@ -3119,7 +3119,7 @@ TEST_F(HeartbeatResponseTest, ASSERT_EQUALS(0, getCurrentPrimaryIndex()); ASSERT_EQUALS(HeartbeatResponseAction::StepDownRemotePrimary, nextAction.getAction()); ASSERT_EQUALS(1, nextAction.getPrimaryConfigIndex()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); } // TODO(dannenberg) figure out what this is about... @@ -3297,12 +3297,12 @@ TEST_F(HeartbeatResponseTest, StepDownSelfWhenRemoteNodeWasElectedMoreRecently) ASSERT_EQUALS(HeartbeatResponseAction::StepDownSelf, nextAction.getAction()); ASSERT_EQUALS(0, nextAction.getPrimaryConfigIndex()); // Doesn't actually do the stepdown until stepDownIfPending is called - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); getTopoCoord().prepareForUnconditionalStepDown(); getTopoCoord().finishUnconditionalStepDown(); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(1, getCurrentPrimaryIndex()); } @@ -3322,7 +3322,7 @@ TEST_F(HeartbeatResponseTest, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTest, @@ -3361,7 +3361,7 @@ TEST_F(HeartbeatResponseTest, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTest, @@ -3384,7 +3384,7 @@ TEST_F(HeartbeatResponseTest, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTest, @@ -3403,7 +3403,7 @@ TEST_F(HeartbeatResponseTest, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_NO_ACTION(nextAction.getAction()); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTest, @@ -3432,7 +3432,7 @@ TEST_F(HeartbeatResponseTest, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTest, @@ -3468,7 +3468,7 @@ TEST_F(HeartbeatResponseTest, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_NO_ACTION(nextAction.getAction()); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTest, StartElectionWhenPrimaryIsMarkedDownAndWeAreElectable) { @@ -3491,7 +3491,7 @@ TEST_F(HeartbeatResponseTest, StartElectionWhenPrimaryIsMarkedDownAndWeAreElecta nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_EQUALS(HeartbeatResponseAction::StartElection, nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTest, NodeDoesNotStartElectionWhileAlreadyCandidate) { @@ -3530,7 +3530,7 @@ TEST_F(HeartbeatResponseTest, NodeDoesNotStartElectionWhileAlreadyCandidate) { nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_EQUALS(HeartbeatResponseAction::StartElection, nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // see the downed node as SECONDARY and decide to take no action, but are still a candidate nextAction = receiveUpHeartbeat( @@ -3539,7 +3539,7 @@ TEST_F(HeartbeatResponseTest, NodeDoesNotStartElectionWhileAlreadyCandidate) { // normally this would trigger StartElection, but we are already a candidate ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // now voteForSelf as though we received all our fresh responses ASSERT_TRUE(getTopoCoord().voteForMyself(now()++)); @@ -3548,7 +3548,7 @@ TEST_F(HeartbeatResponseTest, NodeDoesNotStartElectionWhileAlreadyCandidate) { getTopoCoord().processWinElection(round, election.getTimestamp()); ASSERT_EQUALS(round, getTopoCoord().getElectionId()); ASSERT_EQUALS(election.getTimestamp(), getTopoCoord().getElectionTime()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); } @@ -3589,7 +3589,7 @@ TEST_F(HeartbeatResponseTest, LoseElectionWhenVotingForAnotherNodeWhileRunningTh nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_EQUALS(HeartbeatResponseAction::StartElection, nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); Timestamp originalElectionTime = getTopoCoord().getElectionTime(); OID originalElectionId = getTopoCoord().getElectionId(); @@ -3610,7 +3610,7 @@ TEST_F(HeartbeatResponseTest, LoseElectionWhenVotingForAnotherNodeWhileRunningTh ASSERT_EQUALS(lastOpTimeApplied.getTimestamp(), Timestamp(response["opTime"].timestampValue())); ASSERT_FALSE(response["fresher"].trueValue()); ASSERT_FALSE(response["veto"].trueValue()); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // make sure incoming fresh commands do not change electionTime and electionId ASSERT_EQUALS(originalElectionTime, getTopoCoord().getElectionTime()); ASSERT_EQUALS(originalElectionId, getTopoCoord().getElectionId()); @@ -3633,7 +3633,7 @@ TEST_F(HeartbeatResponseTest, LoseElectionWhenVotingForAnotherNodeWhileRunningTh ASSERT_EQUALS(1, response["vote"].Int()); ASSERT_EQUALS(round, response["round"].OID()); ASSERT_EQUALS(1, countLogLinesContaining("voting yea for host3:27017 (2)")); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // make sure incoming elect commands do not change electionTime and electionId ASSERT_EQUALS(originalElectionTime, getTopoCoord().getElectionTime()); ASSERT_EQUALS(originalElectionId, getTopoCoord().getElectionId()); @@ -3654,7 +3654,7 @@ TEST_F(HeartbeatResponseTest, LoseElectionWhenVotingForAnotherNodeWhileRunningTh getTopoCoord().processLoseElection(); ASSERT_EQUALS(OID(), getTopoCoord().getElectionId()); ASSERT_EQUALS(Timestamp(), getTopoCoord().getElectionTime()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(2, getCurrentPrimaryIndex()); } @@ -3698,7 +3698,7 @@ TEST_F(HeartbeatResponseTest, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_EQUALS(HeartbeatResponseAction::StartElection, nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // prepare an incoming fresh command ReplicationCoordinator::ReplSetFreshArgs freshArgs; @@ -3717,7 +3717,7 @@ TEST_F(HeartbeatResponseTest, ASSERT_EQUALS(lastOpTimeApplied.getTimestamp(), Timestamp(response["opTime"].timestampValue())); ASSERT_FALSE(response["fresher"].trueValue()); ASSERT_FALSE(response["veto"].trueValue()); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // now voteForSelf as though we received all our fresh responses ASSERT_TRUE(getTopoCoord().voteForMyself(now()++)); @@ -3725,7 +3725,7 @@ TEST_F(HeartbeatResponseTest, getTopoCoord().processWinElection(round, election.getTimestamp()); ASSERT_EQUALS(round, getTopoCoord().getElectionId()); ASSERT_EQUALS(election.getTimestamp(), getTopoCoord().getElectionTime()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); // an elect command comes in @@ -3744,7 +3744,7 @@ TEST_F(HeartbeatResponseTest, ASSERT_OK(result); ASSERT_EQUALS(-10000, response["vote"].Int()); ASSERT_EQUALS(remoteRound, response["round"].OID()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); } @@ -3788,14 +3788,14 @@ TEST_F(HeartbeatResponseTest, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_EQUALS(HeartbeatResponseAction::StartElection, nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // now voteForSelf as though we received all our fresh responses ASSERT_TRUE(getTopoCoord().voteForMyself(now()++)); // now win election getTopoCoord().processWinElection(round, election.getTimestamp()); ASSERT_EQUALS(0, getTopoCoord().getCurrentPrimaryIndex()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); // prepare an incoming fresh command ReplicationCoordinator::ReplSetFreshArgs freshArgs; @@ -3814,7 +3814,7 @@ TEST_F(HeartbeatResponseTest, ASSERT_EQUALS(lastOpTimeApplied.getTimestamp(), Timestamp(response["opTime"].timestampValue())); ASSERT_FALSE(response["fresher"].trueValue()); ASSERT_TRUE(response["veto"].trueValue()) << response["errmsg"]; - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); // an elect command comes in @@ -3833,7 +3833,7 @@ TEST_F(HeartbeatResponseTest, ASSERT_OK(result); ASSERT_EQUALS(-10000, response["vote"].Int()); ASSERT_EQUALS(remoteRound, response["round"].OID()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); } @@ -3907,7 +3907,7 @@ TEST_F(HeartbeatResponseTest, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", lastOpTimeApplied); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_EQUALS(HeartbeatResponseAction::StartElection, nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTest, RelinquishPrimaryWhenMajorityOfVotersIsNoLongerVisible) { @@ -3932,12 +3932,12 @@ TEST_F(HeartbeatResponseTest, RelinquishPrimaryWhenMajorityOfVotersIsNoLongerVis ASSERT_EQUALS(HeartbeatResponseAction::StepDownSelf, nextAction.getAction()); ASSERT_EQUALS(0, nextAction.getPrimaryConfigIndex()); // Doesn't actually do the stepdown until stepDownIfPending is called - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); getTopoCoord().prepareForUnconditionalStepDown(); getTopoCoord().finishUnconditionalStepDown(); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); } @@ -4407,7 +4407,7 @@ TEST_F(TopoCoordTest, TopologyCoordinator::PrepareFreezeResponseResult::kElectSelf, unittest::assertGet(getTopoCoord().prepareFreezeResponse(now()++, 0, &response2))); ASSERT_EQUALS("unfreezing", response2.obj()["info"].String()); - ASSERT(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // prepareFreezeResult returns error if we are running for election. auto result = getTopoCoord().prepareFreezeResponse(now()++, 20, &response); @@ -4436,14 +4436,14 @@ TEST_F(TopoCoordTest, DoNotBecomeCandidateOnUnfreezingInMaintenanceMode) { ASSERT(response.obj().isEmpty()); BSONObjBuilder response2; - // We should not transition to Role::candidate if we are in maintenance upon unfreezing. + // We should not transition to Role::kCandidate if we are in maintenance upon unfreezing. getTopoCoord().adjustMaintenanceCountBy(1); ASSERT_EQUALS( TopologyCoordinator::PrepareFreezeResponseResult::kNoAction, unittest::assertGet(getTopoCoord().prepareFreezeResponse(now()++, 0, &response2))); ASSERT_EQUALS("unfreezing", response2.obj()["info"].String()); - ASSERT(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } class PrepareHeartbeatResponseTest : public TopoCoordTest { @@ -4761,7 +4761,7 @@ TEST_F(PrepareHeartbeatResponseTest, } TEST_F(TopoCoordTest, BecomeCandidateWhenBecomingSecondaryInSingleNodeSet) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" @@ -4774,14 +4774,14 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenBecomingSecondaryInSingleNodeSet) { ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); // if we are the only node, we should become a candidate when we transition to SECONDARY - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, BecomeCandidateWhenReconfigToBeElectableInSingleNodeSet) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); ReplSetConfig cfg; cfg.initialize(BSON("_id" @@ -4797,9 +4797,9 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenReconfigToBeElectableInSingleNodeSet) { getTopoCoord().updateConfig(cfg, 0, now()++); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); // we should become a candidate when we reconfig to become electable @@ -4812,11 +4812,11 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenReconfigToBeElectableInSingleNodeSet) { << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself"))), 0); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); } TEST_F(TopoCoordTest, NodeDoesNotBecomeCandidateWhenBecomingSecondaryInSingleNodeSetIfUnelectable) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); ReplSetConfig cfg; cfg.initialize(BSON("_id" @@ -4834,14 +4834,14 @@ TEST_F(TopoCoordTest, NodeDoesNotBecomeCandidateWhenBecomingSecondaryInSingleNod ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); // despite being the only node, we are unelectable, so we should not become a candidate - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, NodeTransitionsFromRemovedToStartup2WhenAddedToConfig) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); // config to be absent from the set updateConfig(BSON("_id" @@ -4855,7 +4855,7 @@ TEST_F(TopoCoordTest, NodeTransitionsFromRemovedToStartup2WhenAddedToConfig) { << "host3:27017"))), -1); // should become removed since we are not in the set - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_REMOVED, getTopoCoord().getMemberState().s); // reconfig to add to set @@ -4872,12 +4872,12 @@ TEST_F(TopoCoordTest, NodeTransitionsFromRemovedToStartup2WhenAddedToConfig) { << "host3:27017"))), 0); // having been added to the config, we should no longer be REMOVED and should enter STARTUP2 - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfig) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" @@ -4891,7 +4891,7 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfig) { << BSON("_id" << 2 << "host" << "host3:27017"))), 0); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); // reconfig to remove self @@ -4906,12 +4906,12 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfig) { << "host3:27017"))), -1); // should become removed since we are no longer in the set - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_REMOVED, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfigEvenWhenPrimary) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" @@ -4921,14 +4921,14 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfigEvenWhenPrima << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017"))), 0); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // win election and primary getTopoCoord().processWinElection(OID::gen(), Timestamp()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); // reconfig to remove self @@ -4943,12 +4943,12 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfigEvenWhenPrima << "host3:27017"))), -1); // should become removed since we are no longer in the set even though we were primary - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_REMOVED, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, NodeTransitionsToSecondaryWhenReconfiggingToBeUnelectable) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" @@ -4958,14 +4958,14 @@ TEST_F(TopoCoordTest, NodeTransitionsToSecondaryWhenReconfiggingToBeUnelectable) << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017"))), 0); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // win election and primary getTopoCoord().processWinElection(OID::gen(), Timestamp()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); // now lose primary due to loss of electability @@ -4983,12 +4983,12 @@ TEST_F(TopoCoordTest, NodeTransitionsToSecondaryWhenReconfiggingToBeUnelectable) << BSON("_id" << 2 << "host" << "host3:27017"))), 0); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElectable) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" @@ -4999,14 +4999,14 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta << "host1:27017"))), 0); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // win election and primary getTopoCoord().processWinElection(OID::gen(), Timestamp()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); // Now reconfig in ways that leave us electable and ensure we are still the primary. @@ -5025,7 +5025,7 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta 0, Date_t::fromMillisSinceEpoch(-1), OpTime(Timestamp(10, 0), 0)); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); // Change priorities and tags @@ -5050,7 +5050,7 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta 0, Date_t::fromMillisSinceEpoch(-1), OpTime(Timestamp(10, 0), 0)); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); } @@ -5065,7 +5065,7 @@ TEST_F(TopoCoordTest, NodeMaintainsSecondaryStateAcrossReconfig) { << BSON("_id" << 2 << "host" << "host2:27017"))), 0); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); setSelfMemberState(MemberState::RS_SECONDARY); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); @@ -5083,7 +5083,7 @@ TEST_F(TopoCoordTest, NodeMaintainsSecondaryStateAcrossReconfig) { << BSON("_id" << 2 << "host" << "host3:27017"))), 0); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); } diff --git a/src/mongo/db/repl/topology_coordinator_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_v1_test.cpp index c43c0b53066..5f5524fa089 100644 --- a/src/mongo/db/repl/topology_coordinator_v1_test.cpp +++ b/src/mongo/db/repl/topology_coordinator_v1_test.cpp @@ -2023,7 +2023,7 @@ TEST_F(PrepareHeartbeatResponseV1Test, } TEST_F(TopoCoordTest, BecomeCandidateWhenBecomingSecondaryInSingleNodeSet) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" @@ -2036,14 +2036,14 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenBecomingSecondaryInSingleNodeSet) { ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); // if we are the only node, we should become a candidate when we transition to SECONDARY - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, DoNotBecomeCandidateWhenBecomingSecondaryInSingleNodeSetIfInMaintenanceMode) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" @@ -2057,10 +2057,10 @@ TEST_F(TopoCoordTest, DoNotBecomeCandidateWhenBecomingSecondaryInSingleNodeSetIf // If we are the only node and we are in maintenance mode, we should not become a candidate when // we transition to SECONDARY. - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); getTopoCoord().adjustMaintenanceCountBy(1); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // getMemberState() returns RS_RECOVERING while we are in maintenance mode even though // _memberState is set to RS_SECONDARY. @@ -2072,7 +2072,7 @@ TEST_F(TopoCoordTest, DoNotBecomeCandidateWhenBecomingSecondaryInSingleNodeSetIf } TEST_F(TopoCoordTest, BecomeCandidateWhenReconfigToBeElectableInSingleNodeSet) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); ReplSetConfig cfg; cfg.initialize(BSON("_id" @@ -2088,9 +2088,9 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenReconfigToBeElectableInSingleNodeSet) { getTopoCoord().updateConfig(cfg, 0, now()++); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); // we should become a candidate when we reconfig to become electable @@ -2103,12 +2103,12 @@ TEST_F(TopoCoordTest, BecomeCandidateWhenReconfigToBeElectableInSingleNodeSet) { << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself"))), 0); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); } TEST_F(TopoCoordTest, DoNotBecomeCandidateWhenReconfigToBeElectableInSingleNodeSetIfInMaintenanceMode) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); ReplSetConfig cfg; ASSERT_OK(cfg.initialize(BSON("_id" @@ -2123,9 +2123,9 @@ TEST_F(TopoCoordTest, getTopoCoord().updateConfig(cfg, 0, now()++); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); // We should not become a candidate when we reconfig to become electable if we are currently in @@ -2139,11 +2139,11 @@ TEST_F(TopoCoordTest, << BSON_ARRAY(BSON("_id" << 1 << "host" << "hself"))), 0); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); } TEST_F(TopoCoordTest, NodeDoesNotBecomeCandidateWhenBecomingSecondaryInSingleNodeSetIfUnelectable) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); ReplSetConfig cfg; cfg.initialize(BSON("_id" @@ -2161,14 +2161,14 @@ TEST_F(TopoCoordTest, NodeDoesNotBecomeCandidateWhenBecomingSecondaryInSingleNod ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); // despite being the only node, we are unelectable, so we should not become a candidate - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, NodeTransitionsFromRemovedToStartup2WhenAddedToConfig) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); // config to be absent from the set updateConfig(BSON("_id" @@ -2182,7 +2182,7 @@ TEST_F(TopoCoordTest, NodeTransitionsFromRemovedToStartup2WhenAddedToConfig) { << "host3:27017"))), -1); // should become removed since we are not in the set - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_REMOVED, getTopoCoord().getMemberState().s); // reconfig to add to set @@ -2199,12 +2199,12 @@ TEST_F(TopoCoordTest, NodeTransitionsFromRemovedToStartup2WhenAddedToConfig) { << "host3:27017"))), 0); // having been added to the config, we should no longer be REMOVED and should enter STARTUP2 - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfig) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" @@ -2218,7 +2218,7 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfig) { << BSON("_id" << 2 << "host" << "host3:27017"))), 0); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); // reconfig to remove self @@ -2233,12 +2233,12 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfig) { << "host3:27017"))), -1); // should become removed since we are no longer in the set - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_REMOVED, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfigEvenWhenPrimary) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" @@ -2248,14 +2248,14 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfigEvenWhenPrima << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017"))), 0); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // win election and primary getTopoCoord().processWinElection(OID::gen(), Timestamp()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); // reconfig to remove self @@ -2270,12 +2270,12 @@ TEST_F(TopoCoordTest, NodeTransitionsToRemovedWhenRemovedFromConfigEvenWhenPrima << "host3:27017"))), -1); // should become removed since we are no longer in the set even though we were primary - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_REMOVED, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, NodeTransitionsToSecondaryWhenReconfiggingToBeUnelectable) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" @@ -2285,14 +2285,14 @@ TEST_F(TopoCoordTest, NodeTransitionsToSecondaryWhenReconfiggingToBeUnelectable) << BSON_ARRAY(BSON("_id" << 0 << "host" << "host1:27017"))), 0); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // win election and primary getTopoCoord().processWinElection(OID::gen(), Timestamp()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); // now lose primary due to loss of electability @@ -2310,12 +2310,12 @@ TEST_F(TopoCoordTest, NodeTransitionsToSecondaryWhenReconfiggingToBeUnelectable) << BSON("_id" << 2 << "host" << "host3:27017"))), 0); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); } TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElectable) { - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP, getTopoCoord().getMemberState().s); updateConfig(BSON("_id" << "rs0" @@ -2326,14 +2326,14 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta << "host1:27017"))), 0); - ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_FALSE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); // win election and primary getTopoCoord().processWinElection(OID::gen(), Timestamp()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); // Now reconfig in ways that leave us electable and ensure we are still the primary. @@ -2351,7 +2351,7 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta << "host3:27017"))), 0, Date_t::fromMillisSinceEpoch(-1)); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); // Change priorities and tags @@ -2375,7 +2375,7 @@ TEST_F(TopoCoordTest, NodeMaintainsPrimaryStateAcrossReconfigIfNodeRemainsElecta << "rack1")))), 0, Date_t::fromMillisSinceEpoch(-1)); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); } @@ -2390,7 +2390,7 @@ TEST_F(TopoCoordTest, NodeMaintainsSecondaryStateAcrossReconfig) { << BSON("_id" << 2 << "host" << "host2:27017"))), 0); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); setSelfMemberState(MemberState::RS_SECONDARY); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); @@ -2408,7 +2408,7 @@ TEST_F(TopoCoordTest, NodeMaintainsSecondaryStateAcrossReconfig) { << BSON("_id" << 2 << "host" << "host3:27017"))), 0); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); } @@ -3722,7 +3722,7 @@ TEST_F(HeartbeatResponseTestV1, NodeDoesNotUpdateHeartbeatDataIfNodeIsAbsentFrom HostAndPort("host9"), "rs0", MemberState::RS_PRIMARY, election, election); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, RelinquishPrimaryWhenMajorityOfVotersIsNoLongerVisible) { @@ -3745,7 +3745,7 @@ TEST_F(HeartbeatResponseTestV1, RelinquishPrimaryWhenMajorityOfVotersIsNoLongerV ASSERT_NO_ACTION(nextAction.getAction()); nextAction = receiveDownHeartbeat(HostAndPort("host3"), "rs0"); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); } @@ -4530,11 +4530,11 @@ TEST_F(HeartbeatResponseTestV1, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0"); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // We are electable now. ASSERT_OK(getTopoCoord().becomeCandidateIfElectable( now(), TopologyCoordinator::StartElectionReason::kElectionTimeout)); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, ScheduleElectionWhenPrimaryIsMarkedDownAndWeAreElectable) { @@ -4556,11 +4556,11 @@ TEST_F(HeartbeatResponseTestV1, ScheduleElectionWhenPrimaryIsMarkedDownAndWeAreE nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0"); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // We are electable now. ASSERT_OK(getTopoCoord().becomeCandidateIfElectable( now(), TopologyCoordinator::StartElectionReason::kElectionTimeout)); - ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kCandidate == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, @@ -4599,7 +4599,7 @@ TEST_F(HeartbeatResponseTestV1, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0"); ASSERT_NO_ACTION(nextAction.getAction()); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, @@ -4627,7 +4627,7 @@ TEST_F(HeartbeatResponseTestV1, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0"); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, @@ -4647,7 +4647,7 @@ TEST_F(HeartbeatResponseTestV1, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0"); ASSERT_NO_ACTION(nextAction.getAction()); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, @@ -4671,7 +4671,7 @@ TEST_F(HeartbeatResponseTestV1, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0"); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, @@ -4713,7 +4713,7 @@ TEST_F(HeartbeatResponseTestV1, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0"); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, @@ -4733,7 +4733,7 @@ TEST_F(HeartbeatResponseTestV1, nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0"); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, NodeDoesNotStepDownSelfWhenRemoteNodeWasElectedMoreRecently) { @@ -4750,12 +4750,12 @@ TEST_F(HeartbeatResponseTestV1, NodeDoesNotStepDownSelfWhenRemoteNodeWasElectedM HeartbeatResponseAction nextAction = receiveUpHeartbeat( HostAndPort("host2"), "rs0", MemberState::RS_PRIMARY, election, election); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); // If the other PRIMARY falls down, this node should set its primaryIndex to itself. nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0"); - ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kLeader == getTopoCoord().getRole()); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); } @@ -4970,7 +4970,7 @@ TEST_F(HeartbeatResponseTestV1, // Second primary does not change primary index. ASSERT_EQUALS(1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, @@ -4991,7 +4991,7 @@ TEST_F(HeartbeatResponseTestV1, // Second primary does not change primary index. ASSERT_EQUALS(1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, UpdatePrimaryIndexWhenAHeartbeatMakesNodeAwareOfANewPrimary) { @@ -5004,7 +5004,7 @@ TEST_F(HeartbeatResponseTestV1, UpdatePrimaryIndexWhenAHeartbeatMakesNodeAwareOf HostAndPort("host2"), "rs0", MemberState::RS_PRIMARY, election, election); ASSERT_EQUALS(1, getCurrentPrimaryIndex()); ASSERT_NO_ACTION(nextAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); } TEST_F(HeartbeatResponseTestV1, NodeDoesNotRetryHeartbeatIfTheFirstFailureTakesTheFullTime) { @@ -5029,7 +5029,7 @@ TEST_F(HeartbeatResponseTestV1, NodeDoesNotRetryHeartbeatIfTheFirstFailureTakesT StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::ExceededTimeLimit, "Took too long")); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because the heartbeat timed out, we'll retry sooner. ASSERT_EQUALS(firstRequestDate + Milliseconds(5000) + ReplSetConfig::kDefaultHeartbeatInterval / 4, @@ -5129,7 +5129,7 @@ public: HeartbeatResponseAction upAction = getTopoCoord().processHeartbeatResponse( _upRequestDate, Milliseconds(0), _target, makeStatusWith<ReplSetHeartbeatResponse>()); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, upAction.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Time of first request for this heartbeat period @@ -5150,7 +5150,7 @@ public: ErrorCodes::ExceededTimeLimit, "Took too long")); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because the heartbeat failed without timing out, we expect to retry immediately. ASSERT_EQUALS(_firstRequestDate + Seconds(4), action.getNextHeartbeatStartDate()); @@ -5208,7 +5208,7 @@ TEST_F(HeartbeatResponseTestOneRetryV1, "Took too long")); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because the heartbeat timed out, we'll retry sooner. ASSERT_EQUALS(firstRequestDate() + Milliseconds(5010) + ReplSetConfig::kDefaultHeartbeatInterval / 4, @@ -5227,7 +5227,7 @@ public: target(), StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::NodeNotFound, "Bad DNS?")); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because the first retry failed without timing out, we expect to retry immediately. ASSERT_EQUALS(firstRequestDate() + Milliseconds(4500), action.getNextHeartbeatStartDate()); @@ -5274,7 +5274,7 @@ TEST_F(HeartbeatResponseTestTwoRetriesV1, NodeDoesNotRetryHeartbeatsAfterFailing target(), StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::NodeNotFound, "Bad DNS?")); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because this is the second retry, rather than retry again, we expect to wait for a quarter // of the heartbeat interval to elapse. ASSERT_EQUALS(firstRequestDate() + Milliseconds(4800) + @@ -5316,7 +5316,7 @@ TEST_F(HeartbeatResponseTestTwoRetriesV1, HeartbeatThreeNonconsecutiveFailures) StatusWith<ReplSetHeartbeatResponse>(response)); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Because the heartbeat succeeded, we'll retry sooner. ASSERT_EQUALS(firstRequestDate() + Milliseconds(4500) + ReplSetConfig::kDefaultHeartbeatInterval / 4, @@ -5333,7 +5333,7 @@ TEST_F(HeartbeatResponseTestTwoRetriesV1, HeartbeatThreeNonconsecutiveFailures) StatusWith<ReplSetHeartbeatResponse>(Status{ErrorCodes::HostUnreachable, ""})); ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); - ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); + ASSERT_TRUE(TopologyCoordinator::Role::kFollower == getTopoCoord().getRole()); // Ensure a third nonconsecutive heartbeat failure did not cause the node to be marked down BSONObjBuilder statusBuilder; |