Grove.Cluster.Membership (Grove v0.1.1)

View Source

Manages peer discovery using Erlang :pg process groups.

Each replication group has a corresponding :pg group. Replicas join/leave automatically based on their GenServer lifecycle.

Usage

# Join a group (typically called from Replication.Server.init/1)
:ok = Membership.join({:document, "doc-123"}, self())

# Get all peers in a group (excluding self)
peers = Membership.peers({:document, "doc-123"})

# Broadcast a message to all peers
:ok = Membership.broadcast({:document, "doc-123"}, {:delta, delta})

Supervision

This module is started automatically by the Grove application. It manages a :pg scope for all Grove replication groups.

Summary

Functions

Broadcasts a message to all peers in a group (excluding self).

Returns a specification to start this module under a supervisor.

Returns all groups that currently have members.

Joins a process to a replication group.

Removes a process from a replication group.

Returns the count of members in a group.

Returns all members of a group, including the calling process.

Returns all members of a group, excluding the calling process.

Selects up to n random peers from a group for gossip.

Returns the :pg scope used for replication groups.

Starts the membership manager.

Functions

broadcast(group, message)

@spec broadcast(term(), term()) :: :ok

Broadcasts a message to all peers in a group (excluding self).

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

groups()

@spec groups() :: [term()]

Returns all groups that currently have members.

join(group, pid \\ self())

@spec join(term(), pid()) :: :ok

Joins a process to a replication group.

The process will automatically leave the group when it terminates.

leave(group, pid \\ self())

@spec leave(group :: term(), pid()) :: :ok

Removes a process from a replication group.

member_count(group)

@spec member_count(term()) :: non_neg_integer()

Returns the count of members in a group.

members(group)

@spec members(term()) :: [pid()]

Returns all members of a group, including the calling process.

peers(group)

@spec peers(term()) :: [pid()]

Returns all members of a group, excluding the calling process.

random_peers(group, n)

@spec random_peers(term(), pos_integer()) :: [pid()]

Selects up to n random peers from a group for gossip.

scope()

@spec scope() :: atom()

Returns the :pg scope used for replication groups.

start_link(opts \\ [])

Starts the membership manager.

This is called automatically by the Grove application supervisor.