Grove.Cluster.Membership (Grove v0.1.1)
View SourceManages 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
Broadcasts a message to all peers in a group (excluding self).
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec groups() :: [term()]
Returns all groups that currently have members.
Joins a process to a replication group.
The process will automatically leave the group when it terminates.
Removes a process from a replication group.
@spec member_count(term()) :: non_neg_integer()
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.
@spec random_peers(term(), pos_integer()) :: [pid()]
Selects up to n random peers from a group for gossip.
@spec scope() :: atom()
Returns the :pg scope used for replication groups.
Starts the membership manager.
This is called automatically by the Grove application supervisor.