Skip to content

Commit 3939d3c

Browse files
author
matt dannenberg
committed
Revert "SERVER-19956: arbiter uses last committed time during electionswq"
This reverts commit ccbac2b.
1 parent 75f6f24 commit 3939d3c

File tree

3 files changed

+21
-66
lines changed

3 files changed

+21
-66
lines changed

src/mongo/db/repl/replication_coordinator_impl.cpp

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void ReplicationCoordinatorImpl::_finishLoadLocalConfig(
365365
invariant(_rsConfigState == kConfigStartingUp);
366366
const PostMemberStateUpdateAction action =
367367
_setCurrentRSConfig_inlock(localConfig, myIndex.getValue());
368-
_setMyLastOptimeAndReport_inlock(&lk, lastOpTime, false);
368+
_setMyLastOptime_inlock(&lk, lastOpTime, false);
369369
_externalState->setGlobalTimestamp(lastOpTime.getTimestamp());
370370
_updateTerm_incallback(term);
371371
LOG(1) << "Current term is now " << term;
@@ -760,30 +760,39 @@ void ReplicationCoordinatorImpl::setMyHeartbeatMessage(const std::string& msg) {
760760
void ReplicationCoordinatorImpl::setMyLastOptimeForward(const OpTime& opTime) {
761761
stdx::unique_lock<stdx::mutex> lock(_mutex);
762762
if (opTime > _getMyLastOptime_inlock()) {
763-
_setMyLastOptimeAndReport_inlock(&lock, opTime, false);
763+
_setMyLastOptime_inlock(&lock, opTime, false);
764764
}
765765
}
766766

767767
void ReplicationCoordinatorImpl::setMyLastOptime(const OpTime& opTime) {
768768
stdx::unique_lock<stdx::mutex> lock(_mutex);
769-
_setMyLastOptimeAndReport_inlock(&lock, opTime, false);
769+
_setMyLastOptime_inlock(&lock, opTime, false);
770770
}
771771

772772
void ReplicationCoordinatorImpl::resetMyLastOptime() {
773773
stdx::unique_lock<stdx::mutex> lock(_mutex);
774774
// Reset to uninitialized OpTime
775-
_setMyLastOptimeAndReport_inlock(&lock, OpTime(), true);
775+
_setMyLastOptime_inlock(&lock, OpTime(), true);
776776
}
777777

778-
void ReplicationCoordinatorImpl::_setMyLastOptimeAndReport_inlock(
779-
stdx::unique_lock<stdx::mutex>* lock, const OpTime& opTime, bool isRollbackAllowed) {
778+
void ReplicationCoordinatorImpl::_setMyLastOptime_inlock(stdx::unique_lock<stdx::mutex>* lock,
779+
const OpTime& opTime,
780+
bool isRollbackAllowed) {
780781
invariant(lock->owns_lock());
781-
_setMyLastOptime_inlock(opTime, isRollbackAllowed);
782+
SlaveInfo* mySlaveInfo = &_slaveInfo[_getMyIndexInSlaveInfo_inlock()];
783+
invariant(isRollbackAllowed || mySlaveInfo->opTime <= opTime);
784+
_updateSlaveInfoOptime_inlock(mySlaveInfo, opTime);
782785

783786
if (getReplicationMode() != modeReplSet) {
784787
return;
785788
}
786789

790+
for (auto& opTimeWaiter : _opTimeWaiterList) {
791+
if (*(opTimeWaiter->opTime) <= opTime) {
792+
opTimeWaiter->condVar->notify_all();
793+
}
794+
}
795+
787796
if (_getMemberState_inlock().primary()) {
788797
return;
789798
}
@@ -793,19 +802,6 @@ void ReplicationCoordinatorImpl::_setMyLastOptimeAndReport_inlock(
793802
_externalState->forwardSlaveProgress(); // Must do this outside _mutex
794803
}
795804

796-
void ReplicationCoordinatorImpl::_setMyLastOptime_inlock(const OpTime& opTime,
797-
bool isRollbackAllowed) {
798-
SlaveInfo* mySlaveInfo = &_slaveInfo[_getMyIndexInSlaveInfo_inlock()];
799-
invariant(isRollbackAllowed || mySlaveInfo->opTime <= opTime);
800-
_updateSlaveInfoOptime_inlock(mySlaveInfo, opTime);
801-
802-
for (auto& opTimeWaiter : _opTimeWaiterList) {
803-
if (*(opTimeWaiter->opTime) <= opTime) {
804-
opTimeWaiter->condVar->notify_all();
805-
}
806-
}
807-
}
808-
809805
OpTime ReplicationCoordinatorImpl::getMyLastOptime() const {
810806
stdx::lock_guard<stdx::mutex> lock(_mutex);
811807
return _getMyLastOptime_inlock();
@@ -2608,7 +2604,7 @@ void ReplicationCoordinatorImpl::resetLastOpTimeFromOplog(OperationContext* txn)
26082604
lastOpTime = lastOpTimeStatus.getValue();
26092605
}
26102606
stdx::unique_lock<stdx::mutex> lk(_mutex);
2611-
_setMyLastOptimeAndReport_inlock(&lk, lastOpTime, true);
2607+
_setMyLastOptime_inlock(&lk, lastOpTime, true);
26122608
_externalState->setGlobalTimestamp(lastOpTime.getTimestamp());
26132609
}
26142610

@@ -2682,10 +2678,6 @@ void ReplicationCoordinatorImpl::_setLastCommittedOpTime_inlock(const OpTime& co
26822678
return;
26832679
}
26842680

2685-
if (_getMemberState_inlock().arbiter()) {
2686-
_setMyLastOptime_inlock(committedOpTime, false);
2687-
}
2688-
26892681
_lastCommittedOpTime = committedOpTime;
26902682

26912683
auto maxSnapshotForOpTime = SnapshotInfo{committedOpTime, SnapshotName::max()};
@@ -2727,9 +2719,7 @@ Status ReplicationCoordinatorImpl::processReplSetRequestVotes(
27272719
return {ErrorCodes::BadValue, "not using election protocol v1"};
27282720
}
27292721

2730-
auto termStatus = updateTerm(args.getTerm());
2731-
if (!termStatus.isOK())
2732-
return termStatus;
2722+
updateTerm(args.getTerm());
27332723

27342724
Status result{ErrorCodes::InternalError, "didn't set status in processReplSetRequestVotes"};
27352725
CBHStatus cbh = _replExecutor.scheduleWork(

src/mongo/db/repl/replication_coordinator_impl.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,10 @@ class ReplicationCoordinatorImpl : public ReplicationCoordinator, public KillOpL
659659
*
660660
* This function has the same rules for "opTime" as setMyLastOptime(), unless
661661
* "isRollbackAllowed" is true.
662-
*
663-
* This function will also report our position externally (like upstream) if necessary.
664662
*/
665-
void _setMyLastOptimeAndReport_inlock(stdx::unique_lock<stdx::mutex>* lock,
666-
const OpTime& opTime,
667-
bool isRollbackAllowed);
668-
void _setMyLastOptime_inlock(const OpTime& opTime, bool isRollbackAllowed);
663+
void _setMyLastOptime_inlock(stdx::unique_lock<stdx::mutex>* lock,
664+
const OpTime& opTime,
665+
bool isRollbackAllowed);
669666

670667
/**
671668
* Schedules a heartbeat to be sent to "target" at "when". "targetIndex" is the index

src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include "mongo/platform/basic.h"
3232

33-
#include "mongo/bson/json.h"
3433
#include "mongo/db/jsobj.h"
3534
#include "mongo/db/operation_context_noop.h"
3635
#include "mongo/db/repl/repl_set_heartbeat_args.h"
@@ -41,7 +40,6 @@
4140
#include "mongo/db/repl/replication_coordinator_test_fixture.h"
4241
#include "mongo/db/repl/topology_coordinator_impl.h"
4342
#include "mongo/executor/network_interface_mock.h"
44-
#include "mongo/rpc/metadata/repl_set_metadata.h"
4543
#include "mongo/unittest/unittest.h"
4644
#include "mongo/util/log.h"
4745

@@ -258,36 +256,6 @@ TEST_F(ReplCoordHBV1Test, OnlyUnauthorizedUpCausesRecovering) {
258256
assertMemberState(MemberState::RS_RECOVERING, "0");
259257
}
260258

261-
TEST_F(ReplCoordHBV1Test, ArbiterRecordsCommittedOpTimeFromHeartbeat) {
262-
// Tests that an arbiter will update its committed optime from the heartbeat metadata
263-
assertStartSuccess(fromjson(
264-
"{_id:'mySet', version:1, protocolVersion:1, members:["
265-
"{_id:1, host:'node1:12345', arbiterOnly:true}, "
266-
"{_id:2, host:'node2:12345'}]}"),
267-
HostAndPort("node1", 12345));
268-
ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_ARBITER));
269-
270-
// calls processReplSetMetadata with the "committed" optime and verifies that the arbiter sets
271-
// its current optime to 'expected'
272-
auto test = [this](OpTime committedOpTime, OpTime expected) {
273-
// process heartbeat metadata directly
274-
StatusWith<rpc::ReplSetMetadata> metadata = rpc::ReplSetMetadata::readFromMetadata(BSON(
275-
rpc::kReplSetMetadataFieldName << BSON(
276-
"lastOpCommitted" << BSON("ts" << committedOpTime.getTimestamp() << "term"
277-
<< committedOpTime.getTerm()) << "lastOpVisible"
278-
<< BSON("ts" << committedOpTime.getTimestamp() << "term"
279-
<< committedOpTime.getTerm()) << "configVersion" << 1
280-
<< "primaryIndex" << 1 << "term" << committedOpTime.getTerm())));
281-
getReplCoord()->processReplSetMetadata(metadata.getValue());
282-
283-
ASSERT_EQ(getReplCoord()->getMyLastOptime().getTimestamp(), expected.getTimestamp());
284-
};
285-
286-
OpTime committedOpTime{Timestamp{10, 10}, 10};
287-
test(committedOpTime, committedOpTime);
288-
OpTime olderOpTime{Timestamp{2, 2}, 9};
289-
test(olderOpTime, committedOpTime);
290-
}
291259
} // namespace
292260
} // namespace repl
293261
} // namespace mongo

0 commit comments

Comments
 (0)