diff options
| author | Matthew Sackman <matthew@rabbitmq.com> | 2010-08-06 17:55:16 +0100 |
|---|---|---|
| committer | Matthew Sackman <matthew@rabbitmq.com> | 2010-08-06 17:55:16 +0100 |
| commit | b73f0e725a82b72b6d8d7bc17b764c46037a8a90 (patch) | |
| tree | 0e7d323bbc8498fd25cce147fc3eda163eb8d3bb | |
| parent | f9d684f8509395e274ab928bc861337cf08dedc7 (diff) | |
| download | rabbitmq-server-git-b73f0e725a82b72b6d8d7bc17b764c46037a8a90.tar.gz | |
Added intrinsic restart type and used it
| -rw-r--r-- | src/rabbit_channel_sup.erl | 8 | ||||
| -rw-r--r-- | src/rabbit_connection_sup.erl | 16 | ||||
| -rw-r--r-- | src/rabbit_heartbeat.erl | 4 | ||||
| -rw-r--r-- | src/rabbit_reader.erl | 25 | ||||
| -rw-r--r-- | src/supervisor2.erl | 19 |
5 files changed, 46 insertions, 26 deletions
diff --git a/src/rabbit_channel_sup.erl b/src/rabbit_channel_sup.erl index 17e1446dcf..e4dcbae1ea 100644 --- a/src/rabbit_channel_sup.erl +++ b/src/rabbit_channel_sup.erl @@ -61,23 +61,23 @@ start_link(Protocol, Sock, Channel, FrameMax, ReaderPid, Username, VHost, SupPid, {writer, {rabbit_writer, start_link, [Sock, Channel, FrameMax, Protocol]}, - permanent, ?MAX_WAIT, worker, [rabbit_writer]}), + intrinsic, ?MAX_WAIT, worker, [rabbit_writer]}), {ok, ChannelPid} = supervisor2:start_child( SupPid, {channel, {rabbit_channel, start_link, [Channel, ReaderPid, WriterPid, Username, VHost, Collector]}, - permanent, ?MAX_WAIT, worker, [rabbit_channel]}), + intrinsic, ?MAX_WAIT, worker, [rabbit_channel]}), {ok, FramingChannelPid} = supervisor2:start_child( SupPid, {framing_channel, {rabbit_framing_channel, start_link, [ChannelPid, Protocol]}, - permanent, ?MAX_WAIT, worker, [rabbit_framing_channel]}), + intrinsic, ?MAX_WAIT, worker, [rabbit_framing_channel]}), {ok, SupPid, FramingChannelPid}. %%---------------------------------------------------------------------------- init([]) -> - {ok, {{one_for_all, 0, 1}, []}}. + {ok, {{one_for_all, 10, 10}, []}}. diff --git a/src/rabbit_connection_sup.erl b/src/rabbit_connection_sup.erl index 8d09961f89..f097f80a77 100644 --- a/src/rabbit_connection_sup.erl +++ b/src/rabbit_connection_sup.erl @@ -41,23 +41,25 @@ start_link() -> {ok, SupPid} = supervisor2:start_link(?MODULE, []), + {ok, Collector} = + supervisor2:start_child( + SupPid, + {collector, {rabbit_queue_collector, start_link, []}, + intrinsic, ?MAX_WAIT, worker, [rabbit_queue_collector]}), {ok, ChannelSupSupPid} = supervisor2:start_child( SupPid, {channel_sup_sup, {rabbit_channel_sup_sup, start_link, []}, - permanent, infinity, supervisor, [rabbit_channel_sup_sup]}), + intrinsic, infinity, supervisor, [rabbit_channel_sup_sup]}), {ok, _ReaderPid} = supervisor2:start_child( SupPid, - {reader, {rabbit_reader, start_link, [ChannelSupSupPid]}, - permanent, ?MAX_WAIT, worker, [rabbit_reader]}), + {reader, {rabbit_reader, start_link, [ChannelSupSupPid, Collector]}, + intrinsic, ?MAX_WAIT, worker, [rabbit_reader]}), {ok, SupPid}. init([]) -> - {ok, {{one_for_all, 0, 1}, - [{collector, {rabbit_queue_collector, start_link, []}, - permanent, ?MAX_WAIT, worker, [rabbit_queue_collector]} - ]}}. + {ok, {{one_for_all, 10, 10}, []}}. reader(Pid) -> hd(supervisor2:find_child(Pid, reader)). diff --git a/src/rabbit_heartbeat.erl b/src/rabbit_heartbeat.erl index d694011a24..b277de70ce 100644 --- a/src/rabbit_heartbeat.erl +++ b/src/rabbit_heartbeat.erl @@ -64,12 +64,12 @@ start_heartbeat(Sup, Sock, TimeoutSec) -> supervisor:start_child( Sup, {heartbeat_sender, {?MODULE, start_heartbeat_sender, [Sock, TimeoutSec]}, - transient, ?MAX_WAIT, worker, [rabbit_heartbeat]}), + permanent, ?MAX_WAIT, worker, [rabbit_heartbeat]}), {ok, Receiver} = supervisor:start_child( Sup, {heartbeat_receiver, {?MODULE, start_heartbeat_receiver, [Sock, TimeoutSec]}, - transient, ?MAX_WAIT, worker, [rabbit_heartbeat]}), + permanent, ?MAX_WAIT, worker, [rabbit_heartbeat]}), {Sender, Receiver}. start_heartbeat_sender(Sock, TimeoutSec) -> diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index eaf568862b..5c0dee7320 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -33,11 +33,11 @@ -include("rabbit_framing.hrl"). -include("rabbit.hrl"). --export([start_link/1, info_keys/0, info/1, info/2, shutdown/2]). +-export([start_link/2, info_keys/0, info/1, info/2, shutdown/2]). -export([system_continue/3, system_terminate/4, system_code_change/4]). --export([init/2, mainloop/2]). +-export([init/3, mainloop/2]). -export([conserve_memory/2, server_properties/0]). @@ -161,7 +161,7 @@ -ifdef(use_specs). --spec(start_link/1 :: (pid()) -> rabbit_types:ok(pid())). +-spec(start_link/2 :: (pid(), pid()) -> rabbit_types:ok(pid())). -spec(info_keys/0 :: () -> [rabbit_types:info_key()]). -spec(info/1 :: (pid()) -> [rabbit_types:info()]). -spec(info/2 :: (pid(), [rabbit_types:info_key()]) -> [rabbit_types:info()]). @@ -171,9 +171,9 @@ -spec(server_properties/0 :: () -> rabbit_framing:amqp_table()). %% These specs only exists to add no_return() to keep dialyzer happy --spec(init/2 :: (pid(), pid()) -> no_return()). --spec(start_connection/5 :: - (pid(), pid(), any(), rabbit_networking:socket(), +-spec(init/3 :: (pid(), pid(), pid()) -> no_return()). +-spec(start_connection/6 :: + (pid(), pid(), pid(), any(), rabbit_networking:socket(), fun ((rabbit_networking:socket()) -> rabbit_types:ok_or_error2( rabbit_networking:socket(), any()))) -> no_return()). @@ -182,17 +182,18 @@ %%-------------------------------------------------------------------------- -start_link(ChannelSupSupPid) -> - {ok, proc_lib:spawn_link(?MODULE, init, [self(), ChannelSupSupPid])}. +start_link(ChannelSupSupPid, Collector) -> + {ok, proc_lib:spawn_link(?MODULE, init, [self(), ChannelSupSupPid, Collector])}. shutdown(Pid, Explanation) -> gen_server:call(Pid, {shutdown, Explanation}, infinity). -init(Parent, ChannelSupSupPid) -> +init(Parent, ChannelSupSupPid, Collector) -> Deb = sys:debug_options([]), receive {go, Sock, SockTransform} -> - start_connection(Parent, ChannelSupSupPid, Deb, Sock, SockTransform) + start_connection( + Parent, ChannelSupSupPid, Collector, Deb, Sock, SockTransform) end. system_continue(Parent, Deb, State) -> @@ -271,7 +272,8 @@ socket_op(Sock, Fun) -> exit(normal) end. -start_connection(Parent, ChannelSupSupPid, Deb, Sock, SockTransform) -> +start_connection(Parent, ChannelSupSupPid, Collector, Deb, Sock, + SockTransform) -> process_flag(trap_exit, true), {PeerAddress, PeerPort} = socket_op(Sock, fun rabbit_net:peername/1), PeerAddressS = inet_parse:ntoa(PeerAddress), @@ -281,7 +283,6 @@ start_connection(Parent, ChannelSupSupPid, Deb, Sock, SockTransform) -> erlang:send_after(?HANDSHAKE_TIMEOUT * 1000, self(), handshake_timeout), ProfilingValue = setup_profiling(), - [Collector] = supervisor2:find_child(Parent, collector), try mainloop(Deb, switch_callback( #v1{parent = Parent, diff --git a/src/supervisor2.erl b/src/supervisor2.erl index 6bc5b1e78a..682faba15e 100644 --- a/src/supervisor2.erl +++ b/src/supervisor2.erl @@ -31,6 +31,14 @@ %% the MaxT and MaxR parameters to permit the child to be %% restarted. This may require waiting for longer than Delay. %% +%% 4) Added an 'intrinsic' restart type. This type means that the +%% child should never be restarted (same as temporary) but whenever +%% such a child exits, it will cause the entire supervisor to exit +%% (i.e. the child's existence is intrinsic to the supervisor's +%% existence). Because such children are never restarted, the +%% supervisor's restart strategy, MaxT and MaxR have no bearing on +%% such children. +%% %% All modifications are (C) 2010 Rabbit Technologies Ltd. %% %% %CopyrightBegin% @@ -525,6 +533,14 @@ restart_child(Pid, Reason, State) -> {ok, State} end. +do_restart(intrinsic, Reason, Child, State) -> + case Reason of + normal -> ok; + shutdown -> ok; + {shutdown, _Term} -> ok; + _ -> report_error(child_terminated, Reason, Child, State#state.name) + end, + {shutdown, remove_child(Child, State)}; do_restart({RestartType, Delay}, Reason, Child, State) -> case restart1(Child, State) of {ok, NState} -> @@ -838,7 +854,7 @@ supname(N,_) -> N. %%% where Name is an atom %%% Func is {Mod, Fun, Args} == {atom, atom, list} %%% RestartType is permanent | temporary | transient | -%%% {permanent, Delay} | +%%% intrinsic | {permanent, Delay} | %%% {transient, Delay} where Delay >= 0 %%% Shutdown = integer() | infinity | brutal_kill %%% ChildType = supervisor | worker @@ -885,6 +901,7 @@ validFunc({M, F, A}) when is_atom(M), is_list(A) -> true; validFunc(Func) -> throw({invalid_mfa, Func}). +validRestartType(intrinsic) -> true; validRestartType(permanent) -> true; validRestartType(temporary) -> true; validRestartType(transient) -> true; |
