Skip to content

Commit

Permalink
Prepare bindings table in a separate recover function.
Browse files Browse the repository at this point in the history
Before #567 all binding recover functions were executed once on
node restart.
Executing table_filter can be expensive with high number of vhosts
and bindings and effectively should be called only once.
Moved to a separate function, which should be called from the global
recovery function (`rabbit_vhost:recover/0`)

(cherry picked from commit e5f4cbd)
  • Loading branch information
hairyhum authored and michaelklishin committed Jul 25, 2018
1 parent bdd5120 commit fff18f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/rabbit_binding.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-module(rabbit_binding).
-include("rabbit.hrl").

-export([recover/2, exists/1, add/2, add/3, remove/1, remove/3, list/1]).
-export([recover/0, recover/2, exists/1, add/2, add/3, remove/1, remove/3, list/1]).
-export([list_for_source/1, list_for_destination/1,
list_for_source_and_destination/2]).
-export([new_deletions/0, combine_deletions/2, add_deletion/3,
Expand Down Expand Up @@ -102,16 +102,20 @@
routing_key, arguments,
vhost]).

recover(XNames, QNames) ->
%% Global table recover
recover() ->
rabbit_misc:table_filter(
fun (Route) ->
mnesia:read({rabbit_semi_durable_route, Route}) =:= []
end,
fun (Route, true) ->
ok = mnesia:write(rabbit_semi_durable_route, Route, write);
(_Route, false) ->
ok
end, rabbit_durable_route),
fun (Route) ->
mnesia:read({rabbit_semi_durable_route, Route}) =:= []
end,
fun (Route, true) ->
ok = mnesia:write(rabbit_semi_durable_route, Route, write);
(_Route, false) ->
ok
end, rabbit_durable_route).

%% Per-vhost recover
recover(XNames, QNames) ->
XNameSet = sets:from_list(XNames),
QNameSet = sets:from_list(QNames),
SelectSet = fun (#resource{kind = exchange}) -> XNameSet;
Expand Down
4 changes: 4 additions & 0 deletions src/rabbit_vhost.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ recover() ->
rabbit_amqqueue:on_node_down(node()),

rabbit_amqqueue:warn_file_limit(),

%% Prepare rabbit_semi_durable_route table
rabbit_binding:recover(),

%% rabbit_vhost_sup_sup will start the actual recovery.
%% So recovery will be run every time a vhost supervisor is restarted.
ok = rabbit_vhost_sup_sup:start(),
Expand Down

0 comments on commit fff18f9

Please sign in to comment.