Skip to content

Commit

Permalink
Change startup so that the application and vnodes start before the se…
Browse files Browse the repository at this point in the history
…rvice is declared as 'up'.

AZ1011
  • Loading branch information
rustyio committed Dec 14, 2011
1 parent e6de7ca commit b7185ad
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/riak_core_ring_handler.erl
Expand Up @@ -114,16 +114,30 @@ ensure_vnodes_started({App,Mod}, Ring) ->
RegName = list_to_atom(
"riak_core_ring_handler_ensure_"
++ atom_to_list(Mod)),
try register(RegName, self())
try erlang:register(RegName, self())
catch error:badarg ->
exit(normal)
end,
wait_for_app(App, 100, 100),
[Mod:start_vnode(I) || I <- Startable],
exit(normal)

%% Let the app finish starting...
case wait_for_app(App, 1000, 100) of
ok ->
%% Start the vnodes.
[Mod:start_vnode(I) || I <- Startable],

%% Mark the service as up.
SupName = list_to_atom(atom_to_list(App) ++ "_sup"),
SupPid = erlang:whereis(SupName),
riak_core_node_watcher:service_up(App, SupPid),
exit(normal);
{error, Reason} ->
lager:critical("Failed to start application: ~p", [App]),
throw({error, Reason})
end
end),
Startable.


startable_vnodes(Mod, Ring) ->
AllMembers = riak_core_ring:all_members(Ring),
case {length(AllMembers), hd(AllMembers) =:= node()} of
Expand All @@ -145,8 +159,8 @@ startable_vnodes(Mod, Ring) ->
end
end.

wait_for_app(_, 0, _) ->
bummer;
wait_for_app(App, 0, _) ->
{error, {timeout, App}};
wait_for_app(App, Count, Sleep) ->
case lists:keymember(App, 1, application:which_applications()) of
true ->
Expand Down

0 comments on commit b7185ad

Please sign in to comment.