SuperCache.Cluster.Raft.Group (SuperCache v1.9.0)

Copy Markdown View Source

Maps SuperCache partitions to Raft server groups.

Each partition gets one Raft cluster named after the partition. The voting members are the partition's primary and replicas from SuperCache.Cluster.Manager, so all nodes sharing a partition map derive the same membership. The primary node creates the group; replica nodes host their server and wait for it to become available.

Summary

Functions

Return status snapshots for all locally tracked groups.

Return the cluster name for a partition.

Return {to_add, to_remove} between current and desired member ids.

Ensure this node has a started group for a partition.

Return the partition indexes this node currently owns.

Return the state machine tuple for a partition.

Return all server ids for a partition, in deterministic {name, node} order derived from the partition map.

Derive deterministic member ids from a {primary, replicas} tuple.

Return the local Raft server name for a partition.

Prepare a node for joining a partition's group.

Return this node's server id for a partition.

Start the Raft group for a partition.

Start groups for every partition owned by this node.

Return a bounded status snapshot for a partition's local group.

Stop the local Raft server for a partition.

Stop every local group started by this node.

Return the partition indexes with a local group started.

Forget all tracked groups without stopping their servers.

Functions

all_status()

@spec all_status() :: [map()]

Return status snapshots for all locally tracked groups.

cluster_name(partition_idx)

@spec cluster_name(non_neg_integer()) :: atom()

Return the cluster name for a partition.

diff_members(current, desired)

@spec diff_members([term()], [term()]) :: {[term()], [term()]}

Return {to_add, to_remove} between current and desired member ids.

ensure_started(partition_idx)

@spec ensure_started(non_neg_integer()) :: :ok | {:error, term()}

Ensure this node has a started group for a partition.

local_partitions()

@spec local_partitions() :: [non_neg_integer()]

Return the partition indexes this node currently owns.

machine(partition_idx)

@spec machine(non_neg_integer()) :: tuple()

Return the state machine tuple for a partition.

member_ids(partition_idx)

@spec member_ids(non_neg_integer()) :: [{atom(), node()}]

Return all server ids for a partition, in deterministic {name, node} order derived from the partition map.

members_from(arg, partition_idx)

@spec members_from({node(), [node()]}, non_neg_integer()) :: [{atom(), node()}]

Derive deterministic member ids from a {primary, replicas} tuple.

name(partition_idx)

@spec name(non_neg_integer()) :: atom()

Return the local Raft server name for a partition.

prepare_member(partition_idx, target \\ node())

@spec prepare_member(non_neg_integer(), node()) :: :ok | {:error, term()}

Prepare a node for joining a partition's group.

Discards stale local state for the partition so the member rebuilds from the committed log: it force-deletes the local Raft server (persisted log and last_applied), clears the local ETS partition, and resets the applied-index watermark. Safe to repeat.

When target differs from this node, the work runs on target via :erpc; the local variant is prepare_member_local/1.

server_id(partition_idx)

@spec server_id(non_neg_integer()) :: {atom(), node()}

Return this node's server id for a partition.

start(partition_idx)

@spec start(non_neg_integer()) :: :ok | {:error, term()}

Start the Raft group for a partition.

start_all()

@spec start_all() :: :ok

Start groups for every partition owned by this node.

status(partition_idx)

@spec status(non_neg_integer()) :: map()

Return a bounded status snapshot for a partition's local group.

stop(partition_idx)

@spec stop(non_neg_integer()) :: :ok | {:error, term()}

Stop the local Raft server for a partition.

stop_all()

@spec stop_all() :: :ok

Stop every local group started by this node.

tracked()

@spec tracked() :: [non_neg_integer()]

Return the partition indexes with a local group started.

untrack_all()

@spec untrack_all() :: :ok

Forget all tracked groups without stopping their servers.