DistSupervisor
DistSupervisor: a supervisor that manages children on remote cluster nodes (P5d).
Mirrors the local supervisor model but each child runs on a named remote node via NodeCall.call to its init function. The supervisor monitors each child with DistLink.monitor and applies the restart strategy when a Down arrives.
Restart strategies (matching local supervisor semantics): Permanent — always restart, regardless of exit reason. Transient — restart only on abnormal exit (Crash, Killed or NodeDown), not Normal. Temporary — never restart.
Supervision strategies (applied to the child set as a whole): OneForOne — restart only the failed child. OneForAll — restart all children when any one fails. RestForOne — restart the failed child and all children started after it.
Implementation note: the supervisor is a local actor. It spawns children via NodeCall.call, monitors them via DistLink.encode_req frames, and processes Down messages to restart as needed. The socket I/O and actor machinery are not eval-testable; only the pure restart-decision logic is tested here.
Types
A remote child specification.
Live child state tracked by the supervisor.
Functions
The number of supervised children.
The first child monitored under [ref], with its 0-based index in [children], or None. O(n).
The supervised children, in start order (every child the state tracks; no liveness check is made).
A supervisor using strategy [strat] with no children yet.
The child indices (0-based, in start order) to restart when child [failed_idx] of [n_children] fails: OneForOne restarts just [failed_idx], OneForAll every index 0..n_children-1, RestForOne failed_idx..n_children-1. [failed_idx] is not range-checked: OneForOne returns it as given, and RestForOne returns [] when it is at or past [n_children].
Examples
DistSupervisor.restart_indices(RestForOne, 1, 4) -- [1, 2, 3]
DistSupervisor.restart_indices(OneForAll, 1, 3) -- [0, 1, 2]Whether a child with restart policy [restart] should be restarted after it went down with [reason]: Permanent always, Temporary never, Transient on every reason except Normal (so Crash, Killed and NodeDown all restart it).
Examples
DistSupervisor.should_restart(Transient, DistLink.Normal) -- false
DistSupervisor.should_restart(Transient, DistLink.NodeDown) -- true[children] with the element at index [idx] replaced by [new_child]; the list is returned unchanged when [idx] is negative or out of range.