Packages

Distributed supervisor & process registry built with DELTA-CRDTs

Current section

Files

Jump to
horde_classic lib horde uniform_random_distribution.ex
Raw

lib/horde/uniform_random_distribution.ex

defmodule HordeClassic.UniformRandomDistribution do
@behaviour HordeClassic.DistributionStrategy
@moduledoc """
Distributes processes with an uniform probability to
any node that is alive.
"""
@doc """
Selects a random alive node.
"""
def choose_node(_identifier, members) do
members
|> Enum.filter(&match?(%{status: :alive}, &1))
|> case do
[] ->
{:error, :no_alive_nodes}
members ->
chosen_member =
Enum.shuffle(members)
|> List.first()
{:ok, chosen_member}
end
end
@doc """
Quorum checks are not enforced, so the process will be
(re)started on both sides of a netsplit.
"""
def has_quorum?(_members), do: true
end