From a52b33d4467d590dc2adcdaf89c3c56a19116c10 Mon Sep 17 00:00:00 2001 From: Jon Meredith Date: Mon, 26 Sep 2011 22:04:47 -0600 Subject: [PATCH] Perform final sync once all handoff data has been sent. The new cluster membership code switched to forwarding once handoff is complete. Without this change the vnode starts forwarding while the new owner is still processing buffered TCP data. --- src/riak_core_handoff_sender.erl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/riak_core_handoff_sender.erl b/src/riak_core_handoff_sender.erl index 6a7cf1aac..b319c3eb5 100644 --- a/src/riak_core_handoff_sender.erl +++ b/src/riak_core_handoff_sender.erl @@ -70,6 +70,16 @@ start_fold(TargetNode, Module, Partition, ParentPid, SslOpts) -> foldfun=fun visit_item/3, acc0={Socket,ParentPid,Module,TcpMod,0,0,ok}}, VMaster, infinity), + %% One last sync to make sure the message has been received. + %% post-0.14 vnodes switch to handoff to forwarding immediately + %% so handoff_complete can only be sent once all of the data is + %% written. handle_handoff_data is a sync call, so once + %% we receive the sync the remote side will be up to date. + lager:debug("~p ~p Sending final sync", [Partition, Module]), + ok = TcpMod:send(Socket, <>), + {ok,[?PT_MSG_SYNC|<<"sync">>]} = TcpMod:recv(Socket, 0), + lager:debug("~p ~p Final sync received", [Partition, Module]), + EndFoldTime = now(), FoldTimeDiff = timer:now_diff(EndFoldTime, StartFoldTime) / 1000000, case ErrStatus of