Skip to content

Commit

Permalink
fixed handling of janitor aborting
Browse files Browse the repository at this point in the history
Change-Id: I393dfa79c5a39b85683dfde31233804b85418869
Reviewed-on: http://review.northscale.com/3186
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Sean Lynch <seanl@literati.org>
  • Loading branch information
Aliaksey Kandratsenka authored and Sean Lynch committed Oct 11, 2010
1 parent e5e1e3f commit ca2e585
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ns_orchestrator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ handle_info(janitor, idle, #idle_state{remaining_buckets=[]} = State) ->
handle_info(janitor, idle, #idle_state{remaining_buckets=Buckets}) ->
Bucket = hd(Buckets),
Pid = proc_lib:spawn_link(ns_janitor, cleanup, [Bucket]),
%% NOTE: Bucket will be popped from Buckets when janitor run will
%% complete successfully
{next_state, janitor_running, #janitor_state{remaining_buckets=Buckets,
pid = Pid}};
handle_info(janitor, StateName, StateData) ->
Expand Down Expand Up @@ -258,11 +260,15 @@ idle(stop_rebalance, _From, State) ->
janitor_running(rebalance_progress, _From, State) ->
{reply, not_running, janitor_running, State};
janitor_running(Msg, From, #janitor_state{pid=Pid} = State) ->
%% when handling some call while janitor is running we kill janitor
exit(Pid, shutdown),
NextState = receive
{'EXIT', Pid, _} = DeathMsg ->
handle_info(DeathMsg, janitor_running, State)
end,
%% than await that it's dead and handle it's death message
{next_state, idle, NextState}
= receive
{'EXIT', Pid, _} = DeathMsg ->
handle_info(DeathMsg, janitor_running, State)
end,
%% and than handle original call in idle state
idle(Msg, From, NextState).

%% Asynchronous rebalancing events
Expand Down

0 comments on commit ca2e585

Please sign in to comment.