diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2011-08-15 15:28:00 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2011-08-15 15:28:00 +0100 |
commit | ab18c39bec6958439ddc67db3d1345c21df22328 (patch) | |
tree | 75befac1dfb84a57961914f2ba7900761748c38a | |
parent | 2a81033f9b193662c189522045f38fc075877008 (diff) | |
parent | d62f2594106a09e3f809d0b1ae5b7838cd9a5cae (diff) | |
download | rabbitmq-server-ab18c39bec6958439ddc67db3d1345c21df22328.tar.gz |
Merge heads.
-rw-r--r-- | src/mirrored_supervisor.erl | 28 | ||||
-rw-r--r-- | src/mirrored_supervisor_tests.erl | 7 |
2 files changed, 28 insertions, 7 deletions
diff --git a/src/mirrored_supervisor.erl b/src/mirrored_supervisor.erl index ae34e997..eb987189 100644 --- a/src/mirrored_supervisor.erl +++ b/src/mirrored_supervisor.erl @@ -256,9 +256,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). @@ -268,9 +268,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 = {Group, Id}, + _ = '_'}, + %% 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. %%---------------------------------------------------------------------------- @@ -340,6 +353,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 fe06bee1..5a48b222 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 |