Malachi.Cluster.PolicyServer (malachi v0.22.7)

View Source

A thin named facade over Malachi.Cluster.RaCluster for the cluster's storage policy store (Malachi.Cluster.PolicyMachine): start the dedicated Raft cluster, submit policy commands through the log, and read the replicated definitions. Mirrors Malachi.Auth.AclServer; ra must already be running. This module owns only the policy cluster, not ra's lifecycle.

Writes (define/3, delete/2) go through the log, replicated by consensus, so every node reads the same definition. Reads (get/2, all/1) use :ra.local_query against the local replica: no consensus round trip, which is what lets the placement path resolve a topic's spread attribute on every segment creation without a cross-node hop. They are eventually consistent, and a policy edit reaching a node within replication lag is the same guarantee ACL grants get.

Summary

Functions

Every definition as a map from name to policy, read from the local replica.

Defines (or replaces) the policy named name. Reply :ok, or {:error, :invalid_policy}.

Removes the policy named name (idempotent). Reply :ok.

Stops and deletes the policy store's Raft cluster (removing its on-disk state).

The policy named name, read from the local replica (nil when undefined).

Ensures this node participates in the policy cluster (self-join), so a staggered boot converges to a fully-replicated store. Idempotent and best-effort. Mirrors Malachi.Auth.AclServer.reconcile/2.

Starts the policy store's Raft cluster named cluster_name across nodes (default the local node) and returns a server_id addressing a real member (the local node when it is one, else the first).

Types

cluster_name()

@type cluster_name() :: atom()

server_id()

@type server_id() :: {cluster_name(), node()}

Functions

all(server_id)

@spec all(server_id()) ::
  {:ok,
   %{required(Malachi.Cluster.Policy.name()) => Malachi.Cluster.Policy.t()}}
  | {:error, term()}

Every definition as a map from name to policy, read from the local replica.

define(server_id, name, policy)

@spec define(server_id(), Malachi.Cluster.Policy.name(), Malachi.Cluster.Policy.t()) ::
  {:ok, term()} | {:error, term()}

Defines (or replaces) the policy named name. Reply :ok, or {:error, :invalid_policy}.

delete(server_id, name)

@spec delete(server_id(), Malachi.Cluster.Policy.name()) ::
  {:ok, term()} | {:error, term()}

Removes the policy named name (idempotent). Reply :ok.

delete_cluster(cluster_name)

@spec delete_cluster(cluster_name()) :: :ok

Stops and deletes the policy store's Raft cluster (removing its on-disk state).

get(server_id, name)

@spec get(server_id(), Malachi.Cluster.Policy.name()) ::
  {:ok, Malachi.Cluster.Policy.t() | nil} | {:error, term()}

The policy named name, read from the local replica (nil when undefined).

reconcile(cluster_name, nodes)

@spec reconcile(cluster_name(), [node()]) :: :ok

Ensures this node participates in the policy cluster (self-join), so a staggered boot converges to a fully-replicated store. Idempotent and best-effort. Mirrors Malachi.Auth.AclServer.reconcile/2.

start(cluster_name, nodes \\ [node()])

@spec start(cluster_name(), [node()]) :: {:ok, server_id()} | {:error, term()}

Starts the policy store's Raft cluster named cluster_name across nodes (default the local node) and returns a server_id addressing a real member (the local node when it is one, else the first).