Skip to content

Commit 926a875

Browse files
committed
Fix dyn shovel child_exists check for old id format
Because the clause `({{_, N}, _, _, _}) -> N =:= Name;` matches both new and old id format but always returns false for old id format, `child_exists` also returned false for old ids. Also rename SupId to ChildId to be pedantically correct.
1 parent 0d43c93 commit 926a875

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

deps/rabbitmq_shovel/src/rabbit_shovel_dyn_worker_sup_sup.erl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ obfuscated_uris_parameters(Def) when is_list(Def) ->
6060
rabbit_shovel_parameters:obfuscate_uris_in_definition(Def).
6161

6262
child_exists(Name) ->
63-
lists:any(fun ({{_, N}, _, _, _}) -> N =:= Name;
64-
%% older format, pre 3.13.0 and 3.12.8. See rabbitmq/rabbitmq-server#9894.
65-
({N, _, _, _}) -> N =:= Name
63+
Id = id(Name),
64+
%% older format, pre 3.13.0 and 3.12.8. See rabbitmq/rabbitmq-server#9894.
65+
OldId = old_id(Name),
66+
lists:any(fun ({ChildId, _, _, _}) ->
67+
ChildId =:= Id orelse ChildId =:= OldId
6668
end,
6769
mirrored_supervisor:which_children(?SUPERVISOR)).
6870

@@ -100,21 +102,21 @@ stop_child({VHost, ShovelName} = Name) ->
100102
cleanup_specs() ->
101103
Children = mirrored_supervisor:which_children(?SUPERVISOR),
102104

103-
SupIdSet = sets:from_list([element(1, S) || S <- Children]),
105+
ChildIdSet = sets:from_list([element(1, S) || S <- Children]),
104106
ParamsSet = params_to_child_ids(rabbit_khepri:is_enabled()),
105-
F = fun(SupId, ok) ->
107+
F = fun(ChildId, ok) ->
106108
try
107109
%% The supervisor operation is very unlikely to fail, it's the schema
108110
%% data stores that can make a fuss about a non-existent or non-standard value passed in.
109111
%% For example, an old style Shovel name is an invalid Khepri query path element. MK.
110-
_ = mirrored_supervisor:delete_child(?SUPERVISOR, SupId)
112+
_ = mirrored_supervisor:delete_child(?SUPERVISOR, ChildId)
111113
catch _:_:_Stacktrace ->
112114
ok
113115
end,
114116
ok
115117
end,
116118
%% Delete any supervisor children that do not have their respective runtime parameters in the database.
117-
SetToCleanUp = sets:subtract(SupIdSet, ParamsSet),
119+
SetToCleanUp = sets:subtract(ChildIdSet, ParamsSet),
118120
ok = sets:fold(F, ok, SetToCleanUp).
119121

120122
params_to_child_ids(_KhepriEnabled = true) ->

0 commit comments

Comments
 (0)