Skip to content
Browse files

expose the pid for the vnode that just received the command

command_return_vnode returns {ok, VnodePid} instead of just 'ok', to
allow the caller to monitor the vnode that is handling its request
  • Loading branch information...
1 parent 8dba0e1 commit a5b1766b15a667cf4412ee221d7a87fdce6641a9 Bryan Fink committed May 26, 2011
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/riak_core_vnode_master.erl
View
12 src/riak_core_vnode_master.erl
@@ -27,6 +27,7 @@
-behaviour(gen_server).
-export([start_link/1, start_link/2, get_vnode_pid/2,
start_vnode/2, command/3, command/4, sync_command/3,
+ command_return_vnode/4,
sync_command/4,
sync_spawn_command/3, make_request/3,
all_nodes/1, reg_name/1]).
@@ -73,6 +74,13 @@ command([{Index,Node}|Rest], Msg, Sender, VMaster) ->
command({Index,Node}, Msg, Sender, VMaster) ->
gen_server:cast({VMaster, Node}, make_request(Msg, Sender, Index)).
+%% Send the command to an individual Index/Node combination, but also
+%% return the pid for the vnode handling the request, as `{ok,
+%% VnodePid}'.
+command_return_vnode({Index,Node}, Msg, Sender, VMaster) ->
+ gen_server:call({VMaster, Node},
+ {return_vnode, make_request(Msg, Sender, Index)}).
+
%% Send a synchronous command to an individual Index/Node combination.
%% Will not return until the vnode has returned
sync_command(IndexNode, Msg, VMaster) ->
@@ -156,6 +164,10 @@ handle_cast(Other, State=#state{legacy=Legacy}) when Legacy =/= undefined ->
{noreply, State}
end.
+handle_call({return_vnode, Req=?VNODE_REQ{index=Idx}}, _From, State) ->
+ Pid = get_vnode(Idx, State),
+ gen_fsm:send_event(Pid, Req),
+ {reply, {ok, Pid}, State};
handle_call(Req=?VNODE_REQ{index=Idx, sender={server, undefined, undefined}}, From, State) ->
Pid = get_vnode(Idx, State),
gen_fsm:send_event(Pid, Req?VNODE_REQ{sender={server, undefined, From}}),

0 comments on commit a5b1766

Please sign in to comment.
Something went wrong with that request. Please try again.