Skip to content
This repository
Browse code

Make vnode check for existing handoff before starting another

Change riak_core_vnode to keep track of the handoff sender pid and not
initiate a new handoff if an existing handoff is already running. In
practice, this is not necessary as the handoff manager ensures that
only one handoff is running per source/target pair. This change is an
optimization to avoid additional work that is potentially expensive on
some backends.
  • Loading branch information...
commit 64512bf425f62dbe399d24c3020c92360459990d 1 parent 6e5ab7c
Joseph Blomstedt jtuple authored

Showing 1 changed file with 26 additions and 16 deletions. Show diff stats Hide diff stats

  1. +26 16 src/riak_core_vnode.erl
42 src/riak_core_vnode.erl
@@ -94,6 +94,7 @@ behaviour_info(_Other) ->
94 94 modstate :: term(),
95 95 forward :: node(),
96 96 handoff_node=none :: none | node(),
  97 + handoff_pid :: pid(),
97 98 pool_pid :: pid() | undefined,
98 99 manager_event_timer :: reference(),
99 100 inactivity_timeout}).
@@ -573,21 +574,29 @@ maybe_handoff(State=#state{modstate={deleted, _}}, _TargetNode) ->
573 574 %% Modstate has been deleted, waiting for unregistered. No handoff.
574 575 continue(State);
575 576 maybe_handoff(State=#state{index=Idx, mod=Mod, modstate=ModState,
576   - handoff_node=HN}, TargetNode) ->
577   - case HN of
578   - none ->
579   - ok;
580   - TargetNode ->
581   - ok;
582   - _ ->
583   - lager:info("~s/~b: handoff request to ~p before "
584   - "finishing handoff to ~p", [Mod, Idx, TargetNode, HN])
585   - end,
586   - case Mod:handoff_starting(TargetNode, ModState) of
587   - {true, NewModState} ->
588   - start_handoff(State#state{modstate=NewModState}, TargetNode);
589   - {false, NewModState} ->
590   - continue(State, NewModState)
  577 + handoff_node=HN, handoff_pid=HPid}, TargetNode) ->
  578 + ExistingHO = is_pid(HPid) andalso is_process_alive(HPid),
  579 + ValidHN = case HN of
  580 + none ->
  581 + true;
  582 + TargetNode ->
  583 + not ExistingHO;
  584 + _ ->
  585 + lager:info("~s/~b: handoff request to ~p before "
  586 + "finishing handoff to ~p",
  587 + [Mod, Idx, TargetNode, HN]),
  588 + not ExistingHO
  589 + end,
  590 + case ValidHN of
  591 + true ->
  592 + case Mod:handoff_starting(TargetNode, ModState) of
  593 + {true, NewModState} ->
  594 + start_handoff(State#state{modstate=NewModState}, TargetNode);
  595 + {false, NewModState} ->
  596 + continue(State, NewModState)
  597 + end;
  598 + false ->
  599 + continue(State)
591 600 end.
592 601
593 602 start_handoff(State=#state{index=Idx, mod=Mod, modstate=ModState}, TargetNode) ->
@@ -597,8 +606,9 @@ start_handoff(State=#state{index=Idx, mod=Mod, modstate=ModState}, TargetNode) -
597 606 handoff_node=TargetNode});
598 607 {false, NewModState} ->
599 608 case riak_core_handoff_manager:add_outbound(Mod,Idx,TargetNode,self()) of
600   - {ok,_Pid} ->
  609 + {ok, Pid} ->
601 610 NewState = State#state{modstate=NewModState,
  611 + handoff_pid=Pid,
602 612 handoff_node=TargetNode},
603 613 continue(NewState);
604 614 {error,_Reason} ->

0 comments on commit 64512bf

Please sign in to comment.
Something went wrong with that request. Please try again.