Commits

Anonymous committed b48a7a9 Merge

merge

  • Participants
  • Parent commits 6698ea3, 44e00d2

Comments (0)

Files changed (3)

src/riak_get_fsm.erl

 -export([start/6]).
 -export([init/1, handle_event/3, handle_sync_event/4,
          handle_info/3, terminate/3, code_change/4]).
--export([waiting_vnode_r/2,waiting_read_repair/2]).
+-export([initialize/2,waiting_vnode_r/2,waiting_read_repair/2]).
 
 -record(state, {client :: {pid(), reference()},
                 n :: pos_integer(), 
                 replied_fail :: list(),
                 repair_sent :: list(), 
                 final_obj :: undefined|riak_object:riak_object(),
-                endtime :: pos_integer(), 
+                timeout :: pos_integer(),
+                endtime :: pos_integer(),
                 bkey :: {riak_object:bucket(), riak_object:key()},
                 ring :: riak_ring:riak_ring()
                }).
 
 %% @private
 init([Ring,Bucket,Key,R,Timeout,Client]) ->
+    StateData = #state{client=Client,r=R, timeout=Timeout,
+                       bkey={Bucket,Key}, ring=Ring},
+    {ok,initialize,StateData,0}.
+
+%% @private
+initialize(timeout, StateData0=#state{timeout=Timeout,
+                                      bkey={Bucket,Key}, ring=Ring}) ->
     RealStartTime = riak_util:moment(),
     DocIdx = chash:key_of({Bucket, Key}),
     ReqID = erlang:phash2({random:uniform(), self(), DocIdx, RealStartTime}),
     end,
     riak_eventer:notify(riak_get_fsm, get_fsm_sent,
                                 {ReqID, [{T,S} || {_I,T,S} <- Sent]}),
-    StateData = #state{client=Client,n=N,r=R,allowmult=AllowMult,repair_sent=[],
+    StateData = StateData0#state{n=N,allowmult=AllowMult,repair_sent=[],
                        preflist=Preflist,final_obj=undefined,
                        req_id=ReqID,replied_r=[],replied_fail=[],
                        replied_notfound=[],starttime=riak_util:moment(),
-                       waiting_for=Sent,endtime=Timeout+riak_util:moment(),
-                       bkey={Bucket,Key}, ring=Ring},
-    {ok,waiting_vnode_r,StateData,Timeout}.
+                       waiting_for=Sent,endtime=Timeout+riak_util:moment()},
+    {next_state,waiting_vnode_r,StateData,Timeout}.
 
 waiting_vnode_r({r, {ok, RObj}, Idx, ReqID},
                   StateData=#state{r=R,allowmult=AllowMult,

src/riak_keys_fsm.erl

 -export([start/4]).
 -export([init/1, handle_event/3, handle_sync_event/4,
          handle_info/3, terminate/3, code_change/4]).
--export([waiting_kl/2]).
+-export([initialize/2,waiting_kl/2]).
 
 -record(state, {client :: {pid(), reference()},
                 keys :: [set()],
                 waiting :: [node()],
+                bucket :: riak_object:bucket(),
+                timeout :: pos_integer(),
                 endtime :: pos_integer(),
-                req_id :: pos_integer()
+                req_id :: pos_integer(),
+                ring :: riak_ring:riak_ring()
                }).
 
 start(Ring,Bucket,Timeout,From) ->
 
 %% @private
 init([Ring,Bucket,Timeout,Client]) ->
+    StateData = #state{client=Client, timeout=Timeout,
+                       bucket=Bucket, ring=Ring},
+    {ok,initialize,StateData,0}.
+
+%% @private
+initialize(timeout, StateData0=#state{timeout=Timeout,
+                                      bucket=Bucket, ring=Ring}) ->
     RealStartTime = riak_util:moment(),
     ReqID = erlang:phash2({random:uniform(), self(), Bucket, RealStartTime}),
     riak_eventer:notify(riak_keys_fsm, keys_fsm_start,
               end,
               [],
               NodeList),
-    StateData = #state{waiting=Asked, keys=[], client=Client,
+    StateData = StateData0#state{waiting=Asked, keys=[],
                        endtime=Timeout+riak_util:moment(),
                        req_id=ReqID},
-    {ok, waiting_kl, StateData, Timeout}.
+    {next_state, waiting_kl, StateData, Timeout}.
 
 waiting_kl({kl, Keys, Idx, ReqID},
            StateData=#state{keys=Acc,waiting=Waiting,endtime=End}) ->

src/riak_put_fsm.erl

 -export([start/6]).
 -export([init/1, handle_event/3, handle_sync_event/4,
          handle_info/3, terminate/3, code_change/4]).
--export([waiting_vnode_w/2,waiting_vnode_dw/2]).
+-export([initialize/2,waiting_vnode_w/2,waiting_vnode_dw/2]).
 
 -record(state, {robj :: riak_object:riak_object(), 
                 client :: {pid(), reference()}, 
                 replied_w :: list(), 
                 replied_dw :: list(), 
                 replied_fail :: list(),
+                timeout :: pos_integer(), 
                 endtime :: pos_integer(), 
                 ring :: riak_ring:riak_ring()
                }).
 
 %% @private
 init([Ring,RObj0,W,DW,Timeout,Client]) ->
+    StateData = #state{robj=RObj0, client=Client, w=W, dw=DW,
+                       timeout=Timeout, ring=Ring},
+    {ok,initialize,StateData,0}.
+
+%% @private
+initialize(timeout, StateData0=#state{robj=RObj0, client=Client, w=W, dw=DW, 
+                                                timeout=Timeout, ring=Ring}) ->
     RealStartTime = riak_util:moment(),
     Bucket = riak_object:bucket(RObj0),
     BucketProps = riak_bucket:get_bucket(Bucket, Ring),
     end,
     riak_eventer:notify(riak_put_fsm, put_fsm_sent,
                                 {ReqID, [{T,S} || {_I,T,S} <- Sent]}),
-    StateData = #state{robj=RObj, client=Client, n=N, w=W, dw=DW,
-                       preflist=Preflist, bkey={Bucket,Key}, waiting_for=Sent,
-                       req_id=ReqID, starttime=riak_util:moment(),
-                       replied_w=[], replied_dw=[], replied_fail=[],
-                       endtime=Timeout+riak_util:moment(), ring=Ring},
-    {ok,waiting_vnode_w,StateData,Timeout}.
-
+    StateData = StateData0#state{
+                  robj=RObj, n=N, preflist=Preflist, bkey={Bucket,Key},
+                  waiting_for=Sent, req_id=ReqID, starttime=riak_util:moment(),
+                  replied_w=[], replied_dw=[], replied_fail=[],
+                  endtime=Timeout+riak_util:moment()},
+    {next_state,waiting_vnode_w,StateData,Timeout}.
 
 waiting_vnode_w({w, Idx, ReqID},
                   StateData=#state{w=W,dw=DW,req_id=ReqID,client=Client,