Skip to content

Commit

Permalink
Fix stop_child when Khepri is enabled
Browse files Browse the repository at this point in the history
It is assumed that old child id format cannot exist in this case.
  • Loading branch information
gomoripeti committed Dec 2, 2023
1 parent 8fdd693 commit 1fdfad9
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions deps/rabbitmq_shovel/src/rabbit_shovel_dyn_worker_sup_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,18 @@ stop_child({VHost, ShovelName} = Name) ->
case get({shovel_worker_autodelete, Name}) of
true -> ok; %% [1]
_ ->
case mirrored_supervisor:terminate_child(?SUPERVISOR, id(Name)) of
case stop_and_delete_child(id(Name)) of
ok ->
ok = mirrored_supervisor:delete_child(?SUPERVISOR, id(Name));
ok;
{error, not_found} ->
%% try older format, pre 3.13.0 and 3.12.8. See rabbitmq/rabbitmq-server#9894.
case mirrored_supervisor:terminate_child(?SUPERVISOR, old_id(Name)) of
ok ->
ok = mirrored_supervisor:delete_child(?SUPERVISOR, old_id(Name));
{error, not_found} ->
case rabbit_khepri:is_enabled() of
true ->
%% Old id format is not supported by and cannot exist in Khepri
ok;
false ->
%% try older format, pre 3.13.0 and 3.12.8.
%% See rabbitmq/rabbitmq-server#9894.
stop_and_delete_child(old_id(Name)),
ok
end
end,
Expand All @@ -91,6 +94,14 @@ stop_child({VHost, ShovelName} = Name) ->
rabbit_shovel_locks:unlock(LockId),
ok.

stop_and_delete_child(Id) ->
case mirrored_supervisor:terminate_child(?SUPERVISOR, Id) of
ok ->
ok = mirrored_supervisor:delete_child(?SUPERVISOR, Id);
{error, not_found} = Error ->
Error
end.

%% [1] An autodeleting worker removes its own parameter, and thus ends
%% up here via the parameter callback. It is a transient worker that
%% is just about to terminate normally - so we don't need to tell the
Expand Down

0 comments on commit 1fdfad9

Please sign in to comment.