RaftEx.LogMeta (raft_ex v0.1.0)

View Source

Durable metadata store for Raft servers: current_term, voted_for, and last_applied.

Storage layout

Data is stored in a DETS file (meta.dets) and mirrored into an ETS table for fast reads. Each row has the shape:

{uid, current_term, voted_for, last_applied}

Writes go to both DETS and ETS immediately. Synchronous writes (store_sync and delete_sync) additionally call :dets.sync/1 so the data is flushed to disk before the call returns.

Concurrency model

All writes are serialised through this GenServer. Reads bypass the process and access ETS directly, making them safe to call from any process.

Summary

Functions

Returns a specification to start this module under a supervisor.

Asynchronously delete all metadata for uid.

Synchronously delete all metadata for uid, fsyncing DETS before returning.

Fetch a single metadata field, returning nil if absent.

Fetch a metadata field, returning default when absent.

Start the metadata store and link it into the supervision tree.

Asynchronously store {uid, key, value}.

Synchronously store {uid, key, value}, fsyncing DETS before returning.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

delete(name, uid)

@spec delete(atom(), binary()) :: :ok

Asynchronously delete all metadata for uid.

delete_sync(name, uid)

@spec delete_sync(atom(), binary()) :: :ok

Synchronously delete all metadata for uid, fsyncing DETS before returning.

fetch(meta_name, uid, atom)

@spec fetch(atom(), binary(), :current_term | :voted_for | :last_applied) ::
  term() | nil

Fetch a single metadata field, returning nil if absent.

fetch(meta_name, uid, key, default)

@spec fetch(atom(), binary(), :current_term | :voted_for | :last_applied, term()) ::
  term()

Fetch a metadata field, returning default when absent.

start_link(cfg)

Start the metadata store and link it into the supervision tree.

store(name, uid, key, value)

@spec store(atom(), binary(), :current_term | :voted_for | :last_applied, term()) ::
  :ok

Asynchronously store {uid, key, value}.

store_sync(name, uid, key, value)

@spec store_sync(atom(), binary(), :current_term | :voted_for | :last_applied, term()) ::
  :ok

Synchronously store {uid, key, value}, fsyncing DETS before returning.