Try
↑ ↓ move↵ openesc close
In this lesson · topic 6 of 7
  1. 1. Agreeing when nodes fail
  2. 2. Elections, terms and the log
  3. 3. Crash the leader and cut the cluster
  4. 4. The leader nobody follows
  5. 5. Walking a follower's log back to the leader's
  6. 6. Adding two nodes without ever having two majorities
  7. 7. Check votes, logs and quorums

Topic 6

Adding two nodes without ever having two majorities

7 min read

The cluster has to change

Machines die, hardware is replaced, load grows. Raft has to let operators add and remove servers while it keeps serving.

The trap is that the safety argument depends on a fixed set. Any two majorities of the same set share a node. Two majorities of different sets may not.

Why a direct switch fails

Old configuration: servers S1, S2, S3. Majority is 2. You want S1 to S5, where the majority is 3. You tell each server to adopt the new configuration, but they receive it at different moments.

Say S1 and S2 are still on the old configuration and S3, S4 and S5 have switched. Now S1 times out and asks for votes in term 7. S2 grants one. In S1’s view two of three is a majority, so S1 becomes leader. Meanwhile S3 also times out in term 7. With S4 and S5 it has three of five, a majority of the new set. S3 becomes leader too.

Two leaders in term 7, committing different entries. The two majorities, S1 with S2 and S3 with S4 and S5, share no server.

Joint consensus

The paper’s answer is a transitional configuration, C-old,new. While it is in effect, a decision needs a majority of the old set and a majority of the new set, counted separately. Elections and commits both follow that rule.

For the move from 3 to 5 servers, the leader first writes the C-old,new entry into its log. Servers use a configuration the moment it enters their log, committed or not. Under C-old,new an entry commits with 2 of S1, S2, S3 and 3 of S1 to S5. No leader can be elected without both, so neither side can act alone. Once C-old,new commits, the leader writes C-new. When C-new commits, the old set is out of the picture.

Predict first

During joint consensus from servers S1 to S3 to servers S1 to S5, an entry is stored on S3, S4 and S5. Is it committed?

One server at a time

Ongaro’s later dissertation gives a simpler rule: change membership by one server at a time. Going from 3 to 4 servers, the majorities are 2 and 3. Any 2 of the old set and any 3 of the new set must overlap, because 2 + 3 = 5 is more than 4. The same holds for every single add or remove. A larger change becomes a sequence of single steps, each committed before the next.

This is easier to implement and is what many libraries do.

New servers join as learners

A fresh server has an empty log. If it counts toward the majority at once, the cluster can stall while it catches up. Say 3 voters become 4 with one empty newcomer, and the majority is now 3. A single crash among the old three leaves only two caught-up voters, so commits stop until the newcomer finishes copying. The paper has new servers join without a vote, receive entries until they are caught up, and only then enter the configuration.

Removed servers can disturb the rest

A server taken out of the cluster stops hearing heartbeats, times out and starts elections with ever higher terms. Those requests could force the leader to step down. The paper’s fix: a server ignores a RequestVote if it has heard from a current leader within the minimum election timeout. A removed server’s requests are then ignored until the leader’s heartbeats stop for real.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms