mirror of
https://github.com/scylladb/scylladb.git
synced 2026-06-06 23:13:15 +00:00
In `raft_group0::discover_group0`, when we detect that we became a leader, we destroy the `discovery` object, create a group 0, and respond with the group 0 information to all further requests. However there is a small time window after becoming a leader but before destroying the `discovery` object where we still answer to discovery requests by returning peer lists, without informing the requester that we become a leader. This is unsafe, and the algorithm specification does not allow this. For example, consider the seed graph 0 --> 1. It satisfies the property required by the algorithm, i.e. that there exists a vertex reachable from every other vertex. Now `1` can become a leader before `0` contacts it. When `0` contacts `1`, it should learn from `1` that `1` created a group 0, so `0` does not become a leader itself and create another group 0. However, with the current implementation, it may happen that `0` contacts `1` and receives a peer list (instead of group 0 information), and also becomes a leader because it has the smallest ID, so we end up with two group 0s. The correct thing to do is to stop returning peer lists to requests immediately after becoming a leader. This is what we fix in this commit.