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