16
16
17
17
-module (rabbit_amqqueue ).
18
18
19
- -export ([recover /0 , stop /0 , start /1 , declare /6 , declare /7 ,
19
+ -export ([warn_file_limit /0 ]).
20
+ -export ([recover /1 , stop /1 , start /1 , declare /6 , declare /7 ,
20
21
delete_immediately /1 , delete_exclusive /2 , delete /4 , purge /1 ,
21
22
forget_all_durable /1 , delete_crashed /1 , delete_crashed /2 ,
22
23
delete_crashed_internal /2 ]).
70
71
{'absent' , rabbit_types :amqqueue (),absent_reason ()}.
71
72
-type not_found_or_absent () ::
72
73
'not_found' | {'absent' , rabbit_types :amqqueue (), absent_reason ()}.
73
- -spec recover () -> [rabbit_types :amqqueue ()].
74
- -spec stop () -> 'ok' .
74
+ -spec recover (rabbit_types : vhost () ) -> [rabbit_types :amqqueue ()].
75
+ -spec stop (rabbit_types : vhost () ) -> 'ok' .
75
76
-spec start ([rabbit_types :amqqueue ()]) -> 'ok' .
76
77
-spec declare
77
78
(name (), boolean (), boolean (), rabbit_framing :amqp_table (),
210
211
[queue_name , channel_pid , consumer_tag , ack_required , prefetch_count ,
211
212
arguments ]).
212
213
213
- recover () ->
214
- % % Clear out remnants of old incarnation, in case we restarted
215
- % % faster than other nodes handled DOWN messages from us.
216
- on_node_down (node ()),
214
+ warn_file_limit () ->
217
215
DurableQueues = find_durable_queues (),
218
216
L = length (DurableQueues ),
219
217
@@ -226,27 +224,23 @@ recover() ->
226
224
[L , file_handle_cache :get_limit (), L ]);
227
225
false ->
228
226
ok
229
- end ,
227
+ end .
230
228
229
+ recover (VHost ) ->
230
+ Queues = find_durable_queues (VHost ),
231
231
{ok , BQ } = application :get_env (rabbit , backing_queue_module ),
232
-
233
232
% % We rely on BQ:start/1 returning the recovery terms in the same
234
233
% % order as the supplied queue names, so that we can zip them together
235
234
% % for further processing in recover_durable_queues.
236
235
{ok , OrderedRecoveryTerms } =
237
- BQ :start ([QName || # amqqueue {name = QName } <- DurableQueues ]),
238
- {ok ,_ } = supervisor :start_child (
239
- rabbit_sup ,
240
- {rabbit_amqqueue_sup_sup ,
241
- {rabbit_amqqueue_sup_sup , start_link , []},
242
- transient , infinity , supervisor , [rabbit_amqqueue_sup_sup ]}),
243
- recover_durable_queues (lists :zip (DurableQueues , OrderedRecoveryTerms )).
244
-
245
- stop () ->
246
- ok = supervisor :terminate_child (rabbit_sup , rabbit_amqqueue_sup_sup ),
247
- ok = supervisor :delete_child (rabbit_sup , rabbit_amqqueue_sup_sup ),
236
+ BQ :start (VHost , [QName || # amqqueue {name = QName } <- Queues ]),
237
+ {ok , _ } = rabbit_amqqueue_sup_sup :start_for_vhost (VHost ),
238
+ recover_durable_queues (lists :zip (Queues , OrderedRecoveryTerms )).
239
+
240
+ stop (VHost ) ->
241
+ ok = rabbit_amqqueue_sup_sup :stop_for_vhost (VHost ),
248
242
{ok , BQ } = application :get_env (rabbit , backing_queue_module ),
249
- ok = BQ :stop ().
243
+ ok = BQ :stop (VHost ).
250
244
251
245
start (Qs ) ->
252
246
% % At this point all recovered queues and their bindings are
@@ -256,6 +250,24 @@ start(Qs) ->
256
250
[Pid ! {self (), go } || # amqqueue {pid = Pid } <- Qs ],
257
251
ok .
258
252
253
+ find_durable_queues (VHost ) ->
254
+ Node = node (),
255
+ mnesia :async_dirty (
256
+ fun () ->
257
+ qlc :e (qlc :q ([Q || Q = # amqqueue {name = Name ,
258
+ vhost = VH ,
259
+ pid = Pid }
260
+ <- mnesia :table (rabbit_durable_queue ),
261
+ VH =:= VHost ,
262
+ node (Pid ) == Node andalso
263
+ % % Terminations on node down will not remove the rabbit_queue
264
+ % % record if it is a mirrored queue (such info is now obtained from
265
+ % % the policy). Thus, we must check if the local pid is alive
266
+ % % - if the record is present - in order to restart.
267
+ (mnesia :read (rabbit_queue , Name , read ) =:= []
268
+ orelse not erlang :is_process_alive (Pid ))]))
269
+ end ).
270
+
259
271
find_durable_queues () ->
260
272
Node = node (),
261
273
mnesia :async_dirty (
@@ -268,8 +280,8 @@ find_durable_queues() ->
268
280
% % record if it is a mirrored queue (such info is now obtained from
269
281
% % the policy). Thus, we must check if the local pid is alive
270
282
% % - if the record is present - in order to restart.
271
- (mnesia :read (rabbit_queue , Name , read ) =:= []
272
- orelse not erlang :is_process_alive (Pid ))]))
283
+ (mnesia :read (rabbit_queue , Name , read ) =:= []
284
+ orelse not erlang :is_process_alive (Pid ))]))
273
285
end ).
274
286
275
287
recover_durable_queues (QueuesAndRecoveryTerms ) ->
0 commit comments