March Docs

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

typeRestartStrategyRestartStrategy = Permanent | Transient | Temporary#
typeSupervisionStrategySupervisionStrategy = OneForOne | OneForAll | RestForOne#
typeRemoteChildRemoteChild = {#

A remote child specification.

typeChildStateChildState = {#

Live child state tracked by the supervisor.

typeStateState = {#

Supervisor state.

Functions

fnchild_countchild_count(s : State) : Int do List.length(s.children) end#

The number of supervised children.

fnfind_child_by_reffind_child_by_ref(children : List(ChildState),#

The first child monitored under [ref], with its 0-based index in [children], or None. O(n).

fnlive_childrenlive_children(s : State) : List(ChildState) do s.children end#

The supervised children, in start order (every child the state tracks; no liveness check is made).

fnmakemake(strat : SupervisionStrategy) : State#

A supervisor using strategy [strat] with no children yet.

fnrestart_indicesrestart_indices(strat : SupervisionStrategy, failed_idx : Int,#

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]
fnshould_restartshould_restart(restart : RestartStrategy, reason : DistLink.DownReason) : Bool#

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
fnupdate_childupdate_child(children : List(ChildState), idx : Int,#

[children] with the element at index [idx] replaced by [new_child]; the list is returned unchanged when [idx] is negative or out of range.