ExMCP.Transport.Beam.PartitionDetector (ex_mcp v0.9.2)
View SourceNetwork partition detection and healing for BEAM transport clustering.
Monitors cluster connectivity and detects network partitions (split-brain scenarios). When partitions are detected, applies configured merge strategies to reconcile conflicting service registrations.
Partition Detection Methods
- Node Monitoring: Monitor BEAM node connections
- Heartbeat: Regular heartbeat messages between cluster members
- Service Registry Comparison: Compare service states across nodes
- Clock Synchronization: Detect time drift that may indicate partitions
Merge Strategies
:last_writer_wins- Keep services with most recent timestamps:first_writer_wins- Keep services with earliest timestamps:manual- Require manual intervention to resolve conflicts
Example Usage
{:ok, detector} = PartitionDetector.start_link(%{
cluster: cluster_pid,
detection_interval: 10000,
merge_strategy: :last_writer_wins,
partition_threshold: 3
})
Summary
Functions
Returns a specification to start this module under a supervisor.
Manually triggers partition detection.
Gets current partition status.
Gets partition detector statistics.
Manually heals a detected partition.
Simulates a network partition for testing purposes.
Starts the partition detector with the given configuration.
Stops the partition detector.
Updates the merge strategy.
Types
@type config() :: %{ cluster: GenServer.server(), registry: GenServer.server(), detection_interval: non_neg_integer(), merge_strategy: merge_strategy(), partition_threshold: non_neg_integer(), heartbeat_timeout: non_neg_integer() }
@type merge_strategy() :: :last_writer_wins | :first_writer_wins | :manual
@type partition_state() :: :normal | :partitioned | :healing
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec detect_partitions(GenServer.server()) :: {:ok, partition_state()} | {:error, term()}
Manually triggers partition detection.
@spec get_partition_status(GenServer.server()) :: {:ok, partition_state()}
Gets current partition status.
@spec get_stats(GenServer.server()) :: {:ok, map()}
Gets partition detector statistics.
@spec heal_partition(GenServer.server()) :: :ok | {:error, term()}
Manually heals a detected partition.
@spec simulate_partition(GenServer.server(), [atom()], [atom()]) :: :ok
Simulates a network partition for testing purposes.
@spec start_link(config()) :: GenServer.on_start()
Starts the partition detector with the given configuration.
@spec stop(GenServer.server()) :: :ok
Stops the partition detector.
@spec update_merge_strategy(GenServer.server(), merge_strategy()) :: :ok
Updates the merge strategy.