Skip to content

Commit

Permalink
federation_exchange_link_sup_sup: revert to old id format if khepri i…
Browse files Browse the repository at this point in the history
…s disabled

During an upgrade from pre 3.13.0 version with existing federation
exchange links, the mirrored supervisor preserves old child id
format. During migration to Khepri old child ids are converted to new
format anyway. So let's revert and use old child id format also on
3.13.0 if Mnesia is used. This is to avoid the need to handle
two formats at the same time.
  • Loading branch information
gomoripeti committed Jan 24, 2024
1 parent 5eb4eef commit 1e0f365
Showing 1 changed file with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
Record :: tuple().
upgrade_record(mirrored_sup_childspec,
#mirrored_sup_childspec{key = {?MODULE, #exchange{} = Exchange}} = Record) ->
Record#mirrored_sup_childspec{key = {?MODULE, id(Exchange)}};
Record#mirrored_sup_childspec{key = {?MODULE, id(Exchange, _KhepriEnabled = true)}};
upgrade_record(_Table, Record) ->
Record.

-spec upgrade_key(Table, Key) -> Key when
Table :: mnesia_to_khepri:mnesia_table(),
Key :: any().
upgrade_key(mirrored_sup_childspec, {?MODULE, #exchange{} = Exchange}) ->
{?MODULE, id(Exchange)};
{?MODULE, id(Exchange, _KhepriEnabled = true)};
upgrade_key(_Table, Key) ->
Key.

Expand Down Expand Up @@ -83,12 +83,15 @@ start_child(X) ->

adjust({clear_upstream, VHost, UpstreamName}) ->
_ = [rabbit_federation_link_sup:adjust(Pid, X, {clear_upstream, UpstreamName}) ||
{{_, #exchange{name = Name} = X}, Pid, _, _} <- mirrored_supervisor:which_children(?SUPERVISOR),
Name#resource.virtual_host == VHost],
{Id, Pid, _, _} <- mirrored_supervisor:which_children(?SUPERVISOR),
begin
#exchange{name = Name} = X = id_to_exchange(Id),
Name#resource.virtual_host == VHost
end],
ok;
adjust(Reason) ->
_ = [rabbit_federation_link_sup:adjust(Pid, X, Reason) ||
{{_, X}, Pid, _, _} <- mirrored_supervisor:which_children(?SUPERVISOR)],
_ = [rabbit_federation_link_sup:adjust(Pid, id_to_exchange(Id), Reason) ||
{Id, Pid, _, _} <- mirrored_supervisor:which_children(?SUPERVISOR)],
ok.

stop_child(X) ->
Expand All @@ -111,7 +114,20 @@ init([]) ->
%% See comment in rabbit_federation_queue_link_sup_sup:id/1
id(X = #exchange{policy = Policy}) ->
X1 = rabbit_exchange:immutable(X),
{simple_id(X), X1#exchange{policy = Policy}}.
X2 = X1#exchange{policy = Policy},
id(X2, rabbit_khepri:is_enabled()).

id(X, _KhepriEnabled = true) ->
{simple_id(X), X};
id(X, _KhepriEnabled = false) ->
%% Old child id format before migration to Khepri
X.

simple_id(#exchange{name = #resource{virtual_host = VHost, name = Name}}) ->
[exchange, VHost, Name].

id_to_exchange({_, #exchange{} = X}) ->
X;
id_to_exchange(#exchange{} = X) ->
%% Old child id format before migration to Khepri
X.

0 comments on commit 1e0f365

Please sign in to comment.