summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/bgsync.cpp
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2015-10-12 08:07:25 -0400
committermatt dannenberg <matt.dannenberg@10gen.com>2015-10-14 05:07:49 -0400
commitc860db7d39f8559054d1cebb83a6838accef8d94 (patch)
treeb3110c22e4afcdf6313144797957c8f6c4efe929 /src/mongo/db/repl/bgsync.cpp
parent7d43b0dba28b4b8e0184579a75c3dddab9d86e1f (diff)
downloadmongo-c860db7d39f8559054d1cebb83a6838accef8d94.tar.gz
SERVER-20822 make sync source decisions based on ReplSetMetadata
Diffstat (limited to 'src/mongo/db/repl/bgsync.cpp')
-rw-r--r--src/mongo/db/repl/bgsync.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp
index 96deab1683a..118a9e02046 100644
--- a/src/mongo/db/repl/bgsync.cpp
+++ b/src/mongo/db/repl/bgsync.cpp
@@ -426,6 +426,8 @@ void BackgroundSync::_fetcherCallback(const StatusWith<Fetcher::QueryResponse>&
}
const auto& queryResponse = result.getValue();
+ bool syncSourceHasSyncSource = false;
+ OpTime sourcesLastOp;
// Forward metadata (containing liveness information) to replication coordinator.
bool receivedMetadata =
@@ -443,6 +445,8 @@ void BackgroundSync::_fetcherCallback(const StatusWith<Fetcher::QueryResponse>&
if (metadata.getPrimaryIndex() != rpc::ReplSetMetadata::kNoPrimary) {
_replCoord->cancelAndRescheduleElectionTimeout();
}
+ syncSourceHasSyncSource = metadata.getSyncSourceIndex() != -1;
+ sourcesLastOp = metadata.getLastOpVisible();
}
const auto& documents = queryResponse.documents;
@@ -542,7 +546,7 @@ void BackgroundSync::_fetcherCallback(const StatusWith<Fetcher::QueryResponse>&
}
// re-evaluate quality of sync target
- if (_shouldChangeSyncSource(source)) {
+ if (_shouldChangeSyncSource(source, sourcesLastOp, syncSourceHasSyncSource)) {
return;
}
@@ -562,7 +566,9 @@ void BackgroundSync::_fetcherCallback(const StatusWith<Fetcher::QueryResponse>&
}
}
-bool BackgroundSync::_shouldChangeSyncSource(const HostAndPort& syncSource) {
+bool BackgroundSync::_shouldChangeSyncSource(const HostAndPort& syncSource,
+ const OpTime& syncSourceLastOpTime,
+ bool syncSourceHasSyncSource) {
// is it even still around?
if (getSyncTarget().empty() || syncSource.empty()) {
return true;
@@ -570,7 +576,8 @@ bool BackgroundSync::_shouldChangeSyncSource(const HostAndPort& syncSource) {
// check other members: is any member's optime more than MaxSyncSourceLag seconds
// ahead of the current sync source?
- return _replCoord->shouldChangeSyncSource(syncSource);
+ return _replCoord->shouldChangeSyncSource(
+ syncSource, syncSourceLastOpTime, syncSourceHasSyncSource);
}