LibclusterMesh.Poller behaviour (libcluster_mesh v0.1.0)

Copy Markdown View Source

Shared GenServer poll loop for mesh strategies.

Every polling_interval it asks the strategy module for the current peers (discover/1), filters them down to the online ones that belong to the cluster, and hands the resulting node names to Cluster.Strategy.connect_nodes/4. Discovery runs in this process and the next poll is scheduled only once it returns, so a daemon slower than the interval delays polls instead of piling them up.

Discovery failures are logged and retried on the next interval; they never crash the strategy. Disconnects are left to the mesh and :net_kernel. A control-plane interruption can mark a peer offline while its direct data path and Erlang connection remain healthy, so a poll never tears down an established connection from a transient daemon view. net_ticktime closes a connection whose data path is actually gone.

Summary

Callbacks

Returns the current mesh peers, or an error message when the daemon cannot be queried.

Functions

Returns a specification to start this module under a supervisor.

Filters peers to online cluster members and maps them to node names.

Starts the poll loop for strategy (a module implementing discover/1).

Callbacks

discover(t)

@callback discover(LibclusterMesh.Config.t()) ::
  {:ok, [LibclusterMesh.Peer.t()]} | {:error, String.t()}

Returns the current mesh peers, or an error message when the daemon cannot be queried.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

nodes_for(peers, config)

@spec nodes_for([LibclusterMesh.Peer.t()], LibclusterMesh.Config.t()) :: [node()]

Filters peers to online cluster members and maps them to node names.

The local node is excluded (some daemons include it in their peer output), and duplicates are removed.

iex> peers = [
...>   %LibclusterMesh.Peer{ip: "100.64.0.7", hostname: "myapp-2"},
...>   %LibclusterMesh.Peer{ip: "100.64.0.3", hostname: "laptop"},
...>   %LibclusterMesh.Peer{ip: "100.64.0.9", hostname: "myapp-3", online?: false}
...> ]
iex> config = %LibclusterMesh.Config{node_basename: "myapp", hostnames: ["myapp-"], cli: "ztlctl"}
iex> LibclusterMesh.Poller.nodes_for(peers, config)
[:"myapp@100.64.0.7"]

start_link(strategy, default_cli, list, opts \\ [])

Starts the poll loop for strategy (a module implementing discover/1).

Called by the strategy's start_link/1 with the args libcluster passes in. opts are forwarded to LibclusterMesh.Config.new!/3, declaring which config keys the strategy supports. Raises ArgumentError when the topology config is invalid.