Roux.Database.Heir (roux v0.2.2)

Copy Markdown View Source

Preserves ETS tables across Roux.Database.TableOwner crashes.

When TableOwner dies, ETS automatically transfers all heir-protected tables to this process via ETS-TRANSFER messages. The new TableOwner calls reclaim/1 in its init/1 to get them back. During normal operation this process is idle.

Started before TableOwner under a :rest_for_one supervisor. Its PID is published via :persistent_term so TableOwner can find it without passing PIDs through the supervisor spec.

Summary

Functions

Returns a specification to start this module under a supervisor.

Reclaims all tables held by the heir process.

Reads the heir PID from persistent_term for the given supervisor.

Types

tables()

@type tables() :: %{required(atom()) => :ets.tid()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

reclaim(heir_pid)

@spec reclaim(pid()) :: {:ok, tables()}

Reclaims all tables held by the heir process.

Called by a freshly started TableOwner. The heir gives away each table to the caller and returns the table map. Returns {:ok, %{}} when no tables are held (fresh start).

whereis(sup_pid)

@spec whereis(pid()) :: pid()

Reads the heir PID from persistent_term for the given supervisor.