summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2011-08-15 15:24:18 +0100
committerSimon MacMullen <simon@rabbitmq.com>2011-08-15 15:24:18 +0100
commitd4f7f81de7d5c48335d92df270787d474decc2b3 (patch)
tree82f97015282beef17d1fcfb59b52bc4ff20200e7
parentb18c4c95c5d1bc03756e2eb27d416f2711acbbe3 (diff)
downloadrabbitmq-server-git-d4f7f81de7d5c48335d92df270787d474decc2b3.tar.gz
Make delete / restart / terminate work groupwide.
-rw-r--r--src/mirrored_supervisor.erl28
-rw-r--r--src/mirrored_supervisor_tests.erl7
2 files changed, 28 insertions, 7 deletions
diff --git a/src/mirrored_supervisor.erl b/src/mirrored_supervisor.erl
index 721882e0a0..71bf4f2cd6 100644
--- a/src/mirrored_supervisor.erl
+++ b/src/mirrored_supervisor.erl
@@ -255,9 +255,9 @@ init(Mod, Args) ->
end.
start_child(Sup, ChildSpec) -> call(Sup, {start_child, ChildSpec}).
-delete_child(Sup, Name) -> call(Sup, {delete_child, Name}).
-restart_child(Sup, Name) -> call(Sup, {msg, restart_child, [Name]}).
-terminate_child(Sup, Name) -> call(Sup, {msg, terminate_child, [Name]}).
+delete_child(Sup, Id) -> find_call(Sup, Id, {delete_child, Id}).
+restart_child(Sup, Id) -> find_call(Sup, Id, {msg, restart_child, [Id]}).
+terminate_child(Sup, Id) -> find_call(Sup, Id, {msg, terminate_child, [Id]}).
which_children(Sup) -> ?SUPERVISOR:which_children(child(Sup, delegate)).
check_childspecs(Specs) -> ?SUPERVISOR:check_childspecs(Specs).
@@ -267,9 +267,22 @@ behaviour_info(_Other) -> undefined.
call(Sup, Msg) ->
?GEN_SERVER:call(child(Sup, mirroring), Msg, infinity).
-child(Sup, Name) ->
- [Pid] = [Pid || {Name1, Pid, _, _} <- ?SUPERVISOR:which_children(Sup),
- Name1 =:= Name],
+find_call(Sup, Id, Msg) ->
+ Group = call(Sup, group),
+ MatchHead = #mirrored_sup_childspec{mirroring_pid = '$1',
+ key = {Id, Group},
+ _ = '_'},
+ %% If we did this inside a tx we could still have failover
+ %% immediately after the tx - we can't be 100% here. So we may as
+ %% well direct_select.
+ case mnesia:dirty_select(?TABLE, [{MatchHead, [], ['$1']}]) of
+ [Mirror] -> ?GEN_SERVER:call(Mirror, Msg, infinity);
+ [] -> {error, not_found}
+ end.
+
+child(Sup, Id) ->
+ [Pid] = [Pid || {Id1, Pid, _, _} <- ?SUPERVISOR:which_children(Sup),
+ Id1 =:= Id],
Pid.
%%----------------------------------------------------------------------------
@@ -339,6 +352,9 @@ handle_call({msg, F, A}, _From, State = #state{delegate = Delegate}) ->
handle_call(delegate_supervisor, _From, State = #state{delegate = Delegate}) ->
{reply, Delegate, State};
+handle_call(group, _From, State = #state{group = Group}) ->
+ {reply, Group, State};
+
handle_call(Msg, _From, State) ->
{stop, {unexpected_call, Msg}, State}.
diff --git a/src/mirrored_supervisor_tests.erl b/src/mirrored_supervisor_tests.erl
index fe06bee1c6..5a48b2221c 100644
--- a/src/mirrored_supervisor_tests.erl
+++ b/src/mirrored_supervisor_tests.erl
@@ -89,7 +89,12 @@ test_delete_restart() ->
ok = ?MS:terminate_child(b, worker),
{ok, Pid3} = ?MS:restart_child(b, worker),
Pid3 = pid_of(worker),
- false = (Pid2 =:= Pid3)
+ false = (Pid2 =:= Pid3),
+ %% Not the same supervisor as the worker is on
+ ok = ?MS:terminate_child(a, worker),
+ ok = ?MS:delete_child(a, worker),
+ {ok, Pid4} = ?MS:start_child(a, S),
+ false = (Pid3 =:= Pid4)
end, [a, b]).
%% Not all the members of the group should actually do the failover