Horde v0.3.0-rc1 Horde.Registry View Source

A distributed process registry.

Horde.Registry implements a distributed Registry backed by an add-wins last-write-wins δ-CRDT (provided by DeltaCrdt.AWLWWMap). 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.

Because of the semantics of an AWLWWMap, the guarantees provided by Horde.Registry are more relaxed than those provided by the standard library Registry. Conflicts will be automatically silently resolved by the underlying AWLWWMap.

Cluster membership is managed with Horde.Cluster. Joining a cluster can be done with Horde.Cluster.join_hordes/2 and leaving the cluster happens automatically when you stop the registry with Horde.Registry.stop/3.

In the event of a network partition, using Horde.Cluster.join_hordes/2 to rejoin the two halves will fail with {:error, :network_partition_recovery_not_supported}. This is necessary to avoid the two halves of the cluster obliterating each other (since each side will have removed the other side’s pids from the CRDT). The correct behaviour in this case is to restart instances of Horde.Registry and join them to the larger cluster one by one.

Horde.Registry links itself to every pid in the registry. If you want to handle this (as opposed to letting your process exit and be restarted by its supervisor), then you should handle the EXIT signal. Note: in the event of a network partition, an EXIT signal will also be generated by the BEAM, so be prepared for that.

Horde.Registry supports the common “via tuple”, described in the documentation for GenServer.

Link to this section Summary

Functions

Child spec to enable easy inclusion into a supervisor

Returns the number of keys in a registry. It runs in constant time

Returns registered keys for pid

Finds the {pid, value} for the given key in registry

Reads registry metadata given on start_link/3

processes(registry) deprecated

Get the process registry of the horde

Register a process under the given name

Starts the registry as a supervised process

unregister the process under the given name

Link to this section Functions

Link to this function child_spec(options \\ []) View Source
child_spec(options :: list()) :: Supervisor.child_spec()

Child spec to enable easy inclusion into a supervisor.

Example:

supervise([
  Horde.Registry
])

Example:

supervise([
  {Horde.Registry, [name: MyApp.GlobalRegistry]}
])

Returns the number of keys in a registry. It runs in constant time.

Link to this function count_match(registry, key, pattern, guards \\ []) View Source
Link to this function dispatch(registry, key, mfa_or_fun, opts \\ []) View Source
Link to this function keys(registry, pid) View Source
keys(registry :: Registry.registry(), pid()) :: [Registry.key()]

Returns registered keys for pid

Finds the {pid, value} for the given key in registry

Link to this function match(registry, key, pattern, guards \\ []) View Source
Link to this function meta(registry, key) View Source
meta(registry :: Registry.registry(), key :: Registry.meta_key()) ::
  {:ok, Registry.meta_value()} | :error

Reads registry metadata given on start_link/3

This function is deprecated. Use match/4 instead.

Get the process registry of the horde

Link to this function put_meta(registry, key, value) View Source
put_meta(
  registry :: Registry.registry(),
  key :: Registry.meta_key(),
  value :: Registry.meta_value()
) :: :ok
Link to this function register(registry, name, value) View Source
register(
  registry :: GenServer.server(),
  name :: Registry.key(),
  value :: Registry.value()
) :: {:ok, pid()} | {:error, :already_registered, pid()}

Register a process under the given name

Starts the registry as a supervised process

Link to this function stop(supervisor, reason \\ :normal, timeout \\ 5000) View Source
stop(Supervisor.supervisor(), reason :: term(), timeout()) :: :ok
Link to this function unregister(registry, name) View Source
unregister(registry :: GenServer.server(), name :: GenServer.name()) :: :ok

unregister the process under the given name

Link to this function unregister_match(registry, key, pattern, guards \\ []) View Source
Link to this function update_value(registry, key, callback) View Source