Fix leader election conflict resolution for distributed nodes
The previous conflict resolution tried to call Process.info/2 on remote PIDs, which doesn't work. Changed to use node name comparison for deterministic leader selection across the cluster. This ensures only one leader is elected when nodes join the cluster. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
777acc2700
commit
9212088beb
1 changed files with 10 additions and 6 deletions
|
|
@ -85,15 +85,19 @@ defmodule Aprsme.Cluster.LeaderElection do
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
# Conflict resolution - prefer the process that's been running longer
|
# Conflict resolution - prefer the process on the lexicographically lower node
|
||||||
defp resolve_conflict(_name, pid1, pid2) do
|
defp resolve_conflict(_name, pid1, pid2) do
|
||||||
info1 = Process.info(pid1, [:registered_name, :current_function])
|
node1 = node(pid1)
|
||||||
info2 = Process.info(pid2, [:registered_name, :current_function])
|
node2 = node(pid2)
|
||||||
|
|
||||||
Logger.debug("Resolving leader conflict between #{inspect(info1)} and #{inspect(info2)}")
|
Logger.info("Resolving leader conflict between #{node1} and #{node2}")
|
||||||
|
|
||||||
# Keep the first registered process
|
# Choose based on node name ordering for deterministic results
|
||||||
pid1
|
if node1 <= node2 do
|
||||||
|
pid1
|
||||||
|
else
|
||||||
|
pid2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp notify_leadership_change(became_leader) do
|
defp notify_leadership_change(became_leader) do
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue