Skip to content
Merged
Changes from all 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
12 changes: 12 additions & 0 deletions sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,12 @@ 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) {
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 +2240,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 && _leadPeer) {
newSyncPeer = _leadPeer;
}

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