View Source ProcessHub.Strategy.Migration.ColdSwap (ProcessHub v0.5.0-beta)
The cold swap migration strategy implements the ProcessHub.Strategy.Migration.Base protocol.
It provides a migration strategy where the local process is terminated before starting it on
the remote node.
Cold swap is a safe strategy if we want to ensure that the child process is not running on multiple nodes at the same time.
This is the default strategy for process migration.
State Handover
When handover: true is set, ColdSwap will:
- Query state from local processes before termination
- Store states in ETS with TTL
- Terminate local processes
- Send start requests to new nodes
- When new processes are registered, deliver stored state via hook
To use state handover, your GenServer must use ProcessHub.Strategy.Migration.ColdSwap:
defmodule MyServer do
use GenServer
use ProcessHub.Strategy.Migration.ColdSwap
# Optionally override these callbacks:
# def prepare_handover_state(state), do: state
# def alter_handover_state(_current, handover), do: handover
endState Handover with Replication
State handover is not supported when using the
ProcessHub.Strategy.Redundancy.Replicationstrategy. With replication, multiple instances of a process run across the cluster, making state handover semantics undefined. If you attempt to usehandover: truewith replication, the hub will fail to start with{:error, {:invalid_config, :handover_with_replication_not_supported}}.
Summary
Functions
Options
Callback executed on the originating node to deliver stored handover states.
Post-action callback executed on the target node after children are started.
Types
@type t() :: %ProcessHub.Strategy.Migration.ColdSwap{ handover: boolean(), state_query_timeout: pos_integer(), state_ttl: pos_integer() }
The cold swap migration struct.
Options:
:handover- Enable state handover before termination (default: false):state_ttl- TTL for stored states in milliseconds (default: 30000):state_query_timeout- Timeout for querying state from dying process (default: 5000)
Functions
Options:
:declare_behaviour- Whentrue(default), declares theProcessHub.Strategy.Migration.HandoverBehaviourbehaviour and provides default implementations. Set tofalsewhen using both HotSwap and ColdSwap macros in the same module to avoid duplicate declarations.
@spec deliver_handover_states(ProcessHub.Hub.t(), node(), [ {ProcessHub.child_id(), pid()} ]) :: :ok
Callback executed on the originating node to deliver stored handover states.
Called via generic :post_action_callback message from the target node.
handle_post_action_state_fetch(hub, results, originating_node, child_ids)
View Source@spec handle_post_action_state_fetch( ProcessHub.Hub.t(), [ProcessHub.Request.Handler.StartChildrenRequest.PostStartData.t()], node(), [ProcessHub.child_id()] ) :: :ok
Post-action callback executed on the target node after children are started.
Sends a generic callback message to the originating node to deliver stored handover states to the newly started processes.