Skip to content

Commit

Permalink
Merge pull request #2041 from Expensify/dsilva_chooseSyncPeerOtherTha…
Browse files Browse the repository at this point in the history
…nLeader
  • Loading branch information
cead22 authored Dec 31, 2024
2 parents 04a92c2 + a92f259 commit 6367890
Showing 1 changed file with 12 additions and 0 deletions.
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

0 comments on commit 6367890

Please sign in to comment.