Horde v0.7.0 Horde.Registry behaviour View Source
A distributed process registry.
Horde.Registry implements a distributed Registry backed by a δ-CRDT (provided by DeltaCrdt
). This CRDT is used for both tracking membership of the cluster and implementing the registry functionality itself. Local changes to the registry will automatically be synced to other nodes in the cluster.
Cluster membership is managed with Horde.Cluster
. Joining a cluster can be done with Horde.Cluster.set_members/2
. To take a node out of the cluster, call Horde.Cluster.set_members/2
without that node in the list.
Horde.Registry supports the common "via tuple", described in the documentation for GenServer
.
Horde.Registry is API-compatible with Registry
, with the following exceptions:
- Horde.Registry does not support
keys: :duplicate
. - Horde.Registry does not support partitions.
- Horde.Registry sends an exit signal to a process when it has lost a naming conflict. See
Horde.Registry.register/3
for details.
Module-based Registry
Horde supports module-based registries to enable dynamic runtime configuration.
defmodule MyRegistry do
use Horde.Registry
def init(options) do
{:ok, Keyword.put(options, :members, get_members())}
end
defp get_members() do
# ...
end
end
Then you can use MyRegistry.child_spec/1
and MyRegistry.start_link/1
in the same way as you'd use Horde.Registry.child_spec/1
and Horde.Registry.start_link/1
.
Link to this section Summary
Functions
See start_link/2
for options.
Works like Registry.init/1
.
Register a process under the given name. See Registry.register/3
.
Link to this section Types
option()
View Source
option() ::
{:keys, :unique}
| {:name, atom()}
| {:delta_crdt_options, [DeltaCrdt.crdt_option()]}
| {:members, [Horde.Cluster.member()]}
option() :: {:keys, :unique} | {:name, atom()} | {:delta_crdt_options, [DeltaCrdt.crdt_option()]} | {:members, [Horde.Cluster.member()]}
Link to this section Functions
child_spec(arg) View Source
See start_link/2
for options.
count(registry)
View Source
count(registry :: Registry.registry()) :: non_neg_integer()
count(registry :: Registry.registry()) :: non_neg_integer()
See Registry.count/1
.
count_match(registry, key, pattern, guards \\ []) View Source
dispatch(registry, key, mfa_or_fun, opts \\ []) View Source
See Registry.dispatch/4
.
init(options) View Source
Works like Registry.init/1
.
keys(registry, pid)
View Source
keys(registry :: Registry.registry(), pid()) :: [Registry.key()]
keys(registry :: Registry.registry(), pid()) :: [Registry.key()]
See Registry.keys/2
.
lookup(arg) View Source
See Registry.lookup/2
.
lookup(registry, key) View Source
match(registry, key, pattern, guards \\ []) View Source
See Registry.match/4
.
members(options, name) View Source
meta(registry, key)
View Source
meta(registry :: Registry.registry(), key :: Registry.meta_key()) ::
{:ok, Registry.meta_value()} | :error
meta(registry :: Registry.registry(), key :: Registry.meta_key()) :: {:ok, Registry.meta_value()} | :error
See Registry.meta/2
.
put_meta(registry, key, value)
View Source
put_meta(
registry :: Registry.registry(),
key :: Registry.meta_key(),
value :: Registry.meta_value()
) :: :ok
put_meta( registry :: Registry.registry(), key :: Registry.meta_key(), value :: Registry.meta_value() ) :: :ok
See Registry.put_meta/3
.
register(registry, name, value)
View Source
register(
registry :: Registry.registry(),
name :: Registry.key(),
value :: Registry.value()
) :: {:ok, pid()} | {:error, {:already_registered, pid()}}
register( registry :: Registry.registry(), name :: Registry.key(), value :: Registry.value() ) :: {:ok, pid()} | {:error, {:already_registered, pid()}}
Register a process under the given name. See Registry.register/3
.
When 2 clustered registries register the same name at exactly the
same time, it will seem like name registration succeeds for both
registries. The function returns {:ok, pid}
for both of these
calls.
However, due to the eventually consistent nature of the CRDT,
conflict resolution will take place, and the CRDT will pick one of
the two processes as the "winner" of the name. The losing process
will be sent an exit signal (using Process.exit/2
) with the
following reason:
{:name_conflict, {name, value}, registry_name, winning_pid}
When two registries are joined using Horde.Cluster.set_members/2
,
this name conflict message can also occur.
When a cluster is recovering from a netsplit, this name conflict message can also occur.
select(registry, spec) View Source
See Registry.select/2
.
start_link(options) View Source
Does not accept [partitions: x]
, nor [keys: :duplicate]
as options.
start_link(mod, init_arg, opts \\ []) View Source
stop(supervisor, reason \\ :normal, timeout \\ 5000)
View Source
stop(Supervisor.supervisor(), reason :: term(), timeout()) :: :ok
stop(Supervisor.supervisor(), reason :: term(), timeout()) :: :ok
unregister(registry, name)
View Source
unregister(registry :: Registry.registry(), name :: Registry.key()) :: :ok
unregister(registry :: Registry.registry(), name :: Registry.key()) :: :ok
unregister_match(registry, key, pattern, guards \\ []) View Source
update_value(registry, key, callback) View Source
Link to this section Callbacks
child_spec(options)
View Source
child_spec(options :: [option()]) :: Supervisor.child_spec()
child_spec(options :: [option()]) :: Supervisor.child_spec()