Skip to content

Commit

Permalink
Hardcode :restart handoff strategy
Browse files Browse the repository at this point in the history
GenServer.call was blocking the process in high load situations when a
pod died.  All our processes use the :restart strategy anyways, so just
hardcode it in
  • Loading branch information
darrenclark committed Aug 28, 2019
1 parent 0307ddd commit 7dd08d6
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions lib/swarm/tracker/tracker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -856,25 +856,27 @@ defmodule Swarm.Tracker do
debug("#{inspect(pid)} belongs on #{other_node}")
# This process needs to be moved to the new node
try do
case GenServer.call(pid, {:swarm, :begin_handoff}) do
:ignore ->
debug("#{inspect(name)} has requested to be ignored")
state

{:resume, handoff_state} ->
debug("#{inspect(name)} has requested to be resumed")
{:ok, new_state} = remove_registration(obj, state)
send(pid, {:swarm, :die})
debug("sending handoff for #{inspect(name)} to #{other_node}")

GenStateMachine.cast(
{__MODULE__, other_node},
{:handoff, self(), {name, meta, handoff_state, Clock.peek(new_state.clock)}}
)

new_state

:restart ->
# All of our processes are meant to work with :restart, so skip the GenServer.call

# case GenServer.call(pid, {:swarm, :begin_handoff}) do
# :ignore ->
# debug("#{inspect(name)} has requested to be ignored")
# state
#
# {:resume, handoff_state} ->
# debug("#{inspect(name)} has requested to be resumed")
# {:ok, new_state} = remove_registration(obj, state)
# send(pid, {:swarm, :die})
# debug("sending handoff for #{inspect(name)} to #{other_node}")
#
# GenStateMachine.cast(
# {__MODULE__, other_node},
# {:handoff, self(), {name, meta, handoff_state, Clock.peek(new_state.clock)}}
# )
#
# new_state

# :restart ->
debug("#{inspect(name)} has requested to be restarted")
{:ok, new_state} = remove_registration(obj, state)
send(pid, {:swarm, :die})
Expand All @@ -883,7 +885,7 @@ defmodule Swarm.Tracker do
:keep_state_and_data -> new_state
{:keep_state, new_state} -> new_state
end
end
# end
catch
_, err ->
warn("handoff failed for #{inspect(name)}: #{inspect(err)}")
Expand Down

0 comments on commit 7dd08d6

Please sign in to comment.