SuperWorker.Supervisor.Partition (SuperWorker v0.6.0)

Copy Markdown View Source

Partition processes of a SuperWorker.Supervisor.

A supervisor spreads its workers over one or more partitions. Each partition is a plain process running Looper.main_loop/1, owns the worker processes hashed to it, and traps exits so crashing workers never kill the partition itself.

Partitions are monitored (not linked) by the supervisor master, so a crashed partition is restarted individually without affecting the rest of the supervisor (see restart_partition/2). In turn, every partition monitors its master and stops when the master goes away.

Summary

Functions

Start a single partition process for the given partition id.

Entry point of a partition process.

Functions

init_additional_partitions(supervisor)

restart_partition(supervisor, partition_id)

@spec restart_partition(SuperWorker.Supervisor.t(), pos_integer()) ::
  {:ok, pos_integer(), pid(), reference()} | {:error, term()}

Start a single partition process for the given partition id.

Used at supervisor init and to restart a crashed partition without touching other partitions.

start_partition(state)

Entry point of a partition process.

Registers the partition in ETS, notifies the supervisor master, turns the process into a system process (traps exits), starts monitoring the master process and enters the main loop.