diff --git a/deps/amqp_client/src/amqp_channel_sup.erl b/deps/amqp_client/src/amqp_channel_sup.erl index c9015a4eab6f..6966014b0fe5 100644 --- a/deps/amqp_client/src/amqp_channel_sup.erl +++ b/deps/amqp_client/src/amqp_channel_sup.erl @@ -10,7 +10,7 @@ -include("amqp_client_internal.hrl"). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/6]). -export([init/1]). @@ -22,13 +22,17 @@ start_link(Type, Connection, ConnName, InfraArgs, ChNumber, Consumer = {_, _}) -> Identity = {ConnName, ChNumber}, - {ok, Sup} = supervisor2:start_link(?MODULE, [Consumer, Identity]), - [{gen_consumer, ConsumerPid, _, _}] = supervisor2:which_children(Sup), - {ok, ChPid} = supervisor2:start_child( - Sup, {channel, - {amqp_channel, start_link, - [Type, Connection, ChNumber, ConsumerPid, Identity]}, - intrinsic, ?WORKER_WAIT, worker, [amqp_channel]}), + {ok, Sup} = supervisor:start_link(?MODULE, [Consumer, Identity]), + [{gen_consumer, ConsumerPid, _, _}] = supervisor:which_children(Sup), + StartMFA = {amqp_channel, start_link, [Type, Connection, ChNumber, ConsumerPid, Identity]}, + ChildSpec = #{id => channel, + start => StartMFA, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [amqp_channel]}, + {ok, ChPid} = supervisor:start_child(Sup, ChildSpec), case start_writer(Sup, Type, InfraArgs, ConnName, ChNumber, ChPid) of {ok, Writer} -> amqp_channel:set_writer(ChPid, Writer), @@ -59,22 +63,36 @@ start_writer(_Sup, direct, [ConnPid, Node, User, VHost, Collector, AmqpParams], end; start_writer(Sup, network, [Sock, FrameMax], ConnName, ChNumber, ChPid) -> GCThreshold = application:get_env(amqp_client, writer_gc_threshold, ?DEFAULT_GC_THRESHOLD), - supervisor2:start_child( - Sup, - {writer, {rabbit_writer, start_link, + StartMFA = {rabbit_writer, start_link, [Sock, ChNumber, FrameMax, ?PROTOCOL, ChPid, {ConnName, ChNumber}, false, GCThreshold]}, - transient, ?WORKER_WAIT, worker, [rabbit_writer]}). + ChildSpec = #{id => writer, + start => StartMFA, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [rabbit_writer]}, + supervisor:start_child(Sup, ChildSpec). init_command_assembler(direct) -> {ok, none}; init_command_assembler(network) -> rabbit_command_assembler:init(?PROTOCOL). %%--------------------------------------------------------------------------- -%% supervisor2 callbacks +%% supervisor callbacks %%--------------------------------------------------------------------------- init([{ConsumerModule, ConsumerArgs}, Identity]) -> - {ok, {{one_for_all, 0, 1}, - [{gen_consumer, {amqp_gen_consumer, start_link, - [ConsumerModule, ConsumerArgs, Identity]}, - intrinsic, ?WORKER_WAIT, worker, [amqp_gen_consumer]}]}}. + SupFlags = #{strategy => one_for_all, + intensity => 0, + period => 1, + auto_shutdown => any_significant}, + ChildStartMFA = {amqp_gen_consumer, start_link, [ConsumerModule, ConsumerArgs, Identity]}, + ChildSpec = #{id => gen_consumer, + start => ChildStartMFA, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [amqp_gen_consumer]}, + {ok, {SupFlags, [ChildSpec]}}. diff --git a/deps/amqp_client/src/amqp_channel_sup_sup.erl b/deps/amqp_client/src/amqp_channel_sup_sup.erl index 33c8f34adc36..dbb30f341ba1 100644 --- a/deps/amqp_client/src/amqp_channel_sup_sup.erl +++ b/deps/amqp_client/src/amqp_channel_sup_sup.erl @@ -10,7 +10,7 @@ -include("amqp_client.hrl"). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/3, start_channel_sup/4]). -export([init/1]). @@ -20,17 +20,22 @@ %%--------------------------------------------------------------------------- start_link(Type, Connection, ConnName) -> - supervisor2:start_link(?MODULE, [Type, Connection, ConnName]). + supervisor:start_link(?MODULE, [Type, Connection, ConnName]). start_channel_sup(Sup, InfraArgs, ChannelNumber, Consumer) -> - supervisor2:start_child(Sup, [InfraArgs, ChannelNumber, Consumer]). + supervisor:start_child(Sup, [InfraArgs, ChannelNumber, Consumer]). %%--------------------------------------------------------------------------- -%% supervisor2 callbacks +%% supervisor callbacks %%--------------------------------------------------------------------------- init([Type, Connection, ConnName]) -> - {ok, {{simple_one_for_one, 0, 1}, - [{channel_sup, - {amqp_channel_sup, start_link, [Type, Connection, ConnName]}, - temporary, infinity, supervisor, [amqp_channel_sup]}]}}. + SupFlags = #{strategy => simple_one_for_one, intensity => 0, period => 1}, + ChildStartMFA = {amqp_channel_sup, start_link, [Type, Connection, ConnName]}, + ChildSpec = #{id => channel_sup, + start => ChildStartMFA, + restart => temporary, + shutdown => infinity, + type => supervisor, + modules => [amqp_channel_sup]}, + {ok, {SupFlags, [ChildSpec]}}. diff --git a/deps/amqp_client/src/amqp_connection_sup.erl b/deps/amqp_client/src/amqp_connection_sup.erl index a9dbdc74aa08..b64b1ea8c15d 100644 --- a/deps/amqp_client/src/amqp_connection_sup.erl +++ b/deps/amqp_client/src/amqp_connection_sup.erl @@ -10,7 +10,7 @@ -include("amqp_client.hrl"). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/1]). -export([init/1]). @@ -20,22 +20,36 @@ %%--------------------------------------------------------------------------- start_link(AMQPParams) -> - {ok, Sup} = supervisor2:start_link(?MODULE, []), - {ok, TypeSup} = supervisor2:start_child( - Sup, {connection_type_sup, - {amqp_connection_type_sup, start_link, []}, - transient, ?SUPERVISOR_WAIT, supervisor, - [amqp_connection_type_sup]}), - {ok, Connection} = supervisor2:start_child( - Sup, {connection, {amqp_gen_connection, start_link, - [TypeSup, AMQPParams]}, - intrinsic, brutal_kill, worker, - [amqp_gen_connection]}), + {ok, Sup} = supervisor:start_link(?MODULE, []), + + StartMFA0 = {amqp_connection_type_sup, start_link, []}, + ChildSpec0 = #{id => connection_type_sup, + start => StartMFA0, + restart => transient, + shutdown => ?SUPERVISOR_WAIT, + type => supervisor, + modules => [amqp_connection_type_sup]}, + {ok, TypeSup} = supervisor:start_child(Sup, ChildSpec0), + + StartMFA1 = {amqp_gen_connection, start_link, [TypeSup, AMQPParams]}, + ChildSpec1 = #{id => connection, + start => StartMFA1, + restart => transient, + significant => true, + shutdown => brutal_kill, + type => worker, + modules => [amqp_gen_connection]}, + {ok, Connection} = supervisor:start_child(Sup, ChildSpec1), + {ok, Sup, Connection}. %%--------------------------------------------------------------------------- -%% supervisor2 callbacks +%% supervisor callbacks %%--------------------------------------------------------------------------- init([]) -> - {ok, {{one_for_all, 0, 1}, []}}. + SupFlags = #{strategy => one_for_all, + intensity => 0, + period => 1, + auto_shutdown => any_significant}, + {ok, {SupFlags, []}}. diff --git a/deps/amqp_client/src/amqp_connection_type_sup.erl b/deps/amqp_client/src/amqp_connection_type_sup.erl index 25c374fabf38..6a36cb051213 100644 --- a/deps/amqp_client/src/amqp_connection_type_sup.erl +++ b/deps/amqp_client/src/amqp_connection_type_sup.erl @@ -10,7 +10,7 @@ -include("amqp_client_internal.hrl"). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/0, start_infrastructure_fun/3, type_module/1]). @@ -21,7 +21,7 @@ %%--------------------------------------------------------------------------- start_link() -> - supervisor2:start_link(?MODULE, []). + supervisor:start_link(?MODULE, []). type_module(#amqp_params_direct{}) -> {direct, amqp_direct_connection}; type_module(#amqp_params_network{}) -> {network, amqp_network_connection}. @@ -29,63 +29,84 @@ type_module(#amqp_params_network{}) -> {network, amqp_network_connection}. %%--------------------------------------------------------------------------- start_channels_manager(Sup, Conn, ConnName, Type) -> - {ok, ChSupSup} = supervisor2:start_child( - Sup, - {channel_sup_sup, {amqp_channel_sup_sup, start_link, - [Type, Conn, ConnName]}, - intrinsic, ?SUPERVISOR_WAIT, supervisor, - [amqp_channel_sup_sup]}), - {ok, _} = supervisor2:start_child( - Sup, - {channels_manager, {amqp_channels_manager, start_link, - [Conn, ConnName, ChSupSup]}, - transient, ?WORKER_WAIT, worker, [amqp_channels_manager]}). + StartMFA0 = {amqp_channel_sup_sup, start_link, [Type, Conn, ConnName]}, + ChildSpec0 = #{id => channel_sup_sup, + start => StartMFA0, + restart => transient, + significant => true, + shutdown => ?SUPERVISOR_WAIT, + type => supervisor, + modules => [amqp_channel_sup_sup]}, + {ok, ChSupSup} = supervisor:start_child(Sup, ChildSpec0), + + StartMFA1 = {amqp_channels_manager, start_link, [Conn, ConnName, ChSupSup]}, + ChildSpec1 = #{id => channels_manager, + start => StartMFA1, + restart => transient, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [amqp_channels_manager]}, + {ok, _} = supervisor:start_child(Sup, ChildSpec1). start_infrastructure_fun(Sup, Conn, network) -> fun (Sock, ConnName) -> {ok, ChMgr} = start_channels_manager(Sup, Conn, ConnName, network), {ok, AState} = rabbit_command_assembler:init(?PROTOCOL), {ok, GCThreshold} = application:get_env(amqp_client, writer_gc_threshold), - {ok, Writer} = - supervisor2:start_child( - Sup, - {writer, - {rabbit_writer, start_link, - [Sock, 0, ?FRAME_MIN_SIZE, ?PROTOCOL, Conn, ConnName, - false, GCThreshold]}, - transient, ?WORKER_WAIT, worker, [rabbit_writer]}), - {ok, Reader} = - supervisor2:start_child( - Sup, - {main_reader, {amqp_main_reader, start_link, - [Sock, Conn, ChMgr, AState, ConnName]}, - transient, ?WORKER_WAIT, worker, [amqp_main_reader]}), + + WriterStartMFA = {rabbit_writer, start_link, + [Sock, 0, ?FRAME_MIN_SIZE, ?PROTOCOL, Conn, + ConnName, false, GCThreshold]}, + WriterChildSpec = #{id => writer, + start => WriterStartMFA, + restart => transient, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [rabbit_writer]}, + {ok, Writer} = supervisor:start_child(Sup, WriterChildSpec), + + ReaderStartMFA = {amqp_main_reader, start_link, + [Sock, Conn, ChMgr, AState, ConnName]}, + ReaderChildSpec = #{id => main_reader, + start => ReaderStartMFA, + restart => transient, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [amqp_main_reader]}, + {ok, Reader} = supervisor:start_child(Sup, ReaderChildSpec), case rabbit_net:controlling_process(Sock, Reader) of - ok -> - case amqp_main_reader:post_init(Reader) of - ok -> - {ok, ChMgr, Writer}; - {error, Reason} -> + ok -> + case amqp_main_reader:post_init(Reader) of + ok -> + {ok, ChMgr, Writer}; + {error, Reason} -> + {error, Reason} + end; + {error, Reason} -> {error, Reason} - end; - {error, Reason} -> - {error, Reason} end end; start_infrastructure_fun(Sup, Conn, direct) -> fun (ConnName) -> {ok, ChMgr} = start_channels_manager(Sup, Conn, ConnName, direct), - {ok, Collector} = - supervisor2:start_child( - Sup, - {collector, {rabbit_queue_collector, start_link, [ConnName]}, - transient, ?WORKER_WAIT, worker, [rabbit_queue_collector]}), + StartMFA = {rabbit_queue_collector, start_link, [ConnName]}, + ChildSpec = #{id => collector, + start => StartMFA, + restart => transient, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [rabbit_queue_collector]}, + {ok, Collector} = supervisor:start_child(Sup, ChildSpec), {ok, ChMgr, Collector} end. %%--------------------------------------------------------------------------- -%% supervisor2 callbacks +%% supervisor callbacks %%--------------------------------------------------------------------------- init([]) -> - {ok, {{one_for_all, 0, 1}, []}}. + SupFlags = #{strategy => one_for_all, + intensity => 0, + period => 1, + auto_shutdown => any_significant}, + {ok, {SupFlags, []}}. diff --git a/deps/amqp_client/src/amqp_sup.erl b/deps/amqp_client/src/amqp_sup.erl index 986c772c4715..ab683744691b 100644 --- a/deps/amqp_client/src/amqp_sup.erl +++ b/deps/amqp_client/src/amqp_sup.erl @@ -10,7 +10,7 @@ -include("amqp_client.hrl"). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/0, is_ready/0, start_connection_sup/1]). -export([init/1]). @@ -20,19 +20,26 @@ %%--------------------------------------------------------------------------- start_link() -> - supervisor2:start_link({local, amqp_sup}, ?MODULE, []). + supervisor:start_link({local, amqp_sup}, ?MODULE, []). is_ready() -> whereis(amqp_sup) =/= undefined. start_connection_sup(AmqpParams) -> - supervisor2:start_child(amqp_sup, [AmqpParams]). + supervisor:start_child(amqp_sup, [AmqpParams]). %%--------------------------------------------------------------------------- -%% supervisor2 callbacks +%% supervisor callbacks %%--------------------------------------------------------------------------- init([]) -> - {ok, {{simple_one_for_one, 0, 1}, - [{connection_sup, {amqp_connection_sup, start_link, []}, - temporary, ?SUPERVISOR_WAIT, supervisor, [amqp_connection_sup]}]}}. + SupFlags = #{strategy => simple_one_for_one, + intensity => 0, + period => 1}, + ChildSpec = #{id => connection_sup, + start => {amqp_connection_sup, start_link, []}, + restart => temporary, + shutdown => ?SUPERVISOR_WAIT, + type => supervisor, + modules => [amqp_connection_sup]}, + {ok, {SupFlags, [ChildSpec]}}. diff --git a/deps/rabbit/src/rabbit_amqqueue_sup.erl b/deps/rabbit/src/rabbit_amqqueue_sup.erl index 3085175a512d..6cfbfffc48fa 100644 --- a/deps/rabbit/src/rabbit_amqqueue_sup.erl +++ b/deps/rabbit/src/rabbit_amqqueue_sup.erl @@ -7,7 +7,7 @@ -module(rabbit_amqqueue_sup). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/2]). @@ -22,12 +22,16 @@ start_link(Q, StartMode) -> Marker = spawn_link(fun() -> receive stop -> ok end end), - ChildSpec = {rabbit_amqqueue, - {rabbit_prequeue, start_link, [Q, StartMode, Marker]}, - intrinsic, ?CLASSIC_QUEUE_WORKER_WAIT, worker, - [rabbit_amqqueue_process, rabbit_mirror_queue_slave]}, - {ok, SupPid} = supervisor2:start_link(?MODULE, []), - {ok, QPid} = supervisor2:start_child(SupPid, ChildSpec), + StartMFA = {rabbit_prequeue, start_link, [Q, StartMode, Marker]}, + ChildSpec = #{id => rabbit_amqqueue, + start => StartMFA, + restart => transient, + significant => true, + shutdown => ?CLASSIC_QUEUE_WORKER_WAIT, + type => worker, + modules => [rabbit_amqqueue_process, rabbit_mirror_queue_slave]}, + {ok, SupPid} = supervisor:start_link(?MODULE, []), + {ok, QPid} = supervisor:start_child(SupPid, ChildSpec), unlink(Marker), Marker ! stop, {ok, SupPid, QPid}. @@ -37,4 +41,8 @@ init([]) -> %% that crash queue processes on purpose and may end up crashing %% the queues faster than we normally allow. {Intensity, Period} = application:get_env(rabbit, amqqueue_max_restart_intensity, {5, 10}), - {ok, {{one_for_one, Intensity, Period}, []}}. + SupFlags = #{strategy => one_for_one, + intensity => Intensity, + period => Period, + auto_shutdown => any_significant}, + {ok, {SupFlags, []}}. diff --git a/deps/rabbit/src/rabbit_amqqueue_sup_sup.erl b/deps/rabbit/src/rabbit_amqqueue_sup_sup.erl index 5b6837fe50df..62c2ad328fd4 100644 --- a/deps/rabbit/src/rabbit_amqqueue_sup_sup.erl +++ b/deps/rabbit/src/rabbit_amqqueue_sup_sup.erl @@ -7,7 +7,7 @@ -module(rabbit_amqqueue_sup_sup). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/0, start_queue_process/3]). -export([start_for_vhost/1, stop_for_vhost/1, @@ -24,7 +24,7 @@ -spec start_link() -> rabbit_types:ok_pid_or_error(). start_link() -> - supervisor2:start_link(?MODULE, []). + supervisor:start_link(?MODULE, []). -spec start_queue_process (node(), amqqueue:amqqueue(), 'declare' | 'recovery' | 'slave') -> @@ -33,13 +33,20 @@ start_link() -> start_queue_process(Node, Q, StartMode) -> #resource{virtual_host = VHost} = amqqueue:get_name(Q), {ok, Sup} = find_for_vhost(VHost, Node), - {ok, _SupPid, QPid} = supervisor2:start_child(Sup, [Q, StartMode]), + {ok, _SupPid, QPid} = supervisor:start_child(Sup, [Q, StartMode]), QPid. init([]) -> - {ok, {{simple_one_for_one, 10, 10}, - [{rabbit_amqqueue_sup, {rabbit_amqqueue_sup, start_link, []}, - temporary, ?SUPERVISOR_WAIT, supervisor, [rabbit_amqqueue_sup]}]}}. + SupFlags = #{strategy => simple_one_for_one, + intensity => 10, + period => 10}, + ChildSpec = #{id => rabbit_amqqueue_sup, + start => {rabbit_amqqueue_sup, start_link, []}, + restart => temporary, + shutdown => ?SUPERVISOR_WAIT, + type => supervisor, + modules => [rabbit_amqqueue_sup]}, + {ok, {SupFlags, [ChildSpec]}}. -spec find_for_vhost(rabbit_types:vhost()) -> {ok, pid()} | {error, term()}. find_for_vhost(VHost) -> @@ -48,7 +55,7 @@ find_for_vhost(VHost) -> -spec find_for_vhost(rabbit_types:vhost(), atom()) -> {ok, pid()} | {error, term()}. find_for_vhost(VHost, Node) -> {ok, VHostSup} = rabbit_vhost_sup_sup:get_vhost_sup(VHost, Node), - case supervisor2:find_child(VHostSup, rabbit_amqqueue_sup_sup) of + case rabbit_misc:find_child(VHostSup, rabbit_amqqueue_sup_sup) of [QSup] -> {ok, QSup}; Result -> {error, {queue_supervisor_not_found, Result}} end. @@ -57,15 +64,18 @@ find_for_vhost(VHost, Node) -> start_for_vhost(VHost) -> case rabbit_vhost_sup_sup:get_vhost_sup(VHost) of {ok, VHostSup} -> - supervisor2:start_child( - VHostSup, - {rabbit_amqqueue_sup_sup, - {rabbit_amqqueue_sup_sup, start_link, []}, - transient, infinity, supervisor, [rabbit_amqqueue_sup_sup]}); + StartMFA = {rabbit_amqqueue_sup_sup, start_link, []}, + ChildSpec = #{id => rabbit_amqqueue_sup_sup, + start => StartMFA, + restart => transient, + shutdown => infinity, + type => supervisor, + modules => [rabbit_amqqueue_sup_sup]}, + supervisor:start_child(VHostSup, ChildSpec); %% we can get here if a vhost is added and removed concurrently %% e.g. some integration tests do it {error, {no_such_vhost, VHost}} -> - rabbit_log:error("Failed to start a queue process supervisor for vhost ~ts: vhost no longer exists!", + rabbit_log:error("Failed to stop a queue process supervisor for vhost ~ts: vhost no longer exists!", [VHost]), {error, {no_such_vhost, VHost}} end. @@ -74,8 +84,8 @@ start_for_vhost(VHost) -> stop_for_vhost(VHost) -> case rabbit_vhost_sup_sup:get_vhost_sup(VHost) of {ok, VHostSup} -> - ok = supervisor2:terminate_child(VHostSup, rabbit_amqqueue_sup_sup), - ok = supervisor2:delete_child(VHostSup, rabbit_amqqueue_sup_sup); + ok = supervisor:terminate_child(VHostSup, rabbit_amqqueue_sup_sup), + ok = supervisor:delete_child(VHostSup, rabbit_amqqueue_sup_sup); %% see start/1 {error, {no_such_vhost, VHost}} -> rabbit_log:error("Failed to stop a queue process supervisor for vhost ~ts: vhost no longer exists!", diff --git a/deps/rabbit/src/rabbit_channel_sup.erl b/deps/rabbit/src/rabbit_channel_sup.erl index b1e2f6fa476c..931d9f71953a 100644 --- a/deps/rabbit/src/rabbit_channel_sup.erl +++ b/deps/rabbit/src/rabbit_channel_sup.erl @@ -17,7 +17,7 @@ %% %% See also rabbit_channel, rabbit_writer, rabbit_limiter. --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/1]). @@ -46,47 +46,79 @@ start_link({tcp, Sock, Channel, FrameMax, ReaderPid, ConnName, Protocol, User, VHost, Capabilities, Collector}) -> - {ok, SupPid} = supervisor2:start_link( + {ok, SupPid} = supervisor:start_link( ?MODULE, {tcp, Sock, Channel, FrameMax, ReaderPid, Protocol, {ConnName, Channel}}), - [LimiterPid] = supervisor2:find_child(SupPid, limiter), - [WriterPid] = supervisor2:find_child(SupPid, writer), - {ok, ChannelPid} = - supervisor2:start_child( - SupPid, - {channel, {rabbit_channel, start_link, - [Channel, ReaderPid, WriterPid, ReaderPid, ConnName, - Protocol, User, VHost, Capabilities, Collector, - LimiterPid]}, - intrinsic, ?FAIR_WAIT, worker, [rabbit_channel]}), + [LimiterPid] = rabbit_misc:find_child(SupPid, limiter), + [WriterPid] = rabbit_misc:find_child(SupPid, writer), + StartMFA = {rabbit_channel, start_link, + [Channel, ReaderPid, WriterPid, ReaderPid, ConnName, + Protocol, User, VHost, Capabilities, Collector, + LimiterPid]}, + ChildSpec = #{id => channel, + start => StartMFA, + restart => transient, + significant => true, + shutdown => ?FAIR_WAIT, + type => worker, + modules => [rabbit_channel]}, + {ok, ChannelPid} = supervisor:start_child(SupPid, ChildSpec), {ok, AState} = rabbit_command_assembler:init(Protocol), {ok, SupPid, {ChannelPid, AState}}; start_link({direct, Channel, ClientChannelPid, ConnPid, ConnName, Protocol, User, VHost, Capabilities, Collector, AmqpParams}) -> - {ok, SupPid} = supervisor2:start_link( + {ok, SupPid} = supervisor:start_link( ?MODULE, {direct, {ConnName, Channel}}), - [LimiterPid] = supervisor2:find_child(SupPid, limiter), - {ok, ChannelPid} = - supervisor2:start_child( - SupPid, - {channel, {rabbit_channel, start_link, - [Channel, ClientChannelPid, ClientChannelPid, ConnPid, - ConnName, Protocol, User, VHost, Capabilities, Collector, - LimiterPid, AmqpParams]}, - intrinsic, ?FAIR_WAIT, worker, [rabbit_channel]}), + [LimiterPid] = rabbit_misc:find_child(SupPid, limiter), + StartMFA = {rabbit_channel, start_link, + [Channel, ClientChannelPid, ClientChannelPid, ConnPid, + ConnName, Protocol, User, VHost, Capabilities, Collector, + LimiterPid, AmqpParams]}, + ChildSpec = #{id => channel, + start => StartMFA, + restart => transient, + significant => true, + shutdown => ?FAIR_WAIT, + type => worker, + modules => [rabbit_channel]}, + {ok, ChannelPid} = supervisor:start_child(SupPid, ChildSpec), {ok, SupPid, {ChannelPid, none}}. %%---------------------------------------------------------------------------- init(Type) -> ?LG_PROCESS_TYPE(channel_sup), - {ok, {{one_for_all, 0, 1}, child_specs(Type)}}. + SupFlags = #{strategy => one_for_all, + intensity => 0, + period => 1, + auto_shutdown => any_significant}, + {ok, {SupFlags, child_specs(Type)}}. child_specs({tcp, Sock, Channel, FrameMax, ReaderPid, Protocol, Identity}) -> - [{writer, {rabbit_writer, start_link, - [Sock, Channel, FrameMax, Protocol, ReaderPid, Identity, true]}, - intrinsic, ?FAIR_WAIT, worker, [rabbit_writer]} - | child_specs({direct, Identity})]; + StartMFA = {rabbit_writer, start_link, + [Sock, Channel, FrameMax, Protocol, ReaderPid, Identity, true]}, + [ + #{ + id => writer, + start => StartMFA, + restart => transient, + significant => true, + shutdown => ?FAIR_WAIT, + type => worker, + modules => [rabbit_writer] + } + | child_specs({direct, Identity}) + ]; child_specs({direct, Identity}) -> - [{limiter, {rabbit_limiter, start_link, [Identity]}, - transient, ?FAIR_WAIT, worker, [rabbit_limiter]}]. + StartMFA = {rabbit_limiter, start_link, [Identity]}, + [ + #{ + id => limiter, + start => StartMFA, + restart => transient, + significant => true, + shutdown => ?FAIR_WAIT, + type => worker, + modules => [rabbit_limiter] + } + ]. diff --git a/deps/rabbit/src/rabbit_channel_sup_sup.erl b/deps/rabbit/src/rabbit_channel_sup_sup.erl index 0e95b66e64db..70f77c924896 100644 --- a/deps/rabbit/src/rabbit_channel_sup_sup.erl +++ b/deps/rabbit/src/rabbit_channel_sup_sup.erl @@ -12,7 +12,7 @@ %% %% See also rabbit_channel_sup, rabbit_connection_helper_sup, rabbit_reader. --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/0, start_channel/2]). @@ -25,18 +25,26 @@ -spec start_link() -> rabbit_types:ok_pid_or_error(). start_link() -> - supervisor2:start_link(?MODULE, []). + supervisor:start_link(?MODULE, []). -spec start_channel(pid(), rabbit_channel_sup:start_link_args()) -> {'ok', pid(), {pid(), any()}}. start_channel(Pid, Args) -> - supervisor2:start_child(Pid, [Args]). + supervisor:start_child(Pid, [Args]). %%---------------------------------------------------------------------------- init([]) -> ?LG_PROCESS_TYPE(channel_sup_sup), - {ok, {{simple_one_for_one, 0, 1}, - [{channel_sup, {rabbit_channel_sup, start_link, []}, - temporary, infinity, supervisor, [rabbit_channel_sup]}]}}. + SupFlags = #{strategy => simple_one_for_one, + intensity => 0, + period => 1, + auto_shutdown => never}, + ChildSpec = #{id => channel_sup, + start => {rabbit_channel_sup, start_link, []}, + restart => transient, + shutdown => infinity, + type => supervisor, + modules => [rabbit_channel_sup]}, + {ok, {SupFlags, [ChildSpec]}}. diff --git a/deps/rabbit/src/rabbit_client_sup.erl b/deps/rabbit/src/rabbit_client_sup.erl index 47ff1c144519..bfb429abc010 100644 --- a/deps/rabbit/src/rabbit_client_sup.erl +++ b/deps/rabbit/src/rabbit_client_sup.erl @@ -7,7 +7,7 @@ -module(rabbit_client_sup). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/1, start_link/2, start_link_worker/2]). @@ -21,23 +21,39 @@ rabbit_types:ok_pid_or_error(). start_link(Callback) -> - supervisor2:start_link(?MODULE, Callback). + supervisor:start_link(?MODULE, Callback). -spec start_link({'local', atom()}, rabbit_types:mfargs()) -> rabbit_types:ok_pid_or_error(). start_link(SupName, Callback) -> - supervisor2:start_link(SupName, ?MODULE, Callback). + supervisor:start_link(SupName, ?MODULE, Callback). -spec start_link_worker({'local', atom()}, rabbit_types:mfargs()) -> rabbit_types:ok_pid_or_error(). start_link_worker(SupName, Callback) -> - supervisor2:start_link(SupName, ?MODULE, {Callback, worker}). - -init({M,F,A}) -> - {ok, {{simple_one_for_one, 0, 1}, - [{client, {M,F,A}, temporary, infinity, supervisor, [M]}]}}; -init({{M,F,A}, worker}) -> - {ok, {{simple_one_for_one, 0, 1}, - [{client, {M,F,A}, temporary, ?WORKER_WAIT, worker, [M]}]}}. + supervisor:start_link(SupName, ?MODULE, {Callback, worker}). + +init({M, F, A}) -> + SupFlags = #{strategy => simple_one_for_one, + intensity => 0, + period => 1}, + ChildSpec = #{id => client, + start => {M, F, A}, + restart => temporary, + shutdown => infinity, + type => supervisor, + modules => [M]}, + {ok, {SupFlags, [ChildSpec]}}; +init({{M, F, A}, worker}) -> + SupFlags = #{strategy => simple_one_for_one, + intensity => 0, + period => 1}, + ChildSpec = #{id => client, + start => {M, F, A}, + restart => temporary, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [M]}, + {ok, {SupFlags, [ChildSpec]}}. diff --git a/deps/rabbit/src/rabbit_connection_helper_sup.erl b/deps/rabbit/src/rabbit_connection_helper_sup.erl index 5cf0cc210f1b..ecec17fd85b1 100644 --- a/deps/rabbit/src/rabbit_connection_helper_sup.erl +++ b/deps/rabbit/src/rabbit_connection_helper_sup.erl @@ -16,11 +16,13 @@ %% %% See also rabbit_heartbeat, rabbit_channel_sup_sup, rabbit_queue_collector. --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/0]). --export([start_channel_sup_sup/1, - start_queue_collector/2]). +-export([ + start_channel_sup_sup/1, + start_queue_collector/2 +]). -export([init/1]). @@ -31,27 +33,39 @@ -spec start_link() -> rabbit_types:ok_pid_or_error(). start_link() -> - supervisor2:start_link(?MODULE, []). + supervisor:start_link(?MODULE, []). -spec start_channel_sup_sup(pid()) -> rabbit_types:ok_pid_or_error(). start_channel_sup_sup(SupPid) -> - supervisor2:start_child( - SupPid, - {channel_sup_sup, {rabbit_channel_sup_sup, start_link, []}, - intrinsic, infinity, supervisor, [rabbit_channel_sup_sup]}). + ChildSpec = #{id => channel_sup_sup, + start => {rabbit_channel_sup_sup, start_link, []}, + restart => transient, + significant => true, + shutdown => infinity, + type => supervisor, + modules => [rabbit_channel_sup_sup]}, + supervisor:start_child(SupPid, ChildSpec). -spec start_queue_collector(pid(), rabbit_types:proc_name()) -> - rabbit_types:ok_pid_or_error(). + rabbit_types:ok_pid_or_error(). start_queue_collector(SupPid, Identity) -> - supervisor2:start_child( - SupPid, - {collector, {rabbit_queue_collector, start_link, [Identity]}, - intrinsic, ?WORKER_WAIT, worker, [rabbit_queue_collector]}). + ChildSpec = #{id => collector, + start => {rabbit_queue_collector, start_link, [Identity]}, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [rabbit_queue_collector]}, + supervisor:start_child(SupPid, ChildSpec). %%---------------------------------------------------------------------------- init([]) -> ?LG_PROCESS_TYPE(connection_helper_sup), - {ok, {{one_for_one, 10, 10}, []}}. + SupFlags = #{strategy => one_for_one, + intensity => 10, + period => 10, + auto_shutdown => any_significant}, + {ok, {SupFlags, []}}. diff --git a/deps/rabbit/src/rabbit_connection_sup.erl b/deps/rabbit/src/rabbit_connection_sup.erl index 83da3e72e108..fbdde3c9b12a 100644 --- a/deps/rabbit/src/rabbit_connection_sup.erl +++ b/deps/rabbit/src/rabbit_connection_sup.erl @@ -16,7 +16,7 @@ %% %% See also rabbit_reader, rabbit_connection_helper_sup. --behaviour(supervisor2). +-behaviour(supervisor). -behaviour(ranch_protocol). -export([start_link/3, reader/1]). @@ -28,10 +28,10 @@ %%---------------------------------------------------------------------------- -spec start_link(any(), module(), any()) -> - {'ok', pid(), pid()}. + {'ok', pid(), pid()}. start_link(Ref, _Transport, _Opts) -> - {ok, SupPid} = supervisor2:start_link(?MODULE, []), + {ok, SupPid} = supervisor:start_link(?MODULE, []), %% We need to get channels in the hierarchy here so they get shut %% down after the reader, so the reader gets a chance to terminate %% them cleanly. But for 1.0 readers we can't start the real @@ -43,24 +43,49 @@ start_link(Ref, _Transport, _Opts) -> %% reader due to the potential for deadlock if they are added/restarted %% whilst the supervision tree is shutting down. {ok, HelperSup} = - supervisor2:start_child( - SupPid, - {helper_sup, {rabbit_connection_helper_sup, start_link, []}, - intrinsic, infinity, supervisor, [rabbit_connection_helper_sup]}), + supervisor:start_child( + SupPid, + #{ + id => helper_sup, + start => {rabbit_connection_helper_sup, start_link, []}, + restart => transient, + significant => true, + shutdown => infinity, + type => supervisor, + modules => [rabbit_connection_helper_sup] + } + ), {ok, ReaderPid} = - supervisor2:start_child( - SupPid, - {reader, {rabbit_reader, start_link, [HelperSup, Ref]}, - intrinsic, ?WORKER_WAIT, worker, [rabbit_reader]}), + supervisor:start_child( + SupPid, + #{ + id => reader, + start => {rabbit_reader, start_link, [HelperSup, Ref]}, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [rabbit_reader] + } + ), {ok, SupPid, ReaderPid}. -spec reader(pid()) -> pid(). reader(Pid) -> - hd(supervisor2:find_child(Pid, reader)). + hd(rabbit_misc:find_child(Pid, reader)). %%-------------------------------------------------------------------------- init([]) -> ?LG_PROCESS_TYPE(connection_sup), - {ok, {{one_for_all, 0, 1}, []}}. + {ok, + { + #{ + strategy => one_for_all, + intensity => 0, + period => 1, + auto_shutdown => any_significant + }, + [] + }}. diff --git a/deps/rabbit/src/rabbit_direct.erl b/deps/rabbit/src/rabbit_direct.erl index 7112426cab89..cc85d115a040 100644 --- a/deps/rabbit/src/rabbit_direct.erl +++ b/deps/rabbit/src/rabbit_direct.erl @@ -213,7 +213,7 @@ start_channel(Number, ClientChannelPid, ConnPid, ConnName, Protocol, case rabbit_auth_backend_internal:is_over_channel_limit(Username) of false -> {ok, _, {ChannelPid, _}} = - supervisor2:start_child( + supervisor:start_child( rabbit_direct_client_sup, [{direct, Number, ClientChannelPid, ConnPid, ConnName, Protocol, User, VHost, Capabilities, Collector, AmqpParams}]), diff --git a/deps/rabbit/src/rabbit_recovery_terms.erl b/deps/rabbit/src/rabbit_recovery_terms.erl index 216cef1af0ba..ff21afd34448 100644 --- a/deps/rabbit/src/rabbit_recovery_terms.erl +++ b/deps/rabbit/src/rabbit_recovery_terms.erl @@ -35,7 +35,7 @@ start(VHost) -> case rabbit_vhost_sup_sup:get_vhost_sup(VHost) of {ok, VHostSup} -> - {ok, _} = supervisor2:start_child( + {ok, _} = supervisor:start_child( VHostSup, {?MODULE, {?MODULE, start_link, [VHost]}, diff --git a/deps/rabbit/src/rabbit_vhost_msg_store.erl b/deps/rabbit/src/rabbit_vhost_msg_store.erl index 9212884bea96..134a0b8105f8 100644 --- a/deps/rabbit/src/rabbit_vhost_msg_store.erl +++ b/deps/rabbit/src/rabbit_vhost_msg_store.erl @@ -18,7 +18,7 @@ start(VHost, Type, ClientRefs, StartupFunState) when is_list(ClientRefs); case rabbit_vhost_sup_sup:get_vhost_sup(VHost) of {ok, VHostSup} -> VHostDir = rabbit_vhost:msg_store_dir_path(VHost), - supervisor2:start_child(VHostSup, + supervisor:start_child(VHostSup, {Type, {rabbit_msg_store, start_link, [VHost, Type, VHostDir, ClientRefs, StartupFunState]}, transient, ?MSG_STORE_WORKER_WAIT, worker, [rabbit_msg_store]}); @@ -33,8 +33,8 @@ start(VHost, Type, ClientRefs, StartupFunState) when is_list(ClientRefs); stop(VHost, Type) -> case rabbit_vhost_sup_sup:get_vhost_sup(VHost) of {ok, VHostSup} -> - ok = supervisor2:terminate_child(VHostSup, Type), - ok = supervisor2:delete_child(VHostSup, Type); + ok = supervisor:terminate_child(VHostSup, Type), + ok = supervisor:delete_child(VHostSup, Type); %% see start/4 {error, {no_such_vhost, VHost}} -> rabbit_log:error("Failed to stop a message store for vhost ~ts: vhost no longer exists!", @@ -61,7 +61,7 @@ vhost_store_pid(VHost, Type) -> [] -> %% Fall back to using the supervisor (sometimes necessary on queue startup). {ok, VHostSup} = rabbit_vhost_sup_sup:get_vhost_sup(VHost), - case supervisor2:find_child(VHostSup, Type) of + case rabbit_misc:find_child(VHostSup, Type) of [Pid] -> Pid; [] -> no_pid end; diff --git a/deps/rabbit/src/rabbit_vhost_sup.erl b/deps/rabbit/src/rabbit_vhost_sup.erl index e857f4cd434b..fbed26afea13 100644 --- a/deps/rabbit/src/rabbit_vhost_sup.erl +++ b/deps/rabbit/src/rabbit_vhost_sup.erl @@ -11,12 +11,12 @@ %% Each vhost gets an instance of this supervisor that supervises %% message stores and queues (via rabbit_amqqueue_sup_sup). --behaviour(supervisor2). +-behaviour(supervisor). -export([init/1]). -export([start_link/1]). start_link(VHost) -> - supervisor2:start_link(?MODULE, [VHost]). + supervisor:start_link(?MODULE, [VHost]). init([_VHost]) -> - {ok, {{one_for_all, 0, 1}, []}}. + {ok, {#{strategy => one_for_all, intensity => 0, period => 1}, []}}. diff --git a/deps/rabbit/src/rabbit_vhost_sup_sup.erl b/deps/rabbit/src/rabbit_vhost_sup_sup.erl index f077e7dcefe6..9d94489eb8db 100644 --- a/deps/rabbit/src/rabbit_vhost_sup_sup.erl +++ b/deps/rabbit/src/rabbit_vhost_sup_sup.erl @@ -9,7 +9,7 @@ -include_lib("rabbit_common/include/rabbit.hrl"). --behaviour(supervisor2). +-behaviour(supervisor). -export([init/1]). @@ -38,7 +38,7 @@ start() -> end. start_link() -> - supervisor2:start_link({local, ?MODULE}, ?MODULE, []). + supervisor:start_link({local, ?MODULE}, ?MODULE, []). init([]) -> %% This assumes that a single vhost termination should not shut down nodes @@ -81,7 +81,7 @@ stop_and_delete_vhost(VHost) -> rabbit_log:info("Stopping vhost supervisor ~tp" " for vhost '~ts'", [VHostSupPid, VHost]), - case supervisor2:terminate_child(?MODULE, WrapperPid) of + case supervisor:terminate_child(?MODULE, WrapperPid) of ok -> true = ets:delete(?MODULE, VHost), ok; @@ -179,7 +179,7 @@ start_vhost(VHost) -> true -> case whereis(?MODULE) of Pid when is_pid(Pid) -> - supervisor2:start_child(?MODULE, [VHost]); + supervisor:start_child(?MODULE, [VHost]); undefined -> {error, rabbit_vhost_sup_sup_not_running} end diff --git a/deps/rabbit/src/rabbit_vhost_sup_wrapper.erl b/deps/rabbit/src/rabbit_vhost_sup_wrapper.erl index 5093ecda97ba..22279c98833f 100644 --- a/deps/rabbit/src/rabbit_vhost_sup_wrapper.erl +++ b/deps/rabbit/src/rabbit_vhost_sup_wrapper.erl @@ -12,16 +12,14 @@ -include_lib("rabbit_common/include/rabbit.hrl"). --behaviour(supervisor2). +-behaviour(supervisor). -export([init/1]). -export([start_link/1]). -export([start_vhost_sup/1]). start_link(VHost) -> - %% Using supervisor, because supervisor2 does not stop a started child when - %% another one fails to start. Bug? case rabbit_vhost_sup_sup:get_vhost_sup(VHost) of - {ok, Pid} -> + {ok, Pid} -> {error, {already_started, Pid}}; {error, _} -> supervisor:start_link(?MODULE, [VHost]) @@ -29,25 +27,33 @@ start_link(VHost) -> init([VHost]) -> %% 2 restarts in 5 minutes. One per message store. - {ok, {{one_for_all, 2, 300}, - [ - %% rabbit_vhost_sup is an empty supervisor container for - %% all data processes. - {rabbit_vhost_sup, - {rabbit_vhost_sup_wrapper, start_vhost_sup, [VHost]}, - permanent, infinity, supervisor, - [rabbit_vhost_sup]}, - %% rabbit_vhost_process is a vhost identity process, which - %% is responsible for data recovery and vhost aliveness status. - %% See the module comments for more info. - {rabbit_vhost_process, - {rabbit_vhost_process, start_link, [VHost]}, - permanent, ?WORKER_WAIT, worker, - [rabbit_vhost_process]}]}}. - + {ok, + {#{strategy => one_for_all, intensity => 2, period => 300}, [ + %% rabbit_vhost_sup is an empty supervisor container for + %% all data processes. + #{ + id => rabbit_vhost_sup, + start => {rabbit_vhost_sup_wrapper, start_vhost_sup, [VHost]}, + restart => permanent, + shutdown => infinity, + type => supervisor, + modules => [rabbit_vhost_sup] + }, + %% rabbit_vhost_process is a vhost identity process, which + %% is responsible for data recovery and vhost aliveness status. + %% See the module comments for more info. + #{ + id => rabbit_vhost_process, + start => {rabbit_vhost_process, start_link, [VHost]}, + restart => permanent, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [rabbit_vhost_process] + } + ]}}. start_vhost_sup(VHost) -> - case rabbit_vhost_sup:start_link(VHost) of + case rabbit_vhost_sup:start_link(VHost) of {ok, Pid} -> %% Save vhost sup record with wrapper pid and vhost sup pid. ok = rabbit_vhost_sup_sup:save_vhost_sup(VHost, self(), Pid), diff --git a/deps/rabbit/src/rabbit_vm.erl b/deps/rabbit/src/rabbit_vm.erl index 28b507787d60..b6a8e1f4851b 100644 --- a/deps/rabbit/src/rabbit_vm.erl +++ b/deps/rabbit/src/rabbit_vm.erl @@ -209,11 +209,11 @@ all_vhosts_children(Name) -> Pid when is_pid(Pid) -> lists:filtermap( fun({_, VHostSupWrapper, _, _}) -> - case supervisor2:find_child(VHostSupWrapper, + case rabbit_misc:find_child(VHostSupWrapper, rabbit_vhost_sup) of [] -> false; [VHostSup] -> - case supervisor2:find_child(VHostSup, Name) of + case rabbit_misc:find_child(VHostSup, Name) of [QSup] -> {true, QSup}; [] -> false end diff --git a/deps/rabbit/test/crashing_queues_SUITE.erl b/deps/rabbit/test/crashing_queues_SUITE.erl index c756b0a73cd7..a6a4b577f34f 100644 --- a/deps/rabbit/test/crashing_queues_SUITE.erl +++ b/deps/rabbit/test/crashing_queues_SUITE.erl @@ -227,7 +227,7 @@ queue_pid(Node, QName) -> end. sup_child(Node, Sup) -> - case rpc:call(Node, supervisor2, which_children, [Sup]) of + case rpc:call(Node, supervisor, which_children, [Sup]) of [{_, Child, _, _}] -> {ok, Child}; [] -> {error, no_child}; {badrpc, {'EXIT', {noproc, _}}} -> {error, no_sup} diff --git a/deps/rabbit_common/src/rabbit_heartbeat.erl b/deps/rabbit_common/src/rabbit_heartbeat.erl index 67690ebd661a..0d8b36885077 100644 --- a/deps/rabbit_common/src/rabbit_heartbeat.erl +++ b/deps/rabbit_common/src/rabbit_heartbeat.erl @@ -105,7 +105,7 @@ start_heartbeater(0, _SupPid, _Sock, _TimeoutFun, _Name, _Callback, {ok, none}; start_heartbeater(TimeoutSec, SupPid, Sock, TimeoutFun, Name, Callback, Identity) -> - supervisor2:start_child( + supervisor:start_child( SupPid, {Name, {rabbit_heartbeat, Callback, [Sock, TimeoutSec, TimeoutFun, {Name, Identity}]}, diff --git a/deps/rabbit_common/src/rabbit_misc.erl b/deps/rabbit_common/src/rabbit_misc.erl index d0cc1cbc8e32..cd447e3d2944 100644 --- a/deps/rabbit_common/src/rabbit_misc.erl +++ b/deps/rabbit_common/src/rabbit_misc.erl @@ -83,6 +83,7 @@ -export([get_gc_info/1]). -export([group_proplists_by/2]). -export([raw_read_file/1]). +-export([find_child/2]). -export([is_regular_file/1]). %% Horrible macro to use in guards @@ -1435,6 +1436,14 @@ is_regular_file(Name) -> _ -> false end. +%% this used to be in supervisor2 +-spec find_child(Supervisor, Name) -> [pid()] when + Supervisor :: supervisor:sup_ref(), + Name :: supervisor:child_id(). +find_child(Supervisor, Name) -> + [Pid || {Name1, Pid, _Type, _Modules} <- supervisor:which_children(Supervisor), + Name1 =:= Name]. + %% ------------------------------------------------------------------------- %% Begin copypasta from gen_server2.erl diff --git a/deps/rabbit_common/src/supervisor2.erl b/deps/rabbit_common/src/supervisor2.erl index 05c0a3674ff0..d4a36c9e29c2 100644 --- a/deps/rabbit_common/src/supervisor2.erl +++ b/deps/rabbit_common/src/supervisor2.erl @@ -3,16 +3,14 @@ %% %% 1) the module name is supervisor2 %% -%% 2) a find_child/2 utility function has been added -%% -%% 3) Added an 'intrinsic' restart type. Like the transient type, this +%% 2) Added an 'intrinsic' restart type. Like the transient type, this %% type means the child should only be restarted if the child exits %% abnormally. Unlike the transient type, if the child exits %% normally, the supervisor itself also exits normally. If the %% child is a supervisor and it exits normally (i.e. with reason of %% 'shutdown') then the child's parent also exits normally. %% -%% 4) child specifications can contain, as the restart type, a tuple +%% 3) child specifications can contain, as the restart type, a tuple %% {permanent, Delay} | {transient, Delay} | {intrinsic, Delay} %% where Delay >= 0 (see point (4) below for intrinsic). The delay, %% in seconds, indicates what should happen if a child, upon being @@ -37,7 +35,7 @@ %% perspective it's a normal exit, whilst from supervisor's %% perspective, it's an abnormal exit. %% -%% 5) normal, and {shutdown, _} exit reasons are all treated the same +%% 4) normal, and {shutdown, _} exit reasons are all treated the same %% (i.e. are regarded as normal exits) %% %% All modifications are (C) 2010-2022 VMware, Inc. or its affiliates. @@ -69,8 +67,7 @@ start_child/2, restart_child/2, delete_child/2, terminate_child/2, which_children/1, count_children/1, - check_childspecs/1, get_childspec/2, - find_child/2]). + check_childspecs/1, get_childspec/2]). %% Internal exports -export([init/1, handle_call/3, handle_cast/2, handle_info/2, @@ -309,13 +306,6 @@ which_children(Supervisor) -> count_children(Supervisor) -> call(Supervisor, count_children). --spec find_child(Supervisor, Name) -> [pid()] when - Supervisor :: sup_ref(), - Name :: child_id(). -find_child(Supervisor, Name) -> - [Pid || {Name1, Pid, _Type, _Modules} <- which_children(Supervisor), - Name1 =:= Name]. - call(Supervisor, Req) -> gen_server:call(Supervisor, Req, infinity). diff --git a/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_reader.erl b/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_reader.erl index b4073580feb2..477f573db456 100644 --- a/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_reader.erl +++ b/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_reader.erl @@ -591,15 +591,19 @@ start_1_0_connection0(Mode, State = #v1{connection = Connection, helper_sup = HelperSup}) -> ChannelSupSupPid = case Mode of - sasl -> undefined; - amqp -> {ok, Pid} = - supervisor2:start_child( - HelperSup, - {channel_sup_sup, - {rabbit_amqp1_0_session_sup_sup, start_link, []}, - intrinsic, infinity, supervisor, - [rabbit_amqp1_0_session_sup_sup]}), - Pid + sasl -> + undefined; + amqp -> + StartMFA = {rabbit_amqp1_0_session_sup_sup, start_link, []}, + ChildSpec = #{id => channel_sup_sup, + start => StartMFA, + restart => transient, + significant => true, + shutdown => infinity, + type => supervisor, + modules => [rabbit_amqp1_0_session_sup_sup]}, + {ok, Pid} = supervisor:start_child(HelperSup, ChildSpec), + Pid end, switch_callback(State#v1{connection = Connection#v1_connection{ timeout_sec = ?NORMAL_TIMEOUT}, diff --git a/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_session_sup.erl b/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_session_sup.erl index 369a0bb0c350..24c5a2b1fa05 100644 --- a/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_session_sup.erl +++ b/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_session_sup.erl @@ -7,7 +7,7 @@ -module(rabbit_amqp1_0_session_sup). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/1]). @@ -29,24 +29,47 @@ %%---------------------------------------------------------------------------- start_link({amqp10_framing, Sock, Channel, FrameMax, ReaderPid, Username, VHost, Collector, ProxySocket}) -> - {ok, SupPid} = supervisor2:start_link(?MODULE, []), + {ok, SupPid} = supervisor:start_link(?MODULE, []), {ok, WriterPid} = - supervisor2:start_child( - SupPid, - {writer, {rabbit_amqp1_0_writer, start_link, - [Sock, Channel, FrameMax, amqp10_framing, - ReaderPid]}, - intrinsic, ?WORKER_WAIT, worker, [rabbit_amqp1_0_writer]}), + supervisor:start_child( + SupPid, + #{ + id => writer, + start => + {rabbit_amqp1_0_writer, start_link, [ + Sock, + Channel, + FrameMax, + amqp10_framing, + ReaderPid + ]}, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [rabbit_amqp1_0_writer] + } + ), SocketForAdapterInfo = case ProxySocket of undefined -> Sock; _ -> ProxySocket end, - case supervisor2:start_child( + case supervisor:start_child( SupPid, - {channel, {rabbit_amqp1_0_session_process, start_link, - [{Channel, ReaderPid, WriterPid, Username, VHost, FrameMax, - adapter_info(SocketForAdapterInfo), Collector}]}, - intrinsic, ?WORKER_WAIT, worker, [rabbit_amqp1_0_session_process]}) of + #{ + id => channel, + start => + {rabbit_amqp1_0_session_process, start_link, [ + {Channel, ReaderPid, WriterPid, Username, VHost, FrameMax, + adapter_info(SocketForAdapterInfo), Collector} + ]}, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [rabbit_amqp1_0_session_process] + } + ) of {ok, ChannelPid} -> {ok, SupPid, ChannelPid}; {error, Reason} -> @@ -56,7 +79,11 @@ start_link({amqp10_framing, Sock, Channel, FrameMax, ReaderPid, %%---------------------------------------------------------------------------- init([]) -> - {ok, {{one_for_all, 0, 1}, []}}. + SupFlags = #{strategy => one_for_all, + intensity => 0, + period => 1, + auto_shutdown => any_significant}, + {ok, {SupFlags, []}}. adapter_info(Sock) -> amqp_connection:socket_adapter_info(Sock, {'AMQP', "1.0"}). diff --git a/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_session_sup_sup.erl b/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_session_sup_sup.erl index e68344b3a5d5..08a49622edfa 100644 --- a/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_session_sup_sup.erl +++ b/deps/rabbitmq_amqp1_0/src/rabbit_amqp1_0_session_sup_sup.erl @@ -7,7 +7,7 @@ -module(rabbit_amqp1_0_session_sup_sup). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/0, start_session/2]). @@ -25,10 +25,10 @@ %%---------------------------------------------------------------------------- start_link() -> - supervisor2:start_link(?MODULE, []). + supervisor:start_link(?MODULE, []). start_session(Pid, Args) -> - supervisor2:start_child(Pid, [Args]). + supervisor:start_child(Pid, [Args]). %%---------------------------------------------------------------------------- diff --git a/deps/rabbitmq_mqtt/src/rabbit_mqtt_connection_sup.erl b/deps/rabbitmq_mqtt/src/rabbit_mqtt_connection_sup.erl index 898adc765735..79a939c5b044 100644 --- a/deps/rabbitmq_mqtt/src/rabbit_mqtt_connection_sup.erl +++ b/deps/rabbitmq_mqtt/src/rabbit_mqtt_connection_sup.erl @@ -7,7 +7,7 @@ -module(rabbit_mqtt_connection_sup). --behaviour(supervisor2). +-behaviour(supervisor). -behaviour(ranch_protocol). -include_lib("rabbit_common/include/rabbit.hrl"). @@ -19,25 +19,46 @@ %%---------------------------------------------------------------------------- start_link(Ref, _Transport, []) -> - {ok, SupPid} = supervisor2:start_link(?MODULE, []), - {ok, KeepaliveSup} = supervisor2:start_child( - SupPid, - {rabbit_mqtt_keepalive_sup, - {rabbit_mqtt_connection_sup, start_keepalive_link, []}, - intrinsic, infinity, supervisor, [rabbit_keepalive_sup]}), - {ok, ReaderPid} = supervisor2:start_child( - SupPid, - {rabbit_mqtt_reader, - {rabbit_mqtt_reader, start_link, [KeepaliveSup, Ref]}, - intrinsic, ?WORKER_WAIT, worker, [rabbit_mqtt_reader]}), + {ok, SupPid} = supervisor:start_link(?MODULE, []), + {ok, KeepaliveSup} = supervisor:start_child( + SupPid, + #{ + id => rabbit_mqtt_keepalive_sup, + start => {rabbit_mqtt_connection_sup, start_keepalive_link, []}, + restart => transient, + significant => true, + shutdown => infinity, + type => supervisor, + modules => [rabbit_keepalive_sup] + } + ), + {ok, ReaderPid} = supervisor:start_child( + SupPid, + #{ + id => rabbit_mqtt_reader, + start => {rabbit_mqtt_reader, start_link, [KeepaliveSup, Ref]}, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [rabbit_mqtt_reader] + } + ), {ok, SupPid, ReaderPid}. start_keepalive_link() -> - supervisor2:start_link(?MODULE, []). + supervisor:start_link(?MODULE, []). %%---------------------------------------------------------------------------- init([]) -> - {ok, {{one_for_all, 0, 1}, []}}. - - + {ok, + { + #{ + strategy => one_for_all, + intensity => 0, + period => 1, + auto_shutdown => any_significant + }, + [] + }}. diff --git a/deps/rabbitmq_mqtt/src/rabbit_mqtt_retainer_sup.erl b/deps/rabbitmq_mqtt/src/rabbit_mqtt_retainer_sup.erl index 7122e7c08f4c..e42c2a030775 100644 --- a/deps/rabbitmq_mqtt/src/rabbit_mqtt_retainer_sup.erl +++ b/deps/rabbitmq_mqtt/src/rabbit_mqtt_retainer_sup.erl @@ -6,18 +6,18 @@ %% -module(rabbit_mqtt_retainer_sup). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/1, init/1, start_child/2,start_child/1, child_for_vhost/1, delete_child/1]). -define(ENCODING, utf8). --spec start_child(binary()) -> supervisor2:startchild_ret(). --spec start_child(term(), binary()) -> supervisor2:startchild_ret(). +-spec start_child(binary()) -> supervisor:startchild_ret(). +-spec start_child(term(), binary()) -> supervisor:startchild_ret(). start_link(SupName) -> - supervisor2:start_link(SupName, ?MODULE, []). + supervisor:start_link(SupName, ?MODULE, []). child_for_vhost(VHost) when is_binary(VHost) -> case rabbit_mqtt_retainer_sup:start_child(VHost) of @@ -29,28 +29,45 @@ start_child(VHost) when is_binary(VHost) -> start_child(rabbit_mqtt_retainer:store_module(), VHost). start_child(RetainStoreMod, VHost) -> - supervisor2:start_child(?MODULE, - - {vhost_to_atom(VHost), - {rabbit_mqtt_retainer, start_link, [RetainStoreMod, VHost]}, - permanent, 60, worker, [rabbit_mqtt_retainer]}). + supervisor:start_child( + ?MODULE, + #{ + id => vhost_to_atom(VHost), + start => {rabbit_mqtt_retainer, start_link, [RetainStoreMod, VHost]}, + restart => permanent, + shutdown => 60, + type => worker, + modules => [rabbit_mqtt_retainer] + } + ). delete_child(VHost) -> Id = vhost_to_atom(VHost), - ok = supervisor2:terminate_child(?MODULE, Id), - ok = supervisor2:delete_child(?MODULE, Id). + ok = supervisor:terminate_child(?MODULE, Id), + ok = supervisor:delete_child(?MODULE, Id). init([]) -> Mod = rabbit_mqtt_retainer:store_module(), rabbit_log:info("MQTT retained message store: ~p", [Mod]), - {ok, {{one_for_one, 5, 5}, child_specs(Mod, rabbit_vhost:list_names())}}. + {ok, { + #{strategy => one_for_one, intensity => 5, period => 5}, + child_specs(Mod, rabbit_vhost:list_names()) + }}. child_specs(Mod, VHosts) -> - %% see start_child/2 - [{vhost_to_atom(V), - {rabbit_mqtt_retainer, start_link, [Mod, V]}, - permanent, infinity, worker, [rabbit_mqtt_retainer]} || V <- VHosts]. + %% see start_child/2 + [ + #{ + id => vhost_to_atom(V), + start => {rabbit_mqtt_retainer, start_link, [Mod, V]}, + restart => permanent, + shutdown => infinity, + type => worker, + modules => [rabbit_mqtt_retainer] + } + || V <- VHosts + ]. vhost_to_atom(VHost) -> %% we'd like to avoid any conversion here because diff --git a/deps/rabbitmq_mqtt/src/rabbit_mqtt_sup.erl b/deps/rabbitmq_mqtt/src/rabbit_mqtt_sup.erl index 50b077810ffa..d76af71b061f 100644 --- a/deps/rabbitmq_mqtt/src/rabbit_mqtt_sup.erl +++ b/deps/rabbitmq_mqtt/src/rabbit_mqtt_sup.erl @@ -6,7 +6,7 @@ %% -module(rabbit_mqtt_sup). --behaviour(supervisor2). +-behaviour(supervisor). -include_lib("rabbit_common/include/rabbit.hrl"). @@ -16,7 +16,7 @@ -define(TLS_PROTOCOL, 'mqtt/ssl'). start_link(Listeners, []) -> - supervisor2:start_link({local, ?MODULE}, ?MODULE, [Listeners]). + supervisor:start_link({local, ?MODULE}, ?MODULE, [Listeners]). init([{Listeners, SslListeners0}]) -> NumTcpAcceptors = application:get_env(rabbitmq_mqtt, num_tcp_acceptors, 10), @@ -32,15 +32,28 @@ init([{Listeners, SslListeners0}]) -> danger -> [] end} end, - {ok, {{one_for_all, 10, 10}, - [{rabbit_mqtt_retainer_sup, - {rabbit_mqtt_retainer_sup, start_link, [{local, rabbit_mqtt_retainer_sup}]}, - transient, ?SUPERVISOR_WAIT, supervisor, [rabbit_mqtt_retainer_sup]} | - listener_specs(fun tcp_listener_spec/1, - [SocketOpts, NumTcpAcceptors, ConcurrentConnsSups], Listeners) ++ - listener_specs(fun ssl_listener_spec/1, - [SocketOpts, SslOpts, NumSslAcceptors, ConcurrentConnsSups], - SslListeners)]}}. + {ok, + {#{strategy => one_for_all, intensity => 10, period => 10}, [ + #{ + id => rabbit_mqtt_retainer_sup, + start => + {rabbit_mqtt_retainer_sup, start_link, [{local, rabbit_mqtt_retainer_sup}]}, + restart => transient, + shutdown => ?SUPERVISOR_WAIT, + type => supervisor, + modules => [rabbit_mqtt_retainer_sup] + } + | listener_specs( + fun tcp_listener_spec/1, + [SocketOpts, NumTcpAcceptors, ConcurrentConnsSups], + Listeners + ) ++ + listener_specs( + fun ssl_listener_spec/1, + [SocketOpts, SslOpts, NumSslAcceptors, ConcurrentConnsSups], + SslListeners + ) + ]}}. stop_listeners() -> rabbit_networking:stop_ranch_listener_of_protocol(?TCP_PROTOCOL), @@ -52,21 +65,39 @@ stop_listeners() -> %% listener_specs(Fun, Args, Listeners) -> - [Fun([Address | Args]) || - Listener <- Listeners, - Address <- rabbit_networking:tcp_listener_addresses(Listener)]. + [ + Fun([Address | Args]) + || Listener <- Listeners, + Address <- rabbit_networking:tcp_listener_addresses(Listener) + ]. tcp_listener_spec([Address, SocketOpts, NumAcceptors, ConcurrentConnsSups]) -> rabbit_networking:tcp_listener_spec( - rabbit_mqtt_listener_sup, Address, SocketOpts, - transport(?TCP_PROTOCOL), rabbit_mqtt_connection_sup, [], - mqtt, NumAcceptors, ConcurrentConnsSups, "MQTT TCP listener"). + rabbit_mqtt_listener_sup, + Address, + SocketOpts, + transport(?TCP_PROTOCOL), + rabbit_mqtt_connection_sup, + [], + mqtt, + NumAcceptors, + ConcurrentConnsSups, + "MQTT TCP listener" + ). ssl_listener_spec([Address, SocketOpts, SslOpts, NumAcceptors, ConcurrentConnsSups]) -> rabbit_networking:tcp_listener_spec( - rabbit_mqtt_listener_sup, Address, SocketOpts ++ SslOpts, - transport(?TLS_PROTOCOL), rabbit_mqtt_connection_sup, [], - 'mqtt/ssl', NumAcceptors, ConcurrentConnsSups, "MQTT TLS listener"). + rabbit_mqtt_listener_sup, + Address, + SocketOpts ++ SslOpts, + transport(?TLS_PROTOCOL), + rabbit_mqtt_connection_sup, + [], + 'mqtt/ssl', + NumAcceptors, + ConcurrentConnsSups, + "MQTT TLS listener" + ). transport(Protocol) -> case Protocol of diff --git a/deps/rabbitmq_shovel/src/rabbit_shovel_sup.erl b/deps/rabbitmq_shovel/src/rabbit_shovel_sup.erl index 5a55ad798201..3a7591a06efa 100644 --- a/deps/rabbitmq_shovel/src/rabbit_shovel_sup.erl +++ b/deps/rabbitmq_shovel/src/rabbit_shovel_sup.erl @@ -6,7 +6,7 @@ %% -module(rabbit_shovel_sup). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/0, init/1]). @@ -17,35 +17,49 @@ start_link() -> case parse_configuration(application:get_env(shovels)) of {ok, Configurations} -> - supervisor2:start_link({local, ?MODULE}, ?MODULE, [Configurations]); + supervisor:start_link({local, ?MODULE}, ?MODULE, [Configurations]); {error, Reason} -> {error, Reason} end. init([Configurations]) -> Len = dict:size(Configurations), - ChildSpecs = [{rabbit_shovel_status, - {rabbit_shovel_status, start_link, []}, - transient, 16#ffffffff, worker, - [rabbit_shovel_status]}, - {rabbit_shovel_dyn_worker_sup_sup, - {rabbit_shovel_dyn_worker_sup_sup, start_link, []}, - transient, 16#ffffffff, supervisor, - [rabbit_shovel_dyn_worker_sup_sup]} | - make_child_specs(Configurations)], - {ok, {{one_for_one, 2*Len, 2}, ChildSpecs}}. + ChildSpecs = [ + #{ + id => rabbit_shovel_status, + start => {rabbit_shovel_status, start_link, []}, + restart => transient, + shutdown => 16#ffffffff, + type => worker, + modules => [rabbit_shovel_status] + }, + #{ + id => rabbit_shovel_dyn_worker_sup_sup, + start => {rabbit_shovel_dyn_worker_sup_sup, start_link, []}, + restart => transient, + shutdown => 16#ffffffff, + type => supervisor, + modules => [rabbit_shovel_dyn_worker_sup_sup] + } + | make_child_specs(Configurations) + ], + {ok, {#{strategy => one_for_one, intensity => 2 * Len, period => 2}, ChildSpecs}}. make_child_specs(Configurations) -> dict:fold( fun (ShovelName, ShovelConfig, Acc) -> - [{ShovelName, - {rabbit_shovel_worker_sup, start_link, - [ShovelName, ShovelConfig]}, - permanent, - 16#ffffffff, - supervisor, - [rabbit_shovel_worker_sup]} | Acc] - end, [], Configurations). + [ + #{ + id => ShovelName, + start => {rabbit_shovel_worker_sup, start_link, [ShovelName, ShovelConfig]}, + restart => permanent, + shutdown => 16#ffffffff, + type => supervisor, + modules => [rabbit_shovel_worker_sup] + } + | Acc + ] + end, [], Configurations). parse_configuration(undefined) -> {ok, dict:new()}; @@ -55,20 +69,23 @@ parse_configuration({ok, Env}) -> parse_configuration(_Defaults, [], Acc) -> {ok, Acc}; -parse_configuration(Defaults, [{ShovelName, ShovelConfig} | Env], Acc) - when is_atom(ShovelName) andalso is_list(ShovelConfig) -> +parse_configuration(Defaults, [{ShovelName, ShovelConfig} | Env], Acc) when + is_atom(ShovelName) andalso is_list(ShovelConfig) +-> case dict:is_key(ShovelName, Acc) of - true -> {error, {duplicate_shovel_definition, ShovelName}}; - false -> case validate_shovel_config(ShovelName, ShovelConfig) of - {ok, Shovel} -> - %% make sure the config we accumulate has any - %% relevant default values (discovered during - %% validation), applied back to it - Acc2 = dict:store(ShovelName, Shovel, Acc), - parse_configuration(Defaults, Env, Acc2); - Error -> - Error - end + true -> + {error, {duplicate_shovel_definition, ShovelName}}; + false -> + case validate_shovel_config(ShovelName, ShovelConfig) of + {ok, Shovel} -> + %% make sure the config we accumulate has any + %% relevant default values (discovered during + %% validation), applied back to it + Acc2 = dict:store(ShovelName, Shovel, Acc), + parse_configuration(Defaults, Env, Acc2); + Error -> + Error + end end; parse_configuration(_Defaults, _, _Acc) -> {error, require_list_of_shovel_configurations}. diff --git a/deps/rabbitmq_stomp/src/rabbit_stomp.erl b/deps/rabbitmq_stomp/src/rabbit_stomp.erl index 68ae2ba480e7..3a414762e6ce 100644 --- a/deps/rabbitmq_stomp/src/rabbit_stomp.erl +++ b/deps/rabbitmq_stomp/src/rabbit_stomp.erl @@ -115,10 +115,10 @@ report_configuration(#stomp_configuration{ list() -> [Client || - {_, ListSup, _, _} <- supervisor2:which_children(rabbit_stomp_sup), - {_, RanchEmbeddedSup, supervisor, _} <- supervisor2:which_children(ListSup), + {_, ListSup, _, _} <- supervisor:which_children(rabbit_stomp_sup), + {_, RanchEmbeddedSup, supervisor, _} <- supervisor:which_children(ListSup), {{ranch_listener_sup, _}, RanchListSup, _, _} <- supervisor:which_children(RanchEmbeddedSup), - {ranch_conns_sup_sup, RanchConnsSup, supervisor, _} <- supervisor2:which_children(RanchListSup), - {_, RanchConnSup, supervisor, _} <- supervisor2:which_children(RanchConnsSup), - {_, StompClientSup, supervisor, _} <- supervisor2:which_children(RanchConnSup), + {ranch_conns_sup_sup, RanchConnsSup, supervisor, _} <- supervisor:which_children(RanchListSup), + {_, RanchConnSup, supervisor, _} <- supervisor:which_children(RanchConnsSup), + {_, StompClientSup, supervisor, _} <- supervisor:which_children(RanchConnSup), {rabbit_stomp_reader, Client, _, _} <- supervisor:which_children(StompClientSup)]. diff --git a/deps/rabbitmq_stomp/src/rabbit_stomp_client_sup.erl b/deps/rabbitmq_stomp/src/rabbit_stomp_client_sup.erl index 924b284040a5..4e4c977350db 100644 --- a/deps/rabbitmq_stomp/src/rabbit_stomp_client_sup.erl +++ b/deps/rabbitmq_stomp/src/rabbit_stomp_client_sup.erl @@ -6,7 +6,7 @@ %% -module(rabbit_stomp_client_sup). --behaviour(supervisor2). +-behaviour(supervisor). -behaviour(ranch_protocol). -include_lib("rabbit_common/include/rabbit.hrl"). @@ -14,28 +14,48 @@ -export([start_link/3, init/1]). start_link(Ref, _Transport, Configuration) -> - {ok, SupPid} = supervisor2:start_link(?MODULE, []), + {ok, SupPid} = supervisor:start_link(?MODULE, []), {ok, HelperPid} = - supervisor2:start_child(SupPid, - {rabbit_stomp_heartbeat_sup, - {rabbit_connection_helper_sup, start_link, []}, - intrinsic, infinity, supervisor, - [rabbit_connection_helper_sup]}), + supervisor:start_child( + SupPid, + #{ + id => rabbit_stomp_heartbeat_sup, + start => {rabbit_connection_helper_sup, start_link, []}, + restart => transient, + significant => true, + shutdown => infinity, + type => supervisor, + modules => [rabbit_connection_helper_sup] + } + ), %% We want the reader to be transient since when it exits normally %% the processor may have some work still to do (and the reader %% tells the processor to exit). However, if the reader terminates %% abnormally then we want to take everything down. - {ok, ReaderPid} = supervisor2:start_child( - SupPid, - {rabbit_stomp_reader, - {rabbit_stomp_reader, - start_link, [HelperPid, Ref, Configuration]}, - intrinsic, ?WORKER_WAIT, worker, - [rabbit_stomp_reader]}), + {ok, ReaderPid} = supervisor:start_child( + SupPid, + #{ + id => rabbit_stomp_reader, + start => {rabbit_stomp_reader, start_link, [HelperPid, Ref, Configuration]}, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [rabbit_stomp_reader] + } + ), {ok, SupPid, ReaderPid}. init([]) -> - {ok, {{one_for_all, 0, 1}, []}}. - + {ok, + { + #{ + strategy => one_for_all, + intensity => 0, + period => 1, + auto_shutdown => any_significant + }, + [] + }}. diff --git a/deps/rabbitmq_stream/src/rabbit_stream.erl b/deps/rabbitmq_stream/src/rabbit_stream.erl index 5d1a0e9e67a7..4a03b9537970 100644 --- a/deps/rabbitmq_stream/src/rabbit_stream.erl +++ b/deps/rabbitmq_stream/src/rabbit_stream.erl @@ -208,17 +208,17 @@ emit_publisher_info_local(VHost, Items, Ref, AggregatorPid) -> list(VHost) -> [Client || {_, ListSup, _, _} - <- supervisor2:which_children(rabbit_stream_sup), + <- supervisor:which_children(rabbit_stream_sup), {_, RanchEmbeddedSup, supervisor, _} - <- supervisor2:which_children(ListSup), + <- supervisor:which_children(ListSup), {{ranch_listener_sup, _}, RanchListSup, _, _} <- supervisor:which_children(RanchEmbeddedSup), {ranch_conns_sup_sup, RanchConnsSup, supervisor, _} - <- supervisor2:which_children(RanchListSup), + <- supervisor:which_children(RanchListSup), {_, RanchConnSup, supervisor, _} - <- supervisor2:which_children(RanchConnsSup), + <- supervisor:which_children(RanchConnsSup), {_, StreamClientSup, supervisor, _} - <- supervisor2:which_children(RanchConnSup), + <- supervisor:which_children(RanchConnSup), {rabbit_stream_reader, Client, _, _} <- supervisor:which_children(StreamClientSup), rabbit_stream_reader:in_vhost(Client, VHost)]. diff --git a/deps/rabbitmq_stream/src/rabbit_stream_connection_sup.erl b/deps/rabbitmq_stream/src/rabbit_stream_connection_sup.erl index cf68aa307c04..f583151d5625 100644 --- a/deps/rabbitmq_stream/src/rabbit_stream_connection_sup.erl +++ b/deps/rabbitmq_stream/src/rabbit_stream_connection_sup.erl @@ -16,41 +16,60 @@ -module(rabbit_stream_connection_sup). --behaviour(supervisor2). +-behaviour(supervisor). -behaviour(ranch_protocol). -include_lib("rabbit_common/include/rabbit.hrl"). --export([start_link/3, - start_keepalive_link/0]). +-export([ + start_link/3, + start_keepalive_link/0 +]). -export([init/1]). start_link(Ref, Transport, Opts) -> - {ok, SupPid} = supervisor2:start_link(?MODULE, []), + {ok, SupPid} = supervisor:start_link(?MODULE, []), {ok, KeepaliveSup} = - supervisor2:start_child(SupPid, - {rabbit_stream_keepalive_sup, - {rabbit_stream_connection_sup, - start_keepalive_link, []}, - intrinsic, - infinity, - supervisor, - [rabbit_keepalive_sup]}), + supervisor:start_child( + SupPid, + #{ + id => rabbit_stream_keepalive_sup, + start => {rabbit_stream_connection_sup, start_keepalive_link, []}, + restart => transient, + significant => true, + shutdown => infinity, + type => supervisor, + modules => [rabbit_keepalive_sup] + } + ), {ok, ReaderPid} = - supervisor2:start_child(SupPid, - {rabbit_stream_reader, - {rabbit_stream_reader, start_link, - [KeepaliveSup, Transport, Ref, Opts]}, - intrinsic, - ?WORKER_WAIT, - worker, - [rabbit_stream_reader]}), + supervisor:start_child( + SupPid, + #{ + id => rabbit_stream_reader, + start => {rabbit_stream_reader, start_link, [KeepaliveSup, Transport, Ref, Opts]}, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [rabbit_stream_reader] + } + ), {ok, SupPid, ReaderPid}. start_keepalive_link() -> - supervisor2:start_link(?MODULE, []). + supervisor:start_link(?MODULE, []). %%---------------------------------------------------------------------------- init([]) -> - {ok, {{one_for_all, 0, 1}, []}}. + {ok, + { + #{ + strategy => one_for_all, + intensity => 0, + period => 1, + auto_shutdown => any_significant + }, + [] + }}. diff --git a/deps/rabbitmq_tracing/src/rabbit_tracing_consumer_sup.erl b/deps/rabbitmq_tracing/src/rabbit_tracing_consumer_sup.erl index 7b77751b57e1..a246f04f9ec5 100644 --- a/deps/rabbitmq_tracing/src/rabbit_tracing_consumer_sup.erl +++ b/deps/rabbitmq_tracing/src/rabbit_tracing_consumer_sup.erl @@ -14,7 +14,7 @@ -export([start_link/1]). -export([init/1]). -start_link(Args) -> supervisor2:start_link(?MODULE, Args). +start_link(Args) -> supervisor:start_link(?MODULE, Args). %%---------------------------------------------------------------------------- diff --git a/deps/rabbitmq_web_mqtt/src/rabbit_web_mqtt_connection_sup.erl b/deps/rabbitmq_web_mqtt/src/rabbit_web_mqtt_connection_sup.erl index 51e8a41c0227..a6d9484bc9f5 100644 --- a/deps/rabbitmq_web_mqtt/src/rabbit_web_mqtt_connection_sup.erl +++ b/deps/rabbitmq_web_mqtt/src/rabbit_web_mqtt_connection_sup.erl @@ -7,7 +7,7 @@ -module(rabbit_web_mqtt_connection_sup). --behaviour(supervisor2). +-behaviour(supervisor). -behaviour(ranch_protocol). -include_lib("rabbit_common/include/rabbit.hrl"). @@ -19,12 +19,19 @@ %%---------------------------------------------------------------------------- start_link(Ref, Transport, CowboyOpts0) -> - {ok, SupPid} = supervisor2:start_link(?MODULE, []), - {ok, KeepaliveSup} = supervisor2:start_child( - SupPid, - {rabbit_web_mqtt_keepalive_sup, - {?MODULE, start_keepalive_link, []}, - intrinsic, infinity, supervisor, [rabbit_keepalive_sup]}), + {ok, SupPid} = supervisor:start_link(?MODULE, []), + {ok, KeepaliveSup} = supervisor:start_child( + SupPid, + #{ + id => rabbit_web_mqtt_keepalive_sup, + start => {?MODULE, start_keepalive_link, []}, + restart => transient, + significant => true, + shutdown => infinity, + type => supervisor, + modules => [rabbit_keepalive_sup] + } + ), %% In order for the Websocket handler to receive the KeepaliveSup %% variable, we need to pass it first through the environment and @@ -36,17 +43,33 @@ start_link(Ref, Transport, CowboyOpts0) -> ranch_tcp -> cowboy_clear; ranch_ssl -> cowboy_tls end, - {ok, ReaderPid} = supervisor2:start_child( - SupPid, - {Protocol, - {Protocol, start_link, [Ref, Transport, CowboyOpts]}, - intrinsic, ?WORKER_WAIT, worker, [Protocol]}), + {ok, ReaderPid} = supervisor:start_child( + SupPid, + #{ + id => Protocol, + start => {Protocol, start_link, [Ref, Transport, CowboyOpts]}, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [Protocol] + } + ), {ok, SupPid, ReaderPid}. start_keepalive_link() -> - supervisor2:start_link(?MODULE, []). + supervisor:start_link(?MODULE, []). %%---------------------------------------------------------------------------- init([]) -> - {ok, {{one_for_all, 0, 1}, []}}. + {ok, + { + #{ + strategy => one_for_all, + intensity => 0, + period => 1, + auto_shutdown => any_significant + }, + [] + }}. diff --git a/deps/rabbitmq_web_stomp/src/rabbit_web_stomp_connection_sup.erl b/deps/rabbitmq_web_stomp/src/rabbit_web_stomp_connection_sup.erl index 6de898b24774..007f641eaf42 100644 --- a/deps/rabbitmq_web_stomp/src/rabbit_web_stomp_connection_sup.erl +++ b/deps/rabbitmq_web_stomp/src/rabbit_web_stomp_connection_sup.erl @@ -7,7 +7,7 @@ -module(rabbit_web_stomp_connection_sup). --behaviour(supervisor2). +-behaviour(supervisor). -behaviour(ranch_protocol). -include_lib("rabbit_common/include/rabbit.hrl"). @@ -18,12 +18,16 @@ %%---------------------------------------------------------------------------- start_link(Ref, Transport, CowboyOpts0) -> - {ok, SupPid} = supervisor2:start_link(?MODULE, []), - {ok, KeepaliveSup} = supervisor2:start_child( - SupPid, - {rabbit_web_stomp_keepalive_sup, - {?MODULE, start_keepalive_link, []}, - intrinsic, infinity, supervisor, [rabbit_keepalive_sup]}), + {ok, SupPid} = supervisor:start_link(?MODULE, []), + StartMFA = {?MODULE, start_keepalive_link, []}, + ChildSpec = #{id => rabbit_web_stomp_keepalive_sup, + start => StartMFA, + restart => transient, + significant => true, + shutdown => infinity, + type => supervisor, + modules => [rabbit_keepalive_sup]}, + {ok, KeepaliveSup} = supervisor:start_child(SupPid, ChildSpec), %% In order for the Websocket handler to receive the KeepaliveSup %% variable, we need to pass it first through the environment and %% then have the middleware rabbit_web_mqtt_middleware place it @@ -35,17 +39,25 @@ start_link(Ref, Transport, CowboyOpts0) -> ranch_tcp -> cowboy_clear; ranch_ssl -> cowboy_tls end, - {ok, ReaderPid} = supervisor2:start_child( - SupPid, - {Protocol, - {Protocol, start_link, [Ref, Transport, CowboyOpts]}, - intrinsic, ?WORKER_WAIT, worker, [Protocol]}), + StartMFA = {Protocol, start_link, [Ref, Transport, CowboyOpts]}, + ChildSpec = #{id => Protocol, + start => StartMFA, + restart => transient, + significant => true, + shutdown => ?WORKER_WAIT, + type => worker, + modules => [Protocol]}, + {ok, ReaderPid} = supervisor:start_child(SupPid, ChildSpec), {ok, SupPid, ReaderPid}. start_keepalive_link() -> - supervisor2:start_link(?MODULE, []). + supervisor:start_link(?MODULE, []). %%---------------------------------------------------------------------------- init([]) -> - {ok, {{one_for_all, 0, 1}, []}}. + SupFlags = #{strategy => one_for_all, + intensity => 0, + period => 1, + auto_shutdown => any_significant}, + {ok, {SupFlags, []}}. diff --git a/deps/rabbitmq_web_stomp/src/rabbit_web_stomp_sup.erl b/deps/rabbitmq_web_stomp/src/rabbit_web_stomp_sup.erl index e900ccaf2e61..191355904a46 100644 --- a/deps/rabbitmq_web_stomp/src/rabbit_web_stomp_sup.erl +++ b/deps/rabbitmq_web_stomp/src/rabbit_web_stomp_sup.erl @@ -6,7 +6,7 @@ %% -module(rabbit_web_stomp_sup). --behaviour(supervisor2). +-behaviour(supervisor). -export([start_link/0, init/1]). @@ -16,7 +16,7 @@ -spec start_link() -> ignore | {'ok', pid()} | {'error', any()}. start_link() -> - supervisor2:start_link({local, ?SUP_NAME}, ?MODULE, []). + supervisor:start_link({local, ?SUP_NAME}, ?MODULE, []). init([]) -> {ok, {{one_for_one, 1, 5}, []}}.