Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,7 @@ void SQLiteNode::_updateSyncPeer()
{
SQLitePeer* newSyncPeer = nullptr;
uint64_t commitCount = _db.getCommitCount();
bool isLeaderValidPeer = false;
for (auto peer : _peerList) {
// If either of these conditions are true, then we can't use this peer.
if (!peer->loggedIn || peer->commitCount <= commitCount) {
Expand All @@ -2212,6 +2213,13 @@ void SQLiteNode::_updateSyncPeer()
continue;
}

// We want to sync, if possible, from a peer that is not the leader. So at this point, skip choosing it
// as the newSyncPeer.
if (peer == _leadPeer) {
isLeaderValidPeer = true;
continue;
}

// Any peer that makes it to here is a usable peer, so it's by default better than nothing.
if (!newSyncPeer) {
newSyncPeer = peer;
Expand All @@ -2234,6 +2242,12 @@ void SQLiteNode::_updateSyncPeer()
}
}

// If we reached this point, it means that there are no other available peers to sync from, but leader
// was a valid choice. In this case, let's use it as the newSyncPeer.
if (!newSyncPeer && isLeaderValidPeer) {
newSyncPeer = _leadPeer;
}

// Log that we've changed peers.
if (_syncPeer != newSyncPeer) {
string from, to;
Expand Down