andrewjstone / rafter

An Erlang library application which implements the Raft consensus protocol
269 stars 32 forks source link

rafter_config:quorum_min/3 is incorrect for even numbers of servers #16

Closed andrewjstone closed 10 years ago

andrewjstone commented 10 years ago

quorum_min/3 works fine for odd numbers of servers, but the calculation is wrong for even numbers.

For even numbers of servers, the code should look like the following:

 case lists:member(Me, Servers) of
        true ->
            lists:nth(length(Indexes) div 2 + 1, Indexes);
        false ->
            lists:nth(length(Indexes) div 2, Indexes)
 end.
andrewjstone commented 10 years ago

A different approach via refactoring achieved the same ends.