diff --git a/sqlitecluster/SQLiteNode.cpp b/sqlitecluster/SQLiteNode.cpp index 4db1beca1..a87e25f96 100644 --- a/sqlitecluster/SQLiteNode.cpp +++ b/sqlitecluster/SQLiteNode.cpp @@ -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; @@ -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;