Skip to content
This repository

Switch to an RPC call (with timeout) to start remote put fsm on preflist node. #301

Merged
merged 1 commit into from almost 2 years ago

3 participants

Jeffrey Massung Jon Meredith Sean Cribbs
Jeffrey Massung

Fixes #300

Jon Meredith
Owner

Code looks good - will test independently.

Jon Meredith
Owner

+1 merge - managed to provoke errors during testing.


Shell got [{26,{error,{coord_handoff_failed,nodedown}}},
           {25,{error,{coord_handoff_failed,timeout}}},
           {24,{error,{coord_handoff_failed,timeout}}},
Sean Cribbs
Collaborator

Not sure why this was never merged.

Sean Cribbs seancribbs merged commit 4b9d0b6 into from May 23, 2012
Sean Cribbs seancribbs closed this May 23, 2012
Jon Meredith
Owner

I think it was merged against the 1.1 series - interesting 1.1 hadn't been merged to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 09, 2012
Jeffrey Massung Using an rpc:call to start the put_fsm on a preflist node - with a ti…
…meout - to fix issue #300.
3dc718d
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 14 additions and 13 deletions. Show diff stats Hide diff stats

  1. 27  src/riak_kv_put_fsm.erl
27  src/riak_kv_put_fsm.erl
@@ -133,7 +133,7 @@ start_link(From, Object, PutOptions) ->
133 133
 %% bkey - Bucket / Key
134 134
 %% bucket_props - bucket properties
135 135
 %% preflist2 - [{{Idx,Node},primary|fallback}] preference list
136  
-%% 
  136
+%%
137 137
 %% As test, but linked to the caller
138 138
 test_link(From, Object, PutOptions, StateProps) ->
139 139
     gen_fsm:start_link(?MODULE, {test, [From, Object, PutOptions], StateProps}, []).
@@ -148,7 +148,7 @@ test_link(From, Object, PutOptions, StateProps) ->
148 148
 %% @private
149 149
 init([From, RObj, Options]) ->
150 150
     StateData = add_timing(prepare, #state{from = From,
151  
-                                           robj = RObj, 
  151
+                                           robj = RObj,
152 152
                                            options = Options}),
153 153
     {ok, prepare, StateData, 0};
154 154
 init({test, Args, StateProps}) ->
@@ -190,11 +190,12 @@ prepare(timeout, StateData0 = #state{from = From, robj = RObj,
190 190
             %% This node is not in the preference list
191 191
             %% forward on to the first node
192 192
             [{{_Idx, CoordNode},_Type}|_] = Preflist2,
193  
-            case riak_kv_put_fsm_sup:start_put_fsm(CoordNode, [From, RObj, Options]) of
  193
+            Timeout = get_option(timeout, Options, ?DEFAULT_TIMEOUT),
  194
+            case rpc:call(CoordNode,riak_kv_put_fsm_sup,start_put_fsm,[CoordNode,[From,RObj,Options]],Timeout) of
194 195
                 {ok, _Pid} ->
195 196
                     riak_kv_stat:update(coord_redir),
196 197
                     {stop, normal, StateData0};
197  
-                {error, Reason} ->
  198
+                {_, Reason} -> % {error,_} or {badrpc,_}
198 199
                     lager:error("Unable to forward put for ~p to ~p - ~p\n",
199 200
                                 [BKey, CoordNode, Reason]),
200 201
                     process_reply({error, {coord_handoff_failed, Reason}}, StateData0)
@@ -353,7 +354,7 @@ waiting_local_vnode(Result, StateData = #state{putcore = PutCore}) ->
353 354
     end.
354 355
 
355 356
 %% @private
356  
-%% Send the put requests to any remote nodes if necessary and decided if 
  357
+%% Send the put requests to any remote nodes if necessary and decided if
357 358
 %% enough responses have been received yet (i.e. if W/DW=1)
358 359
 %% N.B. Not actually a state - here in the source to make reading the flow easier
359 360
 execute_remote(StateData=#state{robj=RObj, req_id = ReqId,
@@ -466,7 +467,7 @@ process_reply(Reply, StateData = #state{postcommit = PostCommit,
466 467
                      [] ->
467 468
                          StateData1;
468 469
                      _ ->
469  
-                         %% If postcommits defined, calculate final object 
  470
+                         %% If postcommits defined, calculate final object
470 471
                          %% before any replies received after responding to
471 472
                          %% the client for a consistent view.
472 473
                          {_, UpdPutCore} = riak_kv_put_core:final(PutCore),
@@ -506,7 +507,7 @@ handle_options([{update_last_modified, true}|T], State = #state{robj = RObj}) ->
506 507
     handle_options(T, State#state{robj = update_last_modified(RObj)});
507 508
 handle_options([{returnbody, true}|T], State) ->
508 509
     VnodeOpts = [{returnbody, true} | State#state.vnode_options],
509  
-    %% Force DW>0 if requesting return body to ensure the dw event 
  510
+    %% Force DW>0 if requesting return body to ensure the dw event
510 511
     %% returned by the vnode includes the object.
511 512
     handle_options(T, State#state{vnode_options=VnodeOpts,
512 513
                                   dw=erlang:max(1,State#state.dw),
@@ -515,7 +516,7 @@ handle_options([{returnbody, false}|T], State = #state{postcommit = Postcommit})
515 516
     case Postcommit of
516 517
         [] ->
517 518
             handle_options(T, State#state{returnbody=false});
518  
-            
  519
+
519 520
         _ ->
520 521
             %% We have post-commit hooks, we'll need to get the body back
521 522
             %% from the vnode, even though we don't plan to return that to the
@@ -530,7 +531,7 @@ handle_options([{_,_}|T], State) -> handle_options(T, State).
530 531
 
531 532
 init_putcore(State = #state{n = N, w = W, dw = DW, allowmult = AllowMult,
532 533
                             returnbody = ReturnBody}) ->
533  
-    PutCore = riak_kv_put_core:init(N, W, DW, 
  534
+    PutCore = riak_kv_put_core:init(N, W, DW,
534 535
                                     N-W+1,   % cannot ever get W replies
535 536
                                     N-DW+1,  % cannot ever get DW replies
536 537
                                     AllowMult,
@@ -570,7 +571,7 @@ update_last_modified(RObj) ->
570 571
     %% be an external interface concern and are only used for sibling selection
571 572
     %% and if-modified type tests so they could be generated on retrieval instead.
572 573
     %% This changes from being a hash on the value to a likely-to-be-unique value
573  
-    %% which should serve the same purpose.  It was possible to generate two 
  574
+    %% which should serve the same purpose.  It was possible to generate two
574 575
     %% objects with the same vclock on 0.14.2 if the same clientid was used in
575 576
     %% the same second.  It can be revisited post-1.0.0.
576 577
     Now = erlang:now(),
@@ -701,7 +702,7 @@ get_hooks(HookType, BucketProps) ->
701 702
         Hooks when is_list(Hooks) ->
702 703
             Hooks
703 704
     end.
704  
-   
  705
+
705 706
 get_option(Name, Options, Default) ->
706 707
     proplists:get_value(Name, Options, Default).
707 708
 
@@ -750,7 +751,7 @@ default_details() ->
750 751
 add_timing(Stage, State = #state{timing = Timing}) ->
751 752
     State#state{timing = [{Stage, os:timestamp()} | Timing]}.
752 753
 
753  
-%% Calc timing information - stored as {Stage, StageStart} in reverse order. 
  754
+%% Calc timing information - stored as {Stage, StageStart} in reverse order.
754 755
 %% ResponseUsecs is calculated as time from reply to start.
755 756
 calc_timing([{Stage, Now} | Timing]) ->
756 757
     ReplyNow = case Stage of
@@ -764,7 +765,7 @@ calc_timing([{Stage, Now} | Timing]) ->
764 765
 %% Each timing stage has start time.
765 766
 calc_timing([], StageEnd, ReplyNow, Stages) ->
766 767
     %% StageEnd is prepare time
767  
-    {timer:now_diff(ReplyNow, StageEnd), Stages}; 
  768
+    {timer:now_diff(ReplyNow, StageEnd), Stages};
768 769
 calc_timing([{reply, ReplyNow}|_]=Timing, StageEnd, undefined, Stages) ->
769 770
     %% Populate ReplyNow then handle normally.
770 771
     calc_timing(Timing, StageEnd, ReplyNow, Stages);
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.