Skip to content

Commit 2ce0307

Browse files
Dynamic Shovels: support old and new supervisor child ID formats
During a rolling upgrade, all cluster nodes collectively may (and usually will, due to Shovel migration during node restarts) contain mirrored_supervisor children with IDs that use two different parameters (see referenced commits below). The old format should not trip up node startup, so new nodes must accept it in a few places, and try to use these older values during dynamic Shovel spec cleanup. References ccc22cb, 5f0981c, #9785. See #9894.
1 parent ad30e87 commit 2ce0307

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

deps/rabbitmq_shovel/src/rabbit_shovel_dyn_worker_sup_sup.erl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ 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;
62+
%% older format, pre 3.13.0 and 3.12.8. See rabbitmq/rabbitmq-server#9894.
63+
({N, _, _, _}) -> N =:= Name
64+
end,
6265
mirrored_supervisor:which_children(?SUPERVISOR)).
6366

6467
stop_child({VHost, ShovelName} = Name) ->
@@ -83,19 +86,29 @@ stop_child({VHost, ShovelName} = Name) ->
8386
%% See rabbit_shovel_worker:terminate/2
8487

8588
cleanup_specs() ->
86-
SpecsSet = sets:from_list([element(2, element(1, S)) || S <- mirrored_supervisor:which_children(?SUPERVISOR)]),
89+
Children = mirrored_supervisor:which_children(?SUPERVISOR),
90+
91+
%% older format, pre 3.13.0 and 3.12.8. See rabbitmq/rabbitmq-server#9894
92+
OldStyleSpecsSet = sets:from_list([element(1, S) || S <- Children]),
93+
NewStyleSpecsSet = sets:from_list([element(2, element(1, S)) || S <- Children]),
8794
ParamsSet = sets:from_list([ {proplists:get_value(vhost, S), proplists:get_value(name, S)}
8895
|| S <- rabbit_runtime_parameters:list_component(<<"shovel">>) ]),
8996
F = fun(Name, ok) ->
9097
_ = mirrored_supervisor:delete_child(?SUPERVISOR, id(Name)),
9198
ok
9299
end,
93-
ok = sets:fold(F, ok, sets:subtract(SpecsSet, ParamsSet)).
100+
AllSpecs = sets:union(NewStyleSpecsSet, OldStyleSpecsSet),
101+
%% Delete any supervisor children that do not have their respective runtime parameters in the database.
102+
SetToCleanUp = sets:subtract(AllSpecs, ParamsSet),
103+
ok = sets:fold(F, ok, SetToCleanUp).
94104

95105
%%----------------------------------------------------------------------------
96106

97107
init([]) ->
98108
{ok, {{one_for_one, 3, 10}, []}}.
99109

100110
id({V, S} = Name) ->
101-
{[V, S], Name}.
111+
{[V, S], Name};
112+
%% older format, pre 3.13.0 and 3.12.8. See rabbitmq/rabbitmq-server#9894
113+
id(Other) ->
114+
Other.

0 commit comments

Comments
 (0)