RaftEx.Server.Cluster (raft_ex v0.1.0)

View Source

Helpers for managing the cluster membership map inside a server state.

The cluster is a %{server_id => peer_state} map stored under :cluster in the server state. This module keeps all mutation and query logic in one place so that RaftEx.Server stays focused on the Raft protocol.

Summary

Functions

Return the highest index agreed upon by a quorum (majority).

Determine the membership role of id/uid within cluster.

Get a single peer's state, returning nil if not found.

Build an initial cluster map from a list or map of peer identifiers.

Return the peer ids excluding self.

Return all peers excluding self.

Reset all peer statuses to :normal (used on becoming follower).

Reset query_index to 0 for all peers (used on term change).

Update a peer by merging update into its current state.

Collect the match indexes of all voter peers plus the leader's own last written index.

Types

cluster()

@type cluster() :: RaftEx.Types.cluster()

peer_state()

@type peer_state() :: RaftEx.Types.peer_state()

server_id()

@type server_id() :: RaftEx.Types.server_id()

Functions

agreed_commit(indexes)

@spec agreed_commit([RaftEx.Types.index()]) :: RaftEx.Types.index()

Return the highest index agreed upon by a quorum (majority).

get_membership(cluster, peer_id, uid, default)

Determine the membership role of id/uid within cluster.

get_peer(peer_id, cluster)

@spec get_peer(server_id(), cluster()) :: peer_state() | nil

Get a single peer's state, returning nil if not found.

new(self, peers)

@spec new(server_id(), [server_id()] | map()) :: cluster()

Build an initial cluster map from a list or map of peer identifiers.

peer_ids(self, cluster)

@spec peer_ids(server_id(), cluster()) :: [server_id()]

Return the peer ids excluding self.

peers(self, cluster)

@spec peers(server_id(), cluster()) :: cluster()

Return all peers excluding self.

reset_peer_statuses(cluster)

@spec reset_peer_statuses(cluster()) :: cluster()

Reset all peer statuses to :normal (used on becoming follower).

reset_query_indexes(cluster)

@spec reset_query_indexes(cluster()) :: cluster()

Reset query_index to 0 for all peers (used on term change).

update_peer(peer_id, update, cluster)

@spec update_peer(server_id(), map(), cluster()) :: cluster()

Update a peer by merging update into its current state.

voter_match_indexes(self, cluster, leader_last_written)

@spec voter_match_indexes(server_id(), cluster(), RaftEx.Types.index()) :: [
  RaftEx.Types.index()
]

Collect the match indexes of all voter peers plus the leader's own last written index.

Used to compute the new commit index.