Skip to content

Commit e5f4cbd

Browse files
committed
Prepare bindings table in a separate recover function.
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`)
1 parent ddbc864 commit e5f4cbd

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/rabbit_binding.erl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
-module(rabbit_binding).
1818
-include("rabbit.hrl").
1919

20-
-export([recover/2, exists/1, add/2, add/3, remove/1, remove/3, list/1]).
20+
-export([recover/0, recover/2, exists/1, add/2, add/3, remove/1, remove/3, list/1]).
2121
-export([list_for_source/1, list_for_destination/1,
2222
list_for_source_and_destination/2]).
2323
-export([new_deletions/0, combine_deletions/2, add_deletion/3,
@@ -102,16 +102,20 @@
102102
routing_key, arguments,
103103
vhost]).
104104

105-
recover(XNames, QNames) ->
105+
%% Global table recover
106+
recover() ->
106107
rabbit_misc:table_filter(
107-
fun (Route) ->
108-
mnesia:read({rabbit_semi_durable_route, Route}) =:= []
109-
end,
110-
fun (Route, true) ->
111-
ok = mnesia:write(rabbit_semi_durable_route, Route, write);
112-
(_Route, false) ->
113-
ok
114-
end, rabbit_durable_route),
108+
fun (Route) ->
109+
mnesia:read({rabbit_semi_durable_route, Route}) =:= []
110+
end,
111+
fun (Route, true) ->
112+
ok = mnesia:write(rabbit_semi_durable_route, Route, write);
113+
(_Route, false) ->
114+
ok
115+
end, rabbit_durable_route).
116+
117+
%% Per-vhost recover
118+
recover(XNames, QNames) ->
115119
XNameSet = sets:from_list(XNames),
116120
QNameSet = sets:from_list(QNames),
117121
SelectSet = fun (#resource{kind = exchange}) -> XNameSet;

src/rabbit_vhost.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ recover() ->
5252
rabbit_amqqueue:on_node_down(node()),
5353

5454
rabbit_amqqueue:warn_file_limit(),
55+
56+
%% Prepare rabbit_semi_durable_route table
57+
rabbit_binding:recover(),
58+
5559
%% rabbit_vhost_sup_sup will start the actual recovery.
5660
%% So recovery will be run every time a vhost supervisor is restarted.
5761
ok = rabbit_vhost_sup_sup:start(),

0 commit comments

Comments
 (0)