Skip to content

CommitAdvance commits with half of an even-sized cluster, not a majority #33

Open

Description

@resetius

Problem

TVolatileState::CommitAdvance sorts the per-server match indexes in ascending order and takes Indices[nservers / 2] as the new commit index (raft.cpp#L82-L83). With an ascending sort, the entries at positions nservers / 2 .. nservers - 1 are the ones that have the index, which is nservers - nservers / 2 servers. For an odd cluster size that is a majority. For an even size it is exactly half.

Scenario

4 nodes: leader L and followers A, B, C. L has entries up to index 10, A has acknowledged 10, B and C have acknowledged 0. Indices = [0, 0, 10, 10], Indices[4 / 2] = Indices[2] = 10. The leader commits index 10, applies it, and answers the client although only 2 of 4 replicas hold it, which is not a majority. In a 2/2 partition the leader side {L, A} keeps committing and acknowledging writes although it has no majority. The acknowledged data also survives only as long as both holders do: if L and A are lost, the clients were told "committed" for data that a real majority rule would have required on a third node. (The election rule, MinVotes, already requires 3 of 4, so the two rules disagree.)

Expected

A commit index requires a strict majority of the cluster: more than nservers / 2 replicas (Raft paper, section 5.3 and Figure 2, "Rules for Servers: Leaders"). The index to take after an ascending sort is Indices[(nservers - 1) / 2].

Fix in PR #31

PR #31 (closed, not merged) contains the fix in 76aae7a (Indices[(nservers - 1) / 2]). Tests that cover it: test_majority_all_cluster_sizes, test_even_cluster_partition_requires_majority, plus the small deterministic cluster harness from test/test_correctness.cpp. Since the PR is closed, the fix would come as a separate small PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions