RaftEx.Leaderboard (raft_ex v0.1.0)

View Source

In-memory leaderboard for tracking Raft cluster leaders across nodes.

Provides a lightweight ETS-based registry that records which node is the current leader for each Raft cluster. Useful for client-side request routing so that commands can be sent directly to the leader.

Summary

Functions

Clear the leaderboard entry for a cluster.

Initialize the leaderboard ETS table. Idempotent.

Find the local server ID for a given cluster.

Look up the current leader for a cluster.

Look up cluster members.

Get the last recorded timestamp for a cluster.

Return all known leaderboard entries.

Record the current leader and members for a cluster.

Functions

clear(cluster_name)

@spec clear(term()) :: :ok

Clear the leaderboard entry for a cluster.

init()

Initialize the leaderboard ETS table. Idempotent.

local_server_id(cluster_name)

@spec local_server_id(term()) :: RaftEx.Types.server_id() | nil

Find the local server ID for a given cluster.

This is useful for routing requests to the local Raft server process.

lookup_leader(cluster_name)

@spec lookup_leader(term()) :: RaftEx.Types.server_id() | nil

Look up the current leader for a cluster.

lookup_members(cluster_name)

@spec lookup_members(term()) :: [RaftEx.Types.server_id()] | nil

Look up cluster members.

lookup_timestamp(cluster_name)

@spec lookup_timestamp(term()) :: DateTime.t() | nil

Get the last recorded timestamp for a cluster.

overview()

@spec overview() :: list()

Return all known leaderboard entries.

record(cluster_name, leader, members)

@spec record(term(), RaftEx.Types.server_id(), [RaftEx.Types.server_id()]) :: :ok

Record the current leader and members for a cluster.