Skip to content

Commit

Permalink
Merge pull request #626 from basho/bugfix/cherrypick/handoff-fold-abo…
Browse files Browse the repository at this point in the history
…rt-early-2.0

Allow handoff sender to abort handoff by throw'ing from fold fun

Reviewed-by: andrewjstone
  • Loading branch information
borshop committed Sep 15, 2014
2 parents 4476cda + 8620dcc commit aa7fb9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/riak_core_handoff_receiver.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ handle_info({tcp_closed,_Socket},State=#state{partition=Partition,count=Count,
lager:info("Handoff receiver for partition ~p exited after processing ~p"
" objects from ~p", [Partition, Count, Peer]),
{stop, normal, State};
handle_info({tcp_error, _Socket, _Reason}, State=#state{partition=Partition,count=Count,
peer=Peer}) ->
handle_info({tcp_error, _Socket, Reason}, State=#state{partition=Partition,count=Count,
peer=Peer}) ->
lager:info("Handoff receiver for partition ~p exited after processing ~p"
" objects from ~p", [Partition, Count, Peer]),
" objects from ~p: TCP error ~p", [Partition, Count, Peer, Reason]),
{stop, normal, State};
handle_info({tcp, Socket, Data}, State) ->
[MsgType|MsgData] = Data,
Expand Down
9 changes: 4 additions & 5 deletions src/riak_core_handoff_sender.erl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ start_fold(TargetNode, Module, {Type, Opts}, ParentPid, SslOpts) ->
VMaster, infinity),

%% Send any straggler entries remaining in the buffer:
AccRecord = send_objects(AccRecord0#ho_acc.item_queue, AccRecord0),
AccRecord = send_objects(AccRecord0#ho_acc.item_queue, AccRecord0),

if AccRecord == {error, vnode_shutdown} ->
?log_info("because the local vnode was shutdown", []),
Expand Down Expand Up @@ -281,11 +281,10 @@ start_fold(TargetNode, Module, {Type, Opts}, ParentPid, SslOpts) ->
gen_fsm:send_event(ParentPid, {handoff_error, Err, Reason})
end.

%% When a tcp error occurs, the ErrStatus argument is set to {error, Reason}.
%% Since we can't abort the fold, this clause is just a no-op.
visit_item(_K, _V, Acc=#ho_acc{error={error, _Reason}}) ->
Acc;
visit_item(K, V, Acc = #ho_acc{ack = _AccSyncThreshold, acksync_threshold = _AccSyncThreshold}) ->
%% When a TCP/SSL error occurs, #ho_acc.error is set to {error, Reason}.
throw(Acc);
visit_item(K, V, Acc = #ho_acc{ack = AccSyncThreshold, acksync_threshold = AccSyncThreshold}) ->
#ho_acc{module=Module,
socket=Sock,
src_target={SrcPartition, TargetPartition},
Expand Down

0 comments on commit aa7fb9e

Please sign in to comment.