Skip to content

Commit f384947

Browse files
Merge pull request #9800 from rabbitmq/mergify/bp/v3.11.x/pr-9796
Speed up shovel start (backport #9785) (backport #9796)
2 parents 24e2122 + 1ca008e commit f384947

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

deps/rabbitmq_shovel/src/rabbit_shovel_dyn_worker_sup_sup.erl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ start_child({VHost, ShovelName} = Name, Def) ->
4343
rabbit_log_shovel:debug("Starting a mirrored supervisor named '~s' in virtual host '~s'", [ShovelName, VHost]),
4444
Result = case mirrored_supervisor:start_child(
4545
?SUPERVISOR,
46-
{Name, {rabbit_shovel_dyn_worker_sup, start_link, [Name, obfuscated_uris_parameters(Def)]},
46+
{id(Name), {rabbit_shovel_dyn_worker_sup, start_link, [Name, obfuscated_uris_parameters(Def)]},
4747
transient, ?WORKER_WAIT, worker, [rabbit_shovel_dyn_worker_sup]}) of
4848
{ok, _Pid} -> ok;
4949
{error, {already_started, _Pid}} -> ok
@@ -58,7 +58,7 @@ obfuscated_uris_parameters(Def) when is_list(Def) ->
5858
rabbit_shovel_parameters:obfuscate_uris_in_definition(Def).
5959

6060
child_exists(Name) ->
61-
lists:any(fun ({N, _, _, _}) -> N =:= Name end,
61+
lists:any(fun ({{_, N}, _, _, _}) -> N =:= Name end,
6262
mirrored_supervisor:which_children(?SUPERVISOR)).
6363

6464
stop_child({VHost, ShovelName} = Name) ->
@@ -67,8 +67,8 @@ stop_child({VHost, ShovelName} = Name) ->
6767
case get({shovel_worker_autodelete, Name}) of
6868
true -> ok; %% [1]
6969
_ ->
70-
ok = mirrored_supervisor:terminate_child(?SUPERVISOR, Name),
71-
ok = mirrored_supervisor:delete_child(?SUPERVISOR, Name),
70+
ok = mirrored_supervisor:terminate_child(?SUPERVISOR, id(Name)),
71+
ok = mirrored_supervisor:delete_child(?SUPERVISOR, id(Name)),
7272
rabbit_shovel_status:remove(Name)
7373
end,
7474
rabbit_shovel_locks:unlock(LockId),
@@ -83,10 +83,11 @@ stop_child({VHost, ShovelName} = Name) ->
8383
%% See rabbit_shovel_worker:terminate/2
8484

8585
cleanup_specs() ->
86-
SpecsSet = sets:from_list([element(1, S) || S <- mirrored_supervisor:which_children(?SUPERVISOR)]),
87-
ParamsSet = sets:from_list(rabbit_runtime_parameters:list_component(<<"shovel">>)),
88-
F = fun(Spec, ok) ->
89-
_ = mirrored_supervisor:delete_child(?SUPERVISOR, Spec),
86+
SpecsSet = sets:from_list([element(2, element(1, S)) || S <- mirrored_supervisor:which_children(?SUPERVISOR)]),
87+
ParamsSet = sets:from_list([ {proplists:get_value(vhost, S), proplists:get_value(name, S)}
88+
|| S <- rabbit_runtime_parameters:list_component(<<"shovel">>) ]),
89+
F = fun(Name, ok) ->
90+
_ = mirrored_supervisor:delete_child(?SUPERVISOR, id(Name)),
9091
ok
9192
end,
9293
ok = sets:fold(F, ok, sets:subtract(SpecsSet, ParamsSet)).
@@ -95,3 +96,6 @@ cleanup_specs() ->
9596

9697
init([]) ->
9798
{ok, {{one_for_one, 3, 10}, []}}.
99+
100+
id({V, S} = Name) ->
101+
{[V, S], Name}.

0 commit comments

Comments
 (0)