summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2016-05-31 10:00:53 -0400
committerEric Milkie <milkie@10gen.com>2016-05-31 10:05:20 -0400
commited3f25ced04931525db8e2f11f8bdef7bf49992a (patch)
treea21b68dd9fdee4d74c36e15dd9d588913d9b0d3c /src/mongo/db
parentb66741f2da0fe59e7cfa12638753cb9ea8718bef (diff)
downloadmongo-ed3f25ced04931525db8e2f11f8bdef7bf49992a.tar.gz
Revert "SERVER-24222 Update current known primary from command metadata"
This reverts commit 3dd8ba46bf2ce350b5e80b1b2b016a10007beb7b.
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/repl/bgsync.cpp11
-rw-r--r--src/mongo/db/repl/data_replicator_external_state.h3
-rw-r--r--src/mongo/db/repl/data_replicator_external_state_impl.cpp10
-rw-r--r--src/mongo/db/repl/data_replicator_external_state_impl.h3
-rw-r--r--src/mongo/db/repl/data_replicator_external_state_mock.cpp7
-rw-r--r--src/mongo/db/repl/data_replicator_external_state_mock.h3
-rw-r--r--src/mongo/db/repl/data_replicator_test.cpp15
-rw-r--r--src/mongo/db/repl/oplog_fetcher.cpp52
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp10
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.h3
-rw-r--r--src/mongo/db/repl/replication_coordinator_mock.cpp3
-rw-r--r--src/mongo/db/repl/replication_coordinator_mock.h3
-rw-r--r--src/mongo/db/repl/sync_source_selector.h7
-rw-r--r--src/mongo/db/repl/topology_coordinator.h3
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl.cpp20
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl.h3
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl_test.cpp46
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp65
-rw-r--r--src/mongo/db/repl/update_position_args.h2
19 files changed, 134 insertions, 135 deletions
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp
index fb6e689a019..3701e77cdda 100644
--- a/src/mongo/db/repl/bgsync.cpp
+++ b/src/mongo/db/repl/bgsync.cpp
@@ -85,7 +85,8 @@ public:
ReplicationCoordinatorExternalState* replicationCoordinatorExternalState,
BackgroundSync* bgsync);
bool shouldStopFetching(const HostAndPort& source,
- const rpc::ReplSetMetadata& metadata) override;
+ const OpTime& sourceOpTime,
+ bool sourceHasSyncSource) override;
private:
BackgroundSync* _bgsync;
@@ -98,13 +99,15 @@ DataReplicatorExternalStateBackgroundSync::DataReplicatorExternalStateBackground
: DataReplicatorExternalStateImpl(replicationCoordinator, replicationCoordinatorExternalState),
_bgsync(bgsync) {}
-bool DataReplicatorExternalStateBackgroundSync::shouldStopFetching(
- const HostAndPort& source, const rpc::ReplSetMetadata& metadata) {
+bool DataReplicatorExternalStateBackgroundSync::shouldStopFetching(const HostAndPort& source,
+ const OpTime& sourceOpTime,
+ bool sourceHasSyncSource) {
if (_bgsync->shouldStopFetching()) {
return true;
}
- return DataReplicatorExternalStateImpl::shouldStopFetching(source, metadata);
+ return DataReplicatorExternalStateImpl::shouldStopFetching(
+ source, sourceOpTime, sourceHasSyncSource);
}
/**
diff --git a/src/mongo/db/repl/data_replicator_external_state.h b/src/mongo/db/repl/data_replicator_external_state.h
index 848af9c720e..d19f46f9711 100644
--- a/src/mongo/db/repl/data_replicator_external_state.h
+++ b/src/mongo/db/repl/data_replicator_external_state.h
@@ -77,7 +77,8 @@ public:
* metadata).
*/
virtual bool shouldStopFetching(const HostAndPort& source,
- const rpc::ReplSetMetadata& metadata) = 0;
+ const OpTime& sourceOpTime,
+ bool sourceHasSyncSource) = 0;
private:
/**
diff --git a/src/mongo/db/repl/data_replicator_external_state_impl.cpp b/src/mongo/db/repl/data_replicator_external_state_impl.cpp
index 87b5993b231..558f3faf700 100644
--- a/src/mongo/db/repl/data_replicator_external_state_impl.cpp
+++ b/src/mongo/db/repl/data_replicator_external_state_impl.cpp
@@ -60,12 +60,14 @@ void DataReplicatorExternalStateImpl::processMetadata(const rpc::ReplSetMetadata
}
bool DataReplicatorExternalStateImpl::shouldStopFetching(const HostAndPort& source,
- const rpc::ReplSetMetadata& metadata) {
+ const OpTime& sourceOpTime,
+ bool sourceHasSyncSource) {
// Re-evaluate quality of sync target.
- if (_replicationCoordinator->shouldChangeSyncSource(source, metadata)) {
+ if (_replicationCoordinator->shouldChangeSyncSource(
+ source, sourceOpTime, sourceHasSyncSource)) {
LOG(1) << "Canceling oplog query because we have to choose a sync source. Current source: "
- << source << ", OpTime " << metadata.getLastOpVisible()
- << ", its sync source index:" << metadata.getSyncSourceIndex();
+ << source << ", OpTime " << sourceOpTime
+ << ", hasSyncSource:" << sourceHasSyncSource;
return true;
}
return false;
diff --git a/src/mongo/db/repl/data_replicator_external_state_impl.h b/src/mongo/db/repl/data_replicator_external_state_impl.h
index e94dccdab32..25a09e1d7db 100644
--- a/src/mongo/db/repl/data_replicator_external_state_impl.h
+++ b/src/mongo/db/repl/data_replicator_external_state_impl.h
@@ -51,7 +51,8 @@ public:
void processMetadata(const rpc::ReplSetMetadata& metadata) override;
bool shouldStopFetching(const HostAndPort& source,
- const rpc::ReplSetMetadata& metadata) override;
+ const OpTime& sourceOpTime,
+ bool sourceHasSyncSource) override;
private:
StatusWith<OpTime> _multiApply(OperationContext* txn,
diff --git a/src/mongo/db/repl/data_replicator_external_state_mock.cpp b/src/mongo/db/repl/data_replicator_external_state_mock.cpp
index 2ec80fad216..83a6e3fd83c 100644
--- a/src/mongo/db/repl/data_replicator_external_state_mock.cpp
+++ b/src/mongo/db/repl/data_replicator_external_state_mock.cpp
@@ -47,10 +47,11 @@ void DataReplicatorExternalStateMock::processMetadata(const rpc::ReplSetMetadata
}
bool DataReplicatorExternalStateMock::shouldStopFetching(const HostAndPort& source,
- const rpc::ReplSetMetadata& metadata) {
+ const OpTime& sourceOpTime,
+ bool sourceHasSyncSource) {
lastSyncSourceChecked = source;
- syncSourceLastOpTime = metadata.getLastOpVisible();
- syncSourceHasSyncSource = metadata.getSyncSourceIndex() != -1;
+ syncSourceLastOpTime = sourceOpTime;
+ syncSourceHasSyncSource = sourceHasSyncSource;
return shouldStopFetchingResult;
}
diff --git a/src/mongo/db/repl/data_replicator_external_state_mock.h b/src/mongo/db/repl/data_replicator_external_state_mock.h
index 6335552f4b8..4705fb57bd3 100644
--- a/src/mongo/db/repl/data_replicator_external_state_mock.h
+++ b/src/mongo/db/repl/data_replicator_external_state_mock.h
@@ -48,7 +48,8 @@ public:
void processMetadata(const rpc::ReplSetMetadata& metadata) override;
bool shouldStopFetching(const HostAndPort& source,
- const rpc::ReplSetMetadata& metadata) override;
+ const OpTime& sourceOpTime,
+ bool sourceHasSyncSource) override;
// Returned by getCurrentTermAndLastCommittedOpTime.
long long currentTerm = OpTime::kUninitializedTerm;
diff --git a/src/mongo/db/repl/data_replicator_test.cpp b/src/mongo/db/repl/data_replicator_test.cpp
index 43e42f7cc5e..294beba46ed 100644
--- a/src/mongo/db/repl/data_replicator_test.cpp
+++ b/src/mongo/db/repl/data_replicator_test.cpp
@@ -83,7 +83,8 @@ public:
_blacklistedSource = host;
}
bool shouldChangeSyncSource(const HostAndPort& currentSource,
- const rpc::ReplSetMetadata& metadata) override {
+ const OpTime& sourcesOpTime,
+ bool syncSourceHasSyncSource) override {
return false;
}
SyncSourceResolverResponse selectSyncSource(OperationContext* txn,
@@ -125,8 +126,10 @@ public:
_syncSourceSelector->blacklistSyncSource(host, until);
}
bool shouldChangeSyncSource(const HostAndPort& currentSource,
- const rpc::ReplSetMetadata& metadata) override {
- return _syncSourceSelector->shouldChangeSyncSource(currentSource, metadata);
+ const OpTime& sourcesOpTime,
+ bool syncSourceHasSyncSource) override {
+ return _syncSourceSelector->shouldChangeSyncSource(
+ currentSource, sourcesOpTime, syncSourceHasSyncSource);
}
SyncSourceResolverResponse selectSyncSource(OperationContext* txn,
const OpTime& lastOpTimeFetched) override {
@@ -715,7 +718,8 @@ public:
_blacklistedSource = host;
}
bool shouldChangeSyncSource(const HostAndPort& currentSource,
- const rpc::ReplSetMetadata& metadata) override {
+ const OpTime& sourcesOpTime,
+ bool syncSourceHasSyncSource) override {
return false;
}
SyncSourceResolverResponse selectSyncSource(OperationContext* txn,
@@ -846,7 +850,8 @@ public:
}
void blacklistSyncSource(const HostAndPort& host, Date_t until) override {}
bool shouldChangeSyncSource(const HostAndPort& currentSource,
- const rpc::ReplSetMetadata& metadata) override {
+ const OpTime& sourcesOpTime,
+ bool syncSourceHasSyncSource) override {
return false;
}
SyncSourceResolverResponse selectSyncSource(OperationContext* txn,
diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp
index f43e53817f7..fcdc7819c72 100644
--- a/src/mongo/db/repl/oplog_fetcher.cpp
+++ b/src/mongo/db/repl/oplog_fetcher.cpp
@@ -50,8 +50,10 @@ namespace {
* Calculates await data timeout based on the current replica set configuration.
*/
Milliseconds calculateAwaitDataTimeout(const ReplicaSetConfig& config) {
- // Under protocol version 1, make the awaitData timeout (maxTimeMS) dependent on the election
- // timeout. This enables the sync source to communicate liveness of the primary to secondaries.
+ // Under protocol version 1, make the awaitData timeout (maxTimeMS) dependent
+ // on the election
+ // timeout. This enables the sync source to communicate liveness of the
+ // primary to secondaries.
// Under protocol version 0, use a default timeout of 2 seconds for awaitData.
if (config.getProtocolVersion() == 1LL) {
return config.getElectionTimeoutPeriod() / 2;
@@ -109,15 +111,19 @@ StatusWith<BSONObj> makeMetadataObject(bool isV1ElectionProtocol) {
/**
* Checks the first batch of results from query.
- * 'documents' are the first batch of results returned from tailing the remote oplog.
- * 'lastFetched' optime and hash should be consistent with the predicate in the query.
+ * 'documents' are the first batch of results returned from tailing the remote
+ * oplog.
+ * 'lastFetched' optime and hash should be consistent with the predicate in the
+ * query.
* Returns RemoteOplogStale if the oplog query has no results.
- * Returns OplogStartMissing if we cannot find the optime of the last fetched operation in
+ * Returns OplogStartMissing if we cannot find the optime of the last fetched
+ * operation in
* the remote oplog.
*/
Status checkRemoteOplogStart(const Fetcher::Documents& documents, OpTimeWithHash lastFetched) {
if (documents.empty()) {
- // The GTE query from upstream returns nothing, so we're ahead of the upstream.
+ // The GTE query from upstream returns nothing, so we're ahead of the
+ // upstream.
return Status(ErrorCodes::RemoteOplogStale,
str::stream() << "We are ahead of the sync source. Our last op time fetched: "
<< lastFetched.opTime.toString());
@@ -170,7 +176,8 @@ StatusWith<OplogFetcher::DocumentsInfo> OplogFetcher::validateDocuments(
info.networkDocumentBytes += doc.objsize();
++info.networkDocumentCount;
- // If this is the first response (to the $gte query) then we already applied the first doc.
+ // If this is the first response (to the $gte query) then we already applied
+ // the first doc.
if (first && info.networkDocumentCount == 1U) {
continue;
}
@@ -201,7 +208,8 @@ StatusWith<OplogFetcher::DocumentsInfo> OplogFetcher::validateDocuments(
info.toApplyDocumentCount = documents.size();
info.toApplyDocumentBytes = info.networkDocumentBytes;
if (first) {
- // The count is one less since the first document found was already applied ($gte $ts query)
+ // The count is one less since the first document found was already applied
+ // ($gte $ts query)
// and we will not apply it again.
--info.toApplyDocumentCount;
auto alreadyAppliedDocument = documents.cbegin();
@@ -294,9 +302,11 @@ void OplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
}
const auto& queryResponse = result.getValue();
- rpc::ReplSetMetadata metadata;
+ OpTime sourcesLastOpTime;
+ bool syncSourceHasSyncSource = false;
- // Forward metadata (containing liveness information) to data replicator external state.
+ // Forward metadata (containing liveness information) to data replicator
+ // external state.
bool receivedMetadata =
queryResponse.otherFields.metadata.hasElement(rpc::kReplSetMetadataFieldName);
if (receivedMetadata) {
@@ -308,8 +318,10 @@ void OplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
_onShutdown(metadataResult.getStatus());
return;
}
- metadata = metadataResult.getValue();
+ auto metadata = metadataResult.getValue();
_dataReplicatorExternalState->processMetadata(metadata);
+ sourcesLastOpTime = metadata.getLastOpVisible();
+ syncSourceHasSyncSource = metadata.getSyncSourceIndex() != -1;
}
const auto& documents = queryResponse.documents;
@@ -325,7 +337,8 @@ void OplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
auto opTimeWithHash = getLastOpTimeWithHashFetched();
- // Check start of remote oplog and, if necessary, stop fetcher to execute rollback.
+ // Check start of remote oplog and, if necessary, stop fetcher to execute
+ // rollback.
if (queryResponse.first) {
auto status = checkRemoteOplogStart(documents, opTimeWithHash);
if (!status.isOK()) {
@@ -334,7 +347,8 @@ void OplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
return;
}
- // If this is the first batch and no rollback is needed, skip the first document.
+ // If this is the first batch and no rollback is needed, skip the first
+ // document.
firstDocToApply++;
}
@@ -359,15 +373,14 @@ void OplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
_lastFetched = opTimeWithHash;
}
- if (_dataReplicatorExternalState->shouldStopFetching(_fetcher.getSource(), metadata)) {
+ if (_dataReplicatorExternalState->shouldStopFetching(
+ _fetcher.getSource(), sourcesLastOpTime, syncSourceHasSyncSource)) {
_onShutdown(Status(ErrorCodes::InvalidSyncSource,
str::stream() << "sync source " << _fetcher.getSource().toString()
<< " (last optime: "
- << metadata.getLastOpVisible().toString()
- << "; sync source index: "
- << metadata.getSyncSourceIndex()
- << "; primary index: "
- << metadata.getPrimaryIndex()
+ << sourcesLastOpTime.toString()
+ << "; has sync source: "
+ << syncSourceHasSyncSource
<< ") is no longer valid"),
opTimeWithHash);
return;
@@ -394,6 +407,5 @@ void OplogFetcher::_onShutdown(Status status, OpTimeWithHash opTimeWithHash) {
_onShutdownCallbackFn(status, opTimeWithHash);
}
-
} // namespace repl
} // namespace mongo
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index 8b89de49f60..2ef097d1f76 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -2898,10 +2898,14 @@ void ReplicationCoordinatorImpl::resetLastOpTimesFromOplog(OperationContext* txn
}
bool ReplicationCoordinatorImpl::shouldChangeSyncSource(const HostAndPort& currentSource,
- const rpc::ReplSetMetadata& metadata) {
+ const OpTime& syncSourceLastOpTime,
+ bool syncSourceHasSyncSource) {
LockGuard topoLock(_topoMutex);
- return _topCoord->shouldChangeSyncSource(
- currentSource, getMyLastAppliedOpTime(), metadata, _replExecutor.now());
+ return _topCoord->shouldChangeSyncSource(currentSource,
+ getMyLastAppliedOpTime(),
+ syncSourceLastOpTime,
+ syncSourceHasSyncSource,
+ _replExecutor.now());
}
SyncSourceResolverResponse ReplicationCoordinatorImpl::selectSyncSource(
diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h
index 61fda88b59a..8e525c934e3 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.h
+++ b/src/mongo/db/repl/replication_coordinator_impl.h
@@ -275,7 +275,8 @@ public:
virtual void resetLastOpTimesFromOplog(OperationContext* txn) override;
virtual bool shouldChangeSyncSource(const HostAndPort& currentSource,
- const rpc::ReplSetMetadata& metadata) override;
+ const OpTime& syncSourceLastOpTime,
+ bool syncSourceHasSyncSource) override;
virtual SyncSourceResolverResponse selectSyncSource(OperationContext* txn,
const OpTime& lastOpTimeFetched) override;
diff --git a/src/mongo/db/repl/replication_coordinator_mock.cpp b/src/mongo/db/repl/replication_coordinator_mock.cpp
index e8617423953..48fe98a6299 100644
--- a/src/mongo/db/repl/replication_coordinator_mock.cpp
+++ b/src/mongo/db/repl/replication_coordinator_mock.cpp
@@ -357,7 +357,8 @@ void ReplicationCoordinatorMock::resetLastOpTimesFromOplog(OperationContext* txn
}
bool ReplicationCoordinatorMock::shouldChangeSyncSource(const HostAndPort& currentSource,
- const rpc::ReplSetMetadata& metadata) {
+ const OpTime& syncSourceLastOpTime,
+ bool syncSourceHasSyncSource) {
invariant(false);
}
diff --git a/src/mongo/db/repl/replication_coordinator_mock.h b/src/mongo/db/repl/replication_coordinator_mock.h
index 2b56a93c219..5fdf319306d 100644
--- a/src/mongo/db/repl/replication_coordinator_mock.h
+++ b/src/mongo/db/repl/replication_coordinator_mock.h
@@ -208,7 +208,8 @@ public:
virtual void resetLastOpTimesFromOplog(OperationContext* txn);
virtual bool shouldChangeSyncSource(const HostAndPort& currentSource,
- const rpc::ReplSetMetadata& metadata);
+ const OpTime& syncSourceLastOpTime,
+ bool syncSourceHasSyncSource);
virtual OpTime getLastCommittedOpTime() const;
diff --git a/src/mongo/db/repl/sync_source_selector.h b/src/mongo/db/repl/sync_source_selector.h
index c3621c3e95d..812944420a9 100644
--- a/src/mongo/db/repl/sync_source_selector.h
+++ b/src/mongo/db/repl/sync_source_selector.h
@@ -68,16 +68,17 @@ public:
/**
* Determines if a new sync source should be chosen, if a better candidate sync source is
- * available. If the current sync source's last optime (visibleOpTime of metadata under
+ * available. If the current sync source's last optime ("syncSourceLastOpTime" under
* protocolVersion 1, but pulled from the MemberHeartbeatData in protocolVersion 0) is more than
* _maxSyncSourceLagSecs behind any syncable source, this function returns true. If we are
* running in ProtocolVersion 1, our current sync source is not primary, has no sync source
- * and only has data up to "myLastOpTime", returns true.
+ * ("syncSourceHasSyncSource" is false), and only has data up to "myLastOpTime", returns true.
*
* "now" is used to skip over currently blacklisted sync sources.
*/
virtual bool shouldChangeSyncSource(const HostAndPort& currentSource,
- const rpc::ReplSetMetadata& metadata) = 0;
+ const OpTime& syncSourceLastOpTime,
+ bool syncSourceHasSyncSource) = 0;
/**
* Returns a SyncSourceResolverResponse containing the syncSource or a new MinValid boundry as
diff --git a/src/mongo/db/repl/topology_coordinator.h b/src/mongo/db/repl/topology_coordinator.h
index 1548cb774a9..43bcc71f909 100644
--- a/src/mongo/db/repl/topology_coordinator.h
+++ b/src/mongo/db/repl/topology_coordinator.h
@@ -165,7 +165,8 @@ public:
*/
virtual bool shouldChangeSyncSource(const HostAndPort& currentSource,
const OpTime& myLastOpTime,
- const rpc::ReplSetMetadata& metadata,
+ const OpTime& syncSourceLastOpTime,
+ bool syncSourceHasSyncSource,
Date_t now) const = 0;
/**
diff --git a/src/mongo/db/repl/topology_coordinator_impl.cpp b/src/mongo/db/repl/topology_coordinator_impl.cpp
index b72fe47f524..a4d7c3c4934 100644
--- a/src/mongo/db/repl/topology_coordinator_impl.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl.cpp
@@ -2300,11 +2300,10 @@ long long TopologyCoordinatorImpl::getTerm() {
return _term;
}
-// TODO(siyuan): Merge _hddata into _slaveInfo, so that we have a single view of the
-// replset. Passing metadata is unnecessary.
bool TopologyCoordinatorImpl::shouldChangeSyncSource(const HostAndPort& currentSource,
const OpTime& myLastOpTime,
- const rpc::ReplSetMetadata& metadata,
+ const OpTime& syncSourceLastOpTime,
+ bool syncSourceHasSyncSource,
Date_t now) const {
// Methodology:
// If there exists a viable sync source member other than currentSource, whose oplog has
@@ -2318,16 +2317,14 @@ bool TopologyCoordinatorImpl::shouldChangeSyncSource(const HostAndPort& currentS
return true;
}
- if (metadata.getConfigVersion() != _rsConfig.getConfigVersion()) {
+ const int currentSourceIndex = _rsConfig.findMemberIndexByHostAndPort(currentSource);
+ if (currentSourceIndex == -1) {
return true;
}
-
- const int currentSourceIndex = _rsConfig.findMemberIndexByHostAndPort(currentSource);
- invariant(currentSourceIndex != -1);
invariant(currentSourceIndex != _selfIndex);
OpTime currentSourceOpTime =
- std::max(metadata.getLastOpVisible(), _hbdata.at(currentSourceIndex).getAppliedOpTime());
+ std::max(syncSourceLastOpTime, _hbdata.at(currentSourceIndex).getAppliedOpTime());
if (currentSourceOpTime.isNull()) {
// Haven't received a heartbeat from the sync source yet, so can't tell if we should
@@ -2335,10 +2332,9 @@ bool TopologyCoordinatorImpl::shouldChangeSyncSource(const HostAndPort& currentS
return false;
}
- // Change sync source if they are not ahead of us, and don't have a sync source,
- // unless they are primary.
- if (_rsConfig.getProtocolVersion() == 1 && metadata.getSyncSourceIndex() == -1 &&
- currentSourceOpTime <= myLastOpTime && metadata.getPrimaryIndex() != currentSourceIndex) {
+ if (_rsConfig.getProtocolVersion() == 1 && !syncSourceHasSyncSource &&
+ currentSourceOpTime <= myLastOpTime &&
+ _hbdata.at(currentSourceIndex).getState() != MemberState::RS_PRIMARY) {
return true;
}
diff --git a/src/mongo/db/repl/topology_coordinator_impl.h b/src/mongo/db/repl/topology_coordinator_impl.h
index 0cd56272565..74d7368d552 100644
--- a/src/mongo/db/repl/topology_coordinator_impl.h
+++ b/src/mongo/db/repl/topology_coordinator_impl.h
@@ -156,7 +156,8 @@ public:
virtual void clearSyncSourceBlacklist();
virtual bool shouldChangeSyncSource(const HostAndPort& currentSource,
const OpTime& myLastOpTime,
- const rpc::ReplSetMetadata& metadata,
+ const OpTime& syncSourceLastOpTime,
+ bool syncSourceHasSyncSource,
Date_t now) const;
virtual bool becomeCandidateIfStepdownPeriodOverAndSingleNodeSet(Date_t now);
virtual void setElectionSleepUntil(Date_t newTime);
diff --git a/src/mongo/db/repl/topology_coordinator_impl_test.cpp b/src/mongo/db/repl/topology_coordinator_impl_test.cpp
index 030142c628b..0ec6363a09d 100644
--- a/src/mongo/db/repl/topology_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl_test.cpp
@@ -51,7 +51,6 @@
ASSERT_EQUALS(mongo::repl::HeartbeatResponseAction::NoAction, (EXPRESSION))
using std::unique_ptr;
-using mongo::rpc::ReplSetMetadata;
namespace mongo {
namespace repl {
@@ -147,12 +146,6 @@ protected:
_currentConfig = config;
}
- // Make the metadata coming from sync source. Only set visibleOpTime.
- ReplSetMetadata makeMetadata(OpTime opTime = OpTime()) {
- return ReplSetMetadata(
- _topo->getTerm(), OpTime(), opTime, _currentConfig.getConfigVersion(), OID(), -1, -1);
- }
-
HeartbeatResponseAction receiveUpHeartbeat(const HostAndPort& member,
const std::string& setName,
MemberState memberState,
@@ -663,9 +656,9 @@ TEST_F(TopoCoordTest, ChooseRequestedSyncSourceOnlyTheFirstTimeAfterTheSyncSourc
// force should cause shouldChangeSyncSource() to return true
// even if the currentSource is the force target
ASSERT_TRUE(
- getTopoCoord().shouldChangeSyncSource(HostAndPort("h2"), OpTime(), makeMetadata(), now()));
+ getTopoCoord().shouldChangeSyncSource(HostAndPort("h2"), OpTime(), OpTime(), false, now()));
ASSERT_TRUE(
- getTopoCoord().shouldChangeSyncSource(HostAndPort("h3"), OpTime(), makeMetadata(), now()));
+ getTopoCoord().shouldChangeSyncSource(HostAndPort("h3"), OpTime(), OpTime(), false, now()));
getTopoCoord().chooseNewSyncSource(now()++, Timestamp());
ASSERT_EQUALS(HostAndPort("h2"), getTopoCoord().getSyncSourceAddress());
@@ -5224,10 +5217,9 @@ TEST_F(HeartbeatResponseTest, ReconfigNodeRemovedBetweenHeartbeatRequestAndRepso
TEST_F(HeartbeatResponseTest, ShouldChangeSyncSourceWhenMemberNotInConfig) {
// In this test, the TopologyCoordinator should tell us to change sync sources away from
- // "host4" since "host4" is absent from the config of version 10.
- ReplSetMetadata metadata(0, OpTime(), OpTime(), 10, OID(), -1, -1);
- ASSERT_TRUE(
- getTopoCoord().shouldChangeSyncSource(HostAndPort("host4"), OpTime(), metadata, now()));
+ // "host4" since "host4" is absent from the config
+ ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
+ HostAndPort("host4"), OpTime(), OpTime(), false, now()));
}
TEST_F(HeartbeatResponseTest, ShouldChangeSyncSourceWhenMemberHasYetToHeartbeatUs) {
@@ -5235,7 +5227,7 @@ TEST_F(HeartbeatResponseTest, ShouldChangeSyncSourceWhenMemberHasYetToHeartbeatU
// "host2" since we do not yet have a heartbeat (and as a result do not yet have an optime)
// for "host2"
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(), now()));
+ HostAndPort("host2"), OpTime(), OpTime(), false, now()));
}
TEST_F(HeartbeatResponseTest, ShouldNotChangeSyncSourceWhenNodeIsFreshByHeartbeatButNotMetadata) {
@@ -5265,9 +5257,8 @@ TEST_F(HeartbeatResponseTest, ShouldNotChangeSyncSourceWhenNodeIsFreshByHeartbea
// set up complete, time for actual check
startCapturingLogMessages();
- auto metadata = makeMetadata(lastOpTimeApplied);
- ASSERT_FALSE(
- getTopoCoord().shouldChangeSyncSource(HostAndPort("host2"), OpTime(), metadata, now()));
+ ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(0, countLogLinesContaining("re-evaluating sync source"));
}
@@ -5299,9 +5290,8 @@ TEST_F(HeartbeatResponseTest, ShouldNotChangeSyncSourceWhenNodeIsStaleByHeartbea
// set up complete, time for actual check
startCapturingLogMessages();
- auto metadata = makeMetadata(fresherLastOpTimeApplied);
- ASSERT_FALSE(
- getTopoCoord().shouldChangeSyncSource(HostAndPort("host2"), OpTime(), metadata, now()));
+ ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
+ HostAndPort("host2"), OpTime(), fresherLastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(0, countLogLinesContaining("re-evaluating sync source"));
}
@@ -5333,7 +5323,7 @@ TEST_F(HeartbeatResponseTest, ShouldChangeSyncSourceWhenFresherMemberExists) {
// set up complete, time for actual check
startCapturingLogMessages();
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(), now()));
+ HostAndPort("host2"), OpTime(), OpTime(), false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(1, countLogLinesContaining("re-evaluating sync source"));
}
@@ -5367,18 +5357,18 @@ TEST_F(HeartbeatResponseTest, ShouldNotChangeSyncSourceWhileFresherMemberIsBlack
// set up complete, time for actual check
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(), now()));
+ HostAndPort("host2"), OpTime(), OpTime(), false, now()));
// unblacklist with too early a time (node should remained blacklisted)
getTopoCoord().unblacklistSyncSource(HostAndPort("host3"), now() + Milliseconds(90));
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(), now()));
+ HostAndPort("host2"), OpTime(), OpTime(), false, now()));
// unblacklist and it should succeed
getTopoCoord().unblacklistSyncSource(HostAndPort("host3"), now() + Milliseconds(100));
startCapturingLogMessages();
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(), now()));
+ HostAndPort("host2"), OpTime(), OpTime(), false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(1, countLogLinesContaining("re-evaluating sync source"));
}
@@ -5412,7 +5402,7 @@ TEST_F(HeartbeatResponseTest, ShouldNotChangeSyncSourceWhenFresherMemberIsDown)
nextAction = receiveDownHeartbeat(HostAndPort("host3"), "rs0", lastOpTimeApplied);
ASSERT_NO_ACTION(nextAction.getAction());
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(), now()));
+ HostAndPort("host2"), OpTime(), OpTime(), false, now()));
}
TEST_F(HeartbeatResponseTest, ShouldNotChangeSyncSourceWhenFresherMemberIsNotReadable) {
@@ -5442,7 +5432,7 @@ TEST_F(HeartbeatResponseTest, ShouldNotChangeSyncSourceWhenFresherMemberIsNotRea
// set up complete, time for actual check
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(), now()));
+ HostAndPort("host2"), OpTime(), OpTime(), false, now()));
}
TEST_F(HeartbeatResponseTest, ShouldNotChangeSyncSourceWhenFresherMemberDoesNotBuildIndexes) {
@@ -5487,7 +5477,7 @@ TEST_F(HeartbeatResponseTest, ShouldNotChangeSyncSourceWhenFresherMemberDoesNotB
// set up complete, time for actual check
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(), now()));
+ HostAndPort("host2"), OpTime(), OpTime(), false, now()));
}
TEST_F(HeartbeatResponseTest,
@@ -5538,7 +5528,7 @@ TEST_F(HeartbeatResponseTest,
// set up complete, time for actual check
startCapturingLogMessages();
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(), now()));
+ HostAndPort("host2"), OpTime(), OpTime(), false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(1, countLogLinesContaining("re-evaluating sync source"));
}
diff --git a/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp
index 9e04bf8942d..684d39514a9 100644
--- a/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl_v1_test.cpp
@@ -52,7 +52,6 @@
ASSERT_EQUALS(mongo::repl::HeartbeatResponseAction::NoAction, (EXPRESSION))
using std::unique_ptr;
-using mongo::rpc::ReplSetMetadata;
namespace mongo {
namespace repl {
@@ -149,20 +148,6 @@ protected:
_currentConfig = config;
}
- // Make the metadata coming from sync source.
- // Only set visibleOpTime, primaryIndex and syncSourceIndex
- ReplSetMetadata makeMetadata(OpTime opTime = OpTime(),
- int primaryIndex = -1,
- int syncSourceIndex = -1) {
- return ReplSetMetadata(_topo->getTerm(),
- OpTime(),
- opTime,
- _currentConfig.getConfigVersion(),
- OID(),
- primaryIndex,
- syncSourceIndex);
- }
-
HeartbeatResponseAction receiveUpHeartbeat(const HostAndPort& member,
const std::string& setName,
MemberState memberState,
@@ -664,9 +649,9 @@ TEST_F(TopoCoordTest, ChooseRequestedSyncSourceOnlyTheFirstTimeAfterTheSyncSourc
// force should cause shouldChangeSyncSource() to return true
// even if the currentSource is the force target
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("h2"), OpTime(), makeMetadata(oldOpTime), now()));
+ HostAndPort("h2"), OpTime(), oldOpTime, false, now()));
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("h3"), OpTime(), makeMetadata(newOpTime), now()));
+ HostAndPort("h3"), OpTime(), newOpTime, false, now()));
getTopoCoord().chooseNewSyncSource(now()++, Timestamp());
ASSERT_EQUALS(HostAndPort("h2"), getTopoCoord().getSyncSourceAddress());
@@ -3093,7 +3078,7 @@ TEST_F(HeartbeatResponseTestV1,
// set up complete, time for actual check
startCapturingLogMessages();
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(1, countLogLinesContaining("re-evaluating sync source"));
}
@@ -3135,7 +3120,7 @@ TEST_F(HeartbeatResponseTestV1,
ASSERT_NO_ACTION(nextAction.getAction());
// Show we like host2 while it is primary.
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), lastOpTimeApplied, makeMetadata(lastOpTimeApplied, 1), now()));
+ HostAndPort("host2"), lastOpTimeApplied, lastOpTimeApplied, false, now()));
// Show that we also like host2 while it has a sync source.
nextAction = receiveUpHeartbeat(HostAndPort("host2"),
@@ -3146,7 +3131,7 @@ TEST_F(HeartbeatResponseTestV1,
lastOpTimeApplied);
ASSERT_NO_ACTION(nextAction.getAction());
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), lastOpTimeApplied, makeMetadata(lastOpTimeApplied, 2, 2), now()));
+ HostAndPort("host2"), lastOpTimeApplied, lastOpTimeApplied, true, now()));
// Show that we do not like it when it is not PRIMARY and lacks a sync source and lacks progress
// beyond our own.
@@ -3158,16 +3143,9 @@ TEST_F(HeartbeatResponseTestV1,
lastOpTimeApplied);
ASSERT_NO_ACTION(nextAction.getAction());
ASSERT(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), lastOpTimeApplied, makeMetadata(lastOpTimeApplied), now()));
-
- // Sometimes the heartbeat is stale and the metadata says it's the primary. Trust the metadata.
- ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"),
- lastOpTimeApplied,
- makeMetadata(lastOpTimeApplied, 1 /* host2 is primary */, -1 /* no sync source */),
- now()));
+ HostAndPort("host2"), lastOpTimeApplied, lastOpTimeApplied, false, now()));
- // But if it is secondary and has some progress beyond our own, we still like it.
+ // But if it has some progress beyond our own, we still like it.
OpTime newerThanLastOpTimeApplied = OpTime(Timestamp(500, 0), 0);
nextAction = receiveUpHeartbeat(HostAndPort("host2"),
"rs0",
@@ -3177,7 +3155,7 @@ TEST_F(HeartbeatResponseTestV1,
newerThanLastOpTimeApplied);
ASSERT_NO_ACTION(nextAction.getAction());
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), lastOpTimeApplied, makeMetadata(newerThanLastOpTimeApplied), now()));
+ HostAndPort("host2"), lastOpTimeApplied, newerThanLastOpTimeApplied, false, now()));
}
TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberIsDown) {
@@ -3209,7 +3187,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberIsDown
nextAction = receiveDownHeartbeat(HostAndPort("host3"), "rs0", lastOpTimeApplied);
ASSERT_NO_ACTION(nextAction.getAction());
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
}
TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhileFresherMemberIsBlackListed) {
@@ -3241,18 +3219,18 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhileFresherMemberIsBla
// set up complete, time for actual check
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
// unblacklist with too early a time (node should remained blacklisted)
getTopoCoord().unblacklistSyncSource(HostAndPort("host3"), now() + Milliseconds(90));
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
// unblacklist and it should succeed
getTopoCoord().unblacklistSyncSource(HostAndPort("host3"), now() + Milliseconds(100));
startCapturingLogMessages();
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(1, countLogLinesContaining("re-evaluating sync source"));
}
@@ -3285,7 +3263,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceIfNodeIsFreshByHeartbea
// set up complete, time for actual check
startCapturingLogMessages();
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(0, countLogLinesContaining("re-evaluating sync source"));
}
@@ -3318,7 +3296,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceIfNodeIsStaleByHeartbea
// set up complete, time for actual check
startCapturingLogMessages();
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(fresherLastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), fresherLastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(0, countLogLinesContaining("re-evaluating sync source"));
}
@@ -3350,7 +3328,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldChangeSyncSourceWhenFresherMemberExists) {
// set up complete, time for actual check
startCapturingLogMessages();
ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, false, now()));
stopCapturingLogMessages();
ASSERT_EQUALS(1, countLogLinesContaining("re-evaluating sync source"));
}
@@ -3359,15 +3337,14 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenMemberHasYetToHeart
// In this test, the TopologyCoordinator should not tell us to change sync sources away from
// "host2" since we do not use the member's heartbeatdata in pv1.
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(), now()));
+ HostAndPort("host2"), OpTime(), OpTime(), true, now()));
}
TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenMemberNotInConfig) {
// In this test, the TopologyCoordinator should tell us to change sync sources away from
- // "host4" since "host4" is absent from the config of version 10.
- ReplSetMetadata metadata(0, OpTime(), OpTime(), 10, OID(), -1, -1);
- ASSERT_TRUE(
- getTopoCoord().shouldChangeSyncSource(HostAndPort("host4"), OpTime(), metadata, now()));
+ // "host4" since "host4" is absent from the config
+ ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(
+ HostAndPort("host4"), OpTime(), OpTime(), true, now()));
}
// TODO(dannenberg) figure out what this is trying to test..
@@ -4297,7 +4274,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberDoesNo
// set up complete, time for actual check
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, true, now()));
}
TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberIsNotReadable) {
@@ -4327,7 +4304,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenFresherMemberIsNotR
// set up complete, time for actual check
ASSERT_FALSE(getTopoCoord().shouldChangeSyncSource(
- HostAndPort("host2"), OpTime(), makeMetadata(lastOpTimeApplied), now()));
+ HostAndPort("host2"), OpTime(), lastOpTimeApplied, true, now()));
}
class HeartbeatResponseTestOneRetryV1 : public HeartbeatResponseTestV1 {
diff --git a/src/mongo/db/repl/update_position_args.h b/src/mongo/db/repl/update_position_args.h
index 0acac33dd6f..bb4a94d8ffb 100644
--- a/src/mongo/db/repl/update_position_args.h
+++ b/src/mongo/db/repl/update_position_args.h
@@ -40,7 +40,7 @@ class Status;
namespace repl {
/**
- * Arguments to the update position command.
+ * Arguments to the handshake command.
*/
class UpdatePositionArgs {
public: