Skip to content

Instantly share code, notes, and snippets.

@binarytemple
Created May 26, 2015 14:53
Show Gist options
  • Select an option

  • Save binarytemple/f7729d8266473ed0e080 to your computer and use it in GitHub Desktop.

Select an option

Save binarytemple/f7729d8266473ed0e080 to your computer and use it in GitHub Desktop.
riak.2.put.fsm.code.path

Startup the PUT FSM - code

%% @private
init([From, RObj, Options0, Monitor]) ->
    BKey = {Bucket, Key} = {riak_object:bucket(RObj), riak_object:key(RObj)},
    CoordTimeout = get_put_coordinator_failure_timeout(),

Definition of get_put_coordinator_failure_timeout/0 - code

get_put_coordinator_failure_timeout() ->
    app_helper:get_env(riak_kv, put_coordinator_failure_timeout, 3000).

The spawning process - code

                         MiddleMan = spawn_coordinator_proc(
                                      CoordNode, riak_kv_put_fsm, start_link,
                                      [From,RObj,Options2]),
                        ?DTRACE(Trace, ?C_PUT_FSM_PREPARE, [2],
                                ["prepare", atom2list(CoordNode)]),
                        ok = riak_kv_stat:update(coord_redir),
                        monitor_remote_coordinator(UseAckP, MiddleMan,
                                                   CoordNode, StateData0)

Monitoring for a return value - code

monitor_remote_coordinator(true = _UseAckP, MiddleMan, CoordNode, StateData) ->
    receive
        {ack, CoordNode, now_executing} ->
            {stop, normal, StateData}
    after StateData#state.coordinator_timeout ->
            exit(MiddleMan, kill),
            Bad = StateData#state.bad_coordinators,
            prepare(timeout, StateData#state{bad_coordinators=[CoordNode|Bad]})
    end.

The process state (setup) - code

%% @private
prepare(timeout, StateData0 = #state{from = From, robj = RObj,
                                     bkey = BKey = {Bucket, _Key},
                                     options = Options,
                                     trace = Trace,
                                     bad_coordinators = BadCoordinators}) ->
    {ok, DefaultProps} = application:get_env(riak_core, 
                                             default_bucket_props),
    BucketProps = riak_core_bucket:get_bucket(riak_object:bucket(RObj)),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment