Skip to content

Commit 6367890

Browse files
authored
Merge pull request #2041 from Expensify/dsilva_chooseSyncPeerOtherThanLeader
2 parents 04a92c2 + a92f259 commit 6367890

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

sqlitecluster/SQLiteNode.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,12 @@ void SQLiteNode::_updateSyncPeer()
22122212
continue;
22132213
}
22142214

2215+
// We want to sync, if possible, from a peer that is not the leader. So at this point, skip choosing it
2216+
// as the newSyncPeer.
2217+
if (peer == _leadPeer) {
2218+
continue;
2219+
}
2220+
22152221
// Any peer that makes it to here is a usable peer, so it's by default better than nothing.
22162222
if (!newSyncPeer) {
22172223
newSyncPeer = peer;
@@ -2234,6 +2240,12 @@ void SQLiteNode::_updateSyncPeer()
22342240
}
22352241
}
22362242

2243+
// If we reached this point, it means that there are no other available peers to sync from, but leader
2244+
// was a valid choice. In this case, let's use it as the newSyncPeer.
2245+
if (!newSyncPeer && _leadPeer) {
2246+
newSyncPeer = _leadPeer;
2247+
}
2248+
22372249
// Log that we've changed peers.
22382250
if (_syncPeer != newSyncPeer) {
22392251
string from, to;

0 commit comments

Comments
 (0)