Skip to content

Commit

Permalink
Add callback annotations to riak_core_vnode
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Cribbs committed Mar 3, 2014
1 parent 3c00369 commit 74f88d3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 20 deletions.
3 changes: 3 additions & 0 deletions include/riak_core_vnode.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@
-define(VNODE_REQ, #riak_vnode_req_v1).
-define(COVERAGE_REQ, #riak_coverage_req_v1).
-define(FOLD_REQ, #riak_core_fold_req_v2).

-type handoff_type() :: resize_transfer | ownership_transfer | hinted_handoff.
-type handoff_dest() :: {handoff_type(), {partition(), node()}}.
81 changes: 61 additions & 20 deletions src/riak_core_vnode.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
-module('riak_core_vnode').
-behaviour(gen_fsm).
-include("riak_core_vnode.hrl").
-export([behaviour_info/1]).
-export([start_link/3,
start_link/4,
wait_for_init/1,
Expand Down Expand Up @@ -64,23 +63,65 @@
(R == normal orelse R == shutdown orelse
(is_tuple(R) andalso element(1,R) == shutdown))).

-spec behaviour_info(atom()) -> 'undefined' | [{atom(), arity()}].
behaviour_info(callbacks) ->
[{init,1},
{handle_command,3},
{handle_coverage,4},
{handle_exit,3},
{handoff_starting,2},
{handoff_cancelled,1},
{handoff_finished,2},
{handle_handoff_command,3},
{handle_handoff_data,2},
{encode_handoff_item,2},
{is_empty,1},
{terminate,2},
{delete,1}];
behaviour_info(_Other) ->
undefined.
-export_type([vnode_opt/0, pool_opt/0]).

-type vnode_opt() :: pool_opt().
-type pool_opt() :: {pool, WorkerModule::module(), PoolSize::pos_integer(), WorkerArgs::[term()]}.

-callback init([partition()]) ->
{ok, ModState::term()} |
{ok, ModState::term(), [vnode_opt()]} |
{error, Reason::term()}.

-callback handle_command(Request::term(), Sender::sender(), ModState::term()) ->
continue |
{reply, Reply::term(), NewModState::term()} |
{noreply, NewModState::term()} |
{async, Work::function(), From::sender(), NewModState::term()} |
{stop, Reason::term(), NewModState::term()}.

-callback handle_coverage(Request::term(), keyspaces(), Sender::sender(), ModState::term()) ->
continue |
{reply, Reply::term(), NewModState::term()} |
{noreply, NewModState::term()} |
{async, Work::function(), From::sender(), NewModState::term()} |
{stop, Reason::term(), NewModState::term()}.

-callback handle_exit(pid(), Reason::term(), ModState::term()) ->
{noreply, NewModState::term()} |
{stop, Reason::term(), NewModState::term()}.

-callback handoff_starting(handoff_dest(), ModState::term()) ->
{boolean(), NewModState::term()}.

-callback handoff_cancelled(ModState::term()) ->
{ok, NewModState::term()}.

-callback handoff_finished(handoff_dest(), ModState::term()) ->
{ok, NewModState::term()}.

-callback handle_handoff_command(Request::term(), Sender::sender(), ModState::term()) ->
{reply, Reply::term(), NewModState::term()} |
{noreply, NewModState::term()} |
{async, Work::function(), From::sender(), NewModState::term()} |
{forward, NewModState::term()} |
{drop, NewModState::term()} |
{stop, Reason::term(), NewModState::term()}.

-callback handle_handoff_data(binary(), ModState::term()) ->
{reply, ok | {error, Reason::term()}, NewModState::term()}.

-callback encode_handoff_item(Key::term(), Value::term()) ->
corrupted | binary().

-callback is_empty(ModState::term()) ->
{boolean(), NewModState::term()} |
{false, Size::pos_integer(), NewModState::term()}.

-callback terminate(Reason::term(), ModState::term()) ->
ok.

-callback delete(ModState::term()) -> {ok, NewModState::term()}.

%% handle_exit/3 is an optional behaviour callback that can be implemented.
%% It will be called in the case that a process that is linked to the vnode
Expand Down Expand Up @@ -118,7 +159,7 @@ behaviour_info(_Other) ->
pool_pid :: pid() | undefined,
pool_config :: tuple() | undefined,
manager_event_timer :: reference(),
inactivity_timeout :: non_neg_integer()
inactivity_timeout :: non_neg_integer()
}).

start_link(Mod, Index, Forward) ->
Expand Down Expand Up @@ -849,7 +890,7 @@ terminate(Reason, _StateName, #state{mod=Mod, modstate=ModState,
ok
end
catch C:T ->
lager:error("Error while shutting down vnode worker pool ~p:~p trace : ~p",
lager:error("Error while shutting down vnode worker pool ~p:~p trace : ~p",
[C, T, erlang:get_stacktrace()])
after
case ModState of
Expand Down

0 comments on commit 74f88d3

Please sign in to comment.