Fief.Router.Cache (Fief v0.1.0)

Copy Markdown View Source

The boring ETS owner (implementation.md §2, §5): holds the instance's routing-cache table. It sits before Fief.Node under the instance's rest_for_one supervisor, so a Fief.Node crash/restart never drops the cache mid-lookup — the restarted node overwrites rows as it re-joins, and readers fall back to the Authority on any miss.

Fief.Node is the table's only writer of routing state. Readers use plain :ets.lookup (the table is :public with read_concurrency: true); nothing ever calls this process or Fief.Node on the read path. Row shapes:

  • {{:route, vnode_id}, owner, prev_owner, row_epoch} — one cached table row; prev_owner nil = settled; row_epoch = epoch of the last CAS on this row (the transfer-session epoch, Fief.StateStore M4 decision)
  • {:table_epoch, epoch} — the epoch the cached table was read at
  • {:node_status, map}Fief.Node's published upward interface (%{node_id:, owned:, epoch:, lease_live?:, state:}); read it through Fief.Node.status/1
  • {:router_config, map} — static instance config the process-less Fief.Router reads on its hot path (store handle for the authority fallback, max_moved_hops, fallback_jitter, the leadership adapter for Fief.leader/1). Written once, here, at init — immutable, so it does not breach the single-writer rule for routing state (M4 phase B decision).

This process handles no messages of its own. If it ever grows handlers, the M2 process discipline applies: bind the sim context at init (done below) and end every handling with Fief.Seam.checkpoint(:handled).

Summary

Functions

Returns a specification to start this module under a supervisor.

Read the cached assignment for vnode: {:ok, {owner, prev_owner, row_epoch}, table_epoch}, or :miss — on miss (including a cache mid-refresh or an instance that is down) callers fall back to Fief.StateStore.read_table/1.

The instance's routing-cache ETS table name.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

lookup(instance, vnode)

@spec lookup(atom(), non_neg_integer()) ::
  {:ok, Fief.StateStore.assignment(), term()} | :miss

Read the cached assignment for vnode: {:ok, {owner, prev_owner, row_epoch}, table_epoch}, or :miss — on miss (including a cache mid-refresh or an instance that is down) callers fall back to Fief.StateStore.read_table/1.

start_link(opts)

table(instance)

@spec table(atom()) :: atom()

The instance's routing-cache ETS table name.