Skip to content

Commit b2d7021

Browse files
committed
Revert "SERVER-26990 Unify tracking of secondary state between replication and topology coordinators"
This reverts commit 6adc71f.
1 parent 32dccae commit b2d7021

16 files changed

+2164
-1655
lines changed

src/mongo/db/repl/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,6 @@ env.CppUnitTest(
521521
env.Library('topology_coordinator',
522522
[
523523
'heartbeat_response_action.cpp',
524-
'member_heartbeat_data.cpp',
525524
'topology_coordinator.cpp',
526525
],
527526
LIBDEPS=[
@@ -531,6 +530,7 @@ env.Library('topology_coordinator',
531530

532531
env.Library('topology_coordinator_impl',
533532
[
533+
'member_heartbeat_data.cpp',
534534
'topology_coordinator_impl.cpp',
535535
],
536536
LIBDEPS=[

src/mongo/db/repl/heartbeat_response_action.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,5 @@ void HeartbeatResponseAction::setNextHeartbeatStartDate(Date_t when) {
7575
_nextHeartbeatStartDate = when;
7676
}
7777

78-
void HeartbeatResponseAction::setAdvancedOpTime(bool advanced) {
79-
_advancedOpTime = advanced;
80-
}
81-
8278
} // namespace repl
8379
} // namespace mongo

src/mongo/db/repl/heartbeat_response_action.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ class HeartbeatResponseAction {
100100
*/
101101
void setNextHeartbeatStartDate(Date_t when);
102102

103-
/**
104-
* Sets whether or not the heartbeat response advanced the member's opTime.
105-
*/
106-
void setAdvancedOpTime(bool advanced);
107-
108103
/**
109104
* Gets the action type of this action.
110105
*/
@@ -128,19 +123,10 @@ class HeartbeatResponseAction {
128123
return _primaryIndex;
129124
}
130125

131-
/*
132-
* Returns true if the heartbeat response resulting in our conception of the
133-
* member's optime moving forward, so we need to recalculate lastCommittedOpTime.
134-
*/
135-
bool getAdvancedOpTime() const {
136-
return _advancedOpTime;
137-
}
138-
139126
private:
140127
Action _action;
141128
int _primaryIndex;
142129
Date_t _nextHeartbeatStartDate;
143-
bool _advancedOpTime = false;
144130
};
145131

146132
} // namespace repl

src/mongo/db/repl/member_heartbeat_data.cpp

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@
3939
namespace mongo {
4040
namespace repl {
4141

42-
MemberHeartbeatData::MemberHeartbeatData()
43-
: _health(-1), _authIssue(false), _configIndex(-1), _isSelf(false) {
42+
MemberHeartbeatData::MemberHeartbeatData() : _health(-1), _authIssue(false) {
4443
_lastResponse.setState(MemberState::RS_UNKNOWN);
4544
_lastResponse.setElectionTime(Timestamp());
4645
_lastResponse.setAppliedOpTime(OpTime());
4746
}
4847

49-
bool MemberHeartbeatData::setUpValues(Date_t now,
48+
void MemberHeartbeatData::setUpValues(Date_t now,
5049
const HostAndPort& host,
5150
ReplSetHeartbeatResponse&& hbResponse) {
5251
_health = 1;
@@ -55,8 +54,6 @@ bool MemberHeartbeatData::setUpValues(Date_t now,
5554
}
5655
_authIssue = false;
5756
_lastHeartbeat = now;
58-
_lastUpdate = now;
59-
_lastUpdateStale = false;
6057
_updatedSinceRestart = true;
6158

6259
if (!hbResponse.hasState()) {
@@ -74,11 +71,7 @@ bool MemberHeartbeatData::setUpValues(Date_t now,
7471
<< hbResponse.getState().toString() << rsLog;
7572
}
7673

77-
bool opTimeAdvanced = advanceLastAppliedOpTime(hbResponse.getAppliedOpTime(), now);
78-
auto durableOpTime = hbResponse.hasDurableOpTime() ? hbResponse.getDurableOpTime() : OpTime();
79-
opTimeAdvanced = advanceLastDurableOpTime(durableOpTime, now) || opTimeAdvanced;
8074
_lastResponse = std::move(hbResponse);
81-
return opTimeAdvanced;
8275
}
8376

8477
void MemberHeartbeatData::setDownValues(Date_t now, const std::string& heartbeatMessage) {
@@ -94,9 +87,6 @@ void MemberHeartbeatData::setDownValues(Date_t now, const std::string& heartbeat
9487
_lastResponse.setAppliedOpTime(OpTime());
9588
_lastResponse.setHbMsg(heartbeatMessage);
9689
_lastResponse.setSyncingTo(HostAndPort());
97-
98-
// The _lastAppliedOpTime/_lastDurableOpTime fields don't get cleared merely by missing a
99-
// heartbeat.
10090
}
10191

10292
void MemberHeartbeatData::setAuthIssue(Date_t now) {
@@ -114,47 +104,5 @@ void MemberHeartbeatData::setAuthIssue(Date_t now) {
114104
_lastResponse.setSyncingTo(HostAndPort());
115105
}
116106

117-
void MemberHeartbeatData::setLastAppliedOpTime(OpTime opTime, Date_t now) {
118-
_lastUpdate = now;
119-
_lastUpdateStale = false;
120-
_lastAppliedOpTime = opTime;
121-
}
122-
123-
void MemberHeartbeatData::setLastDurableOpTime(OpTime opTime, Date_t now) {
124-
_lastUpdate = now;
125-
_lastUpdateStale = false;
126-
if (_lastAppliedOpTime < opTime) {
127-
// TODO(russotto): We think this should never happen, rollback or no rollback. Make this an
128-
// invariant and see what happens.
129-
log() << "Durable progress (" << opTime << ") is ahead of the applied progress ("
130-
<< _lastAppliedOpTime << ". This is likely due to a "
131-
"rollback."
132-
<< " memberid: " << _memberId << " rid: " << _rid << " host "
133-
<< _hostAndPort.toString() << " previous durable progress: " << _lastDurableOpTime;
134-
} else {
135-
_lastDurableOpTime = opTime;
136-
}
137-
}
138-
139-
bool MemberHeartbeatData::advanceLastAppliedOpTime(OpTime opTime, Date_t now) {
140-
_lastUpdate = now;
141-
_lastUpdateStale = false;
142-
if (_lastAppliedOpTime < opTime) {
143-
setLastAppliedOpTime(opTime, now);
144-
return true;
145-
}
146-
return false;
147-
}
148-
149-
bool MemberHeartbeatData::advanceLastDurableOpTime(OpTime opTime, Date_t now) {
150-
_lastUpdate = now;
151-
_lastUpdateStale = false;
152-
if (_lastDurableOpTime < opTime) {
153-
setLastDurableOpTime(opTime, now);
154-
return true;
155-
}
156-
return false;
157-
}
158-
159107
} // namespace repl
160108
} // namespace mongo

src/mongo/db/repl/member_heartbeat_data.h

Lines changed: 3 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ class MemberHeartbeatData {
6868
const HostAndPort& getSyncSource() const {
6969
return _lastResponse.getSyncingTo();
7070
}
71-
OpTime getHeartbeatAppliedOpTime() const {
71+
OpTime getAppliedOpTime() const {
7272
return _lastResponse.getAppliedOpTime();
7373
}
74-
OpTime getHeartbeatDurableOpTime() const {
74+
OpTime getDurableOpTime() const {
7575
return _lastResponse.hasDurableOpTime() ? _lastResponse.getDurableOpTime() : OpTime();
7676
}
7777
int getConfigVersion() const {
@@ -105,49 +105,10 @@ class MemberHeartbeatData {
105105
return _health != 0;
106106
}
107107

108-
OpTime getLastAppliedOpTime() const {
109-
return _lastAppliedOpTime;
110-
}
111-
112-
OpTime getLastDurableOpTime() const {
113-
return _lastDurableOpTime;
114-
}
115-
116-
// When was the last time this data was updated via any means?
117-
Date_t getLastUpdate() const {
118-
return _lastUpdate;
119-
}
120-
// Was the last update stale as of the last check?
121-
bool lastUpdateStale() const {
122-
return _lastUpdateStale;
123-
}
124-
125-
// Index of this member in the replica set config member list.
126-
int getConfigIndex() const {
127-
return _configIndex;
128-
}
129-
130-
int getMemberId() const {
131-
return _memberId;
132-
}
133-
134-
OID getRid() const {
135-
return _rid;
136-
}
137-
138-
bool isSelf() const {
139-
return _isSelf;
140-
}
141-
142-
HostAndPort getHostAndPort() const {
143-
return _hostAndPort;
144-
}
145-
146108
/**
147109
* Sets values in this object from the results of a successful heartbeat command.
148-
* Returns whether or not the optimes advanced as a result of this heartbeat response.
149110
*/
150-
bool setUpValues(Date_t now, const HostAndPort& host, ReplSetHeartbeatResponse&& hbResponse);
111+
void setUpValues(Date_t now, const HostAndPort& host, ReplSetHeartbeatResponse&& hbResponse);
151112

152113
/**
153114
* Sets values in this object from the results of a erroring/failed heartbeat command.
@@ -173,66 +134,6 @@ class MemberHeartbeatData {
173134
return _updatedSinceRestart;
174135
}
175136

176-
/**
177-
* Sets the last applied op time (not the heartbeat applied op time) and updates the
178-
* lastUpdate time.
179-
*/
180-
void setLastAppliedOpTime(OpTime opTime, Date_t now);
181-
182-
/**
183-
* Sets the last durable op time (not the heartbeat durable op time)
184-
*/
185-
void setLastDurableOpTime(OpTime opTime, Date_t now);
186-
187-
/**
188-
* Sets the last applied op time (not the heartbeat applied op time) iff the new optime is
189-
* later than the current optime, and updates the lastUpdate time. Returns true if the
190-
* optime was advanced.
191-
*/
192-
bool advanceLastAppliedOpTime(OpTime opTime, Date_t now);
193-
194-
/**
195-
* Sets the last durable op time (not the heartbeat applied op time) iff the new optime is
196-
* later than the current optime, and updates the lastUpdate time. Returns true if the
197-
* optime was advanced.
198-
*/
199-
bool advanceLastDurableOpTime(OpTime opTime, Date_t now);
200-
201-
/*
202-
* Indicates that this data is stale, based on _lastUpdateTime.
203-
*/
204-
void markLastUpdateStale() {
205-
_lastUpdateStale = true;
206-
}
207-
208-
/*
209-
* Updates the _lastUpdateTime and clears staleness without changing anything else.
210-
*/
211-
void updateLiveness(Date_t now) {
212-
_lastUpdate = now;
213-
_lastUpdateStale = false;
214-
}
215-
216-
void setConfigIndex(int configIndex) {
217-
_configIndex = configIndex;
218-
}
219-
220-
void setIsSelf(bool isSelf) {
221-
_isSelf = isSelf;
222-
}
223-
224-
void setHostAndPort(HostAndPort hostAndPort) {
225-
_hostAndPort = hostAndPort;
226-
}
227-
228-
void setMemberId(int memberId) {
229-
_memberId = memberId;
230-
}
231-
232-
void setRid(OID rid) {
233-
_rid = rid;
234-
}
235-
236137
private:
237138
// -1 = not checked yet, 0 = member is down/unreachable, 1 = member is up
238139
int _health;
@@ -252,38 +153,6 @@ class MemberHeartbeatData {
252153

253154
// Have we received heartbeats since the last restart?
254155
bool _updatedSinceRestart = false;
255-
256-
// Last time we got any information about this member, whether heartbeat
257-
// or replSetUpdatePosition.
258-
Date_t _lastUpdate;
259-
260-
// Set when lastUpdate time exceeds the election timeout. Implies that the member is down
261-
// on the primary, but not the secondaries.
262-
bool _lastUpdateStale = false;
263-
264-
// Last known OpTime that the replica has applied and journaled to.
265-
OpTime _lastDurableOpTime;
266-
267-
// Last known OpTime that the replica has applied, whether journaled or unjournaled.
268-
OpTime _lastAppliedOpTime;
269-
270-
// TODO(russotto): Since memberHeartbeatData is kept in config order, _configIndex
271-
// and _isSelf may not be necessary.
272-
// Index of this member in the replica set configuration.
273-
int _configIndex;
274-
275-
// Is this the data for this member?
276-
bool _isSelf;
277-
278-
// This member's RID, used only in master/slave replication.
279-
OID _rid;
280-
281-
// This member's member ID. memberId and hostAndPort duplicate information in the
282-
// configuration for replica sets, but are required to be here for master/slave replication.
283-
int _memberId = -1;
284-
285-
// Client address of this member.
286-
HostAndPort _hostAndPort;
287156
};
288157

289158
} // namespace repl

src/mongo/db/repl/repl_set_html_summary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ const std::string ReplSetHtmlSummary::toHtmlString() const {
187187
// TODO(dannenberg): change timestamp to optime in V1
188188
memberTable << td(memberHB.getLastHeartbeat() == Date_t()
189189
? "?"
190-
: memberHB.getHeartbeatAppliedOpTime().toString());
190+
: memberHB.getAppliedOpTime().toString());
191191
}
192192
memberTable << _tr();
193193
}
@@ -201,7 +201,7 @@ const std::string ReplSetHtmlSummary::toHtmlString() const {
201201
const MemberConfig& selfConfig = _config.getMemberAt(_selfIndex);
202202

203203
if (_primaryIndex >= 0 && _primaryIndex != _selfIndex && !selfConfig.isArbiter()) {
204-
int lag = _hbData[_primaryIndex].getHeartbeatAppliedOpTime().getTimestamp().getSecs() -
204+
int lag = _hbData[_primaryIndex].getAppliedOpTime().getTimestamp().getSecs() -
205205
_selfOptime.getTimestamp().getSecs();
206206
s << tr("Lag: ", str::stream() << lag << " secs");
207207
}

0 commit comments

Comments
 (0)