2017/01/11
rafted_value
: Raft protocol implementationraft_fleet
: Running and managing multiple consensus groups in a cluster:gen_statem
processLeaderHook
callbacksstart_link/2
RaftedValue.Server
module
:gen_statem
with 3 states: leader
, candidate
, follower
ExUnit
tests and property-based testsExUnit
tests
%S{f: v}
instead of %S{s | f: v}
rafted_value
processes within a cluster of ErlangVMsraft_fleet
raft_fleet
define “state” and operations on it by implementing RaftedValue.Data
behaviouratom
as ID of consensus group
atom
atom
-only restriction may be relaxed in future releasesraft_fleet
:global
module24
, b: 27
, c: 23
, d: 26
19
, b: 23
, c: 18
, d: 21
, e: 19
1/n_nodes
processes to migratemod
leads to really bad resultsdefun lrw_members(nodes_per_zone :: %{ZoneInfo.t => [node]}, group :: atom, n_replica :: pos_integer) :: [node] do
Enum.flat_map(nodes_per_zone, fn {_z, ns} ->
Enum.map(ns, fn n -> {Hash.calc({n, group}), n} end)
|> Enum.sort
|> Enum.map_reduce(0, fn({hash, node}, index) -> {{index, hash, node}, index + 1} end)
|> elem(0)
end)
|> Enum.sort
|> Enum.map(fn {_i, _h, n} -> n end)
|> Enum.take(n_replica)
end
:slave
module and test against multiple local nodes
raft_fleet
to implement job queues
YourApp.start/2
,
RaftFleet.activate/1
RaftFleet.deactivate/0
before terminating ErlangVM and wait for a while:noconnect
option of :erlang.send/3
is crucial hereraft_fleet
makes cluster-wide “state”s much easier