Skip to content

Commit

Permalink
Fix vnode master to wait until related service is ready
Browse files Browse the repository at this point in the history
Resolve issue #155
  • Loading branch information
jtuple committed Apr 2, 2012
1 parent 67aaf78 commit a73ced8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/riak_core_vnode_master.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
-module(riak_core_vnode_master).
-include("riak_core_vnode.hrl").
-behaviour(gen_server).
-export([start_link/1, start_link/2, get_vnode_pid/2,
-export([start_link/1, start_link/2, start_link/3, get_vnode_pid/2,
start_vnode/2, command/3, command/4, sync_command/3,
coverage/5,
command_return_vnode/4,
Expand All @@ -50,9 +50,12 @@ start_link(VNodeMod) ->
start_link(VNodeMod, undefined).

start_link(VNodeMod, LegacyMod) ->
start_link(VNodeMod, LegacyMod, undefined).

start_link(VNodeMod, LegacyMod, Service) ->
RegName = reg_name(VNodeMod),
gen_server:start_link({local, RegName}, ?MODULE,
[VNodeMod,LegacyMod,RegName], []).
[Service,VNodeMod,LegacyMod,RegName], []).

start_vnode(Index, VNodeMod) ->
riak_core_vnode_manager:start_vnode(Index, VNodeMod).
Expand Down Expand Up @@ -152,7 +155,8 @@ all_nodes(VNodeMod) ->
[Pid || {_Mod, _Idx, Pid} <- VNodes].

%% @private
init([VNodeMod, LegacyMod, _RegName]) ->
init([Service, VNodeMod, LegacyMod, _RegName]) ->
gen_server:cast(self(), {wait_for_service, Service}),
{ok, #state{idxtab=undefined,
vnode_mod=VNodeMod,
legacy=LegacyMod}}.
Expand All @@ -178,6 +182,15 @@ do_proxy_cast({VMaster, Node}, Req=?COVERAGE_REQ{index=Idx}) ->
do_proxy_cast({VMaster, Node}, Other) ->
gen_server:cast({VMaster, Node}, Other).

handle_cast({wait_for_service, Service}, State) ->
case Service of
undefined ->
ok;
_ ->
lager:debug("Waiting for service: ~p", [Service]),
riak_core:wait_for_service(Service)
end,
{noreply, State};
handle_cast(Req=?VNODE_REQ{index=Idx}, State=#state{vnode_mod=Mod}) ->
Proxy = riak_core_vnode_proxy:reg_name(Mod, Idx),
gen_fsm:send_event(Proxy, Req),
Expand Down
1 change: 1 addition & 0 deletions src/riak_core_vnode_proxy_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ stop_proxy(Mod, Index) ->
ok.

start_proxies(Mod) ->
lager:debug("Starting vnode proxies for: ~p", [Mod]),
Indices = get_indices(),
[start_proxy(Mod, Index) || Index <- Indices],
ok.
Expand Down

0 comments on commit a73ced8

Please sign in to comment.