View Source ProcessHub.Strategy.Distribution.Base protocol (ProcessHub v0.5.0-beta)
The distribution strategy protocol defines behaviour to identify the nodes which are responsible for a child process.
Summary
Functions
Returns a map of child_id to list of nodes where the child process belongs to.
Perform any necessary initialization and validation for the started children.
Returns whether this distribution strategy produces deterministic results based solely on the node topology.
Computes a distribution signature based on the current state that affects distribution.
Triggered when coordinator is initialized.
Types
@type t() :: term()
All the types that implement this protocol.
Functions
@spec belongs_to( strategy :: struct(), hub :: ProcessHub.Hub.t(), child_ids :: [ProcessHub.child_id()], replication_factor :: pos_integer() ) :: %{required(ProcessHub.child_id()) => [node()]}
Returns a map of child_id to list of nodes where the child process belongs to.
The map is used to determine where the child process should be started or migrated to.
@spec children_init(struct(), ProcessHub.Hub.t(), [map()], keyword()) :: :ok | {:error, any()}
Perform any necessary initialization and validation for the started children.
Returns whether this distribution strategy produces deterministic results based solely on the node topology.
Deterministic strategies (like ConsistentHashing) always produce the same distribution for the same set of nodes. Non-deterministic strategies (like CentralizedLoadBalancer) may produce different distributions based on runtime factors like node load.
This is used to optimize child validation - deterministic strategies can skip revalidation when topology signature matches.
@spec distribution_signature( struct(), ProcessHub.Hub.t() ) :: non_neg_integer()
Computes a distribution signature based on the current state that affects distribution.
For deterministic strategies (like ConsistentHashing), this is typically based on the sorted list of cluster nodes. For non-deterministic strategies (like CentralizedLoadBalancer), this may include additional state like load scores.
Used to detect if distribution-relevant state has changed between request creation and execution.
Returns an integer hash that uniquely identifies the current distribution state.
@spec init( struct(), ProcessHub.Hub.t() ) :: struct()
Triggered when coordinator is initialized.
Could be used to perform initialization.