@@ -230,12 +230,21 @@ stop() ->
230
230
ok = rabbit_queue_index :stop ().
231
231
232
232
start_msg_store (Refs , StartFunState ) ->
233
- ok = rabbit_sup :start_child (? TRANSIENT_MSG_STORE , rabbit_msg_store ,
233
+ ok = rabbit_sup :start_child (? TRANSIENT_MSG_STORE , rabbit_msg_store_vhost_sup ,
234
234
[? TRANSIENT_MSG_STORE , rabbit_mnesia :dir (),
235
235
undefined , {fun (ok ) -> finished end , ok }]),
236
- ok = rabbit_sup :start_child (? PERSISTENT_MSG_STORE , rabbit_msg_store ,
236
+ ok = rabbit_sup :start_child (? PERSISTENT_MSG_STORE , rabbit_msg_store_vhost_sup ,
237
237
[? PERSISTENT_MSG_STORE , rabbit_mnesia :dir (),
238
- Refs , StartFunState ]).
238
+ Refs , StartFunState ]),
239
+ % % Start message store for all known vhosts
240
+ VHosts = rabbit_vhost :list (),
241
+ lists :foreach (
242
+ fun (VHost ) ->
243
+ rabbit_msg_store_vhost_sup :add_vhost (? TRANSIENT_MSG_STORE , VHost ),
244
+ rabbit_msg_store_vhost_sup :add_vhost (? PERSISTENT_MSG_STORE , VHost )
245
+ end ,
246
+ VHosts ),
247
+ ok .
239
248
240
249
stop_msg_store () ->
241
250
ok = rabbit_sup :stop_child (? PERSISTENT_MSG_STORE ),
@@ -254,22 +263,26 @@ init(#amqqueue { name = QueueName, durable = IsDurable }, new,
254
263
AsyncCallback , MsgOnDiskFun , MsgIdxOnDiskFun , MsgAndIdxOnDiskFun ) ->
255
264
IndexState = rabbit_queue_index :init (QueueName ,
256
265
MsgIdxOnDiskFun , MsgAndIdxOnDiskFun ),
266
+ VHost = QueueName # resource .virtual_host ,
257
267
init (IsDurable , IndexState , 0 , 0 , [],
258
268
case IsDurable of
259
269
true -> msg_store_client_init (? PERSISTENT_MSG_STORE ,
260
- MsgOnDiskFun , AsyncCallback );
270
+ MsgOnDiskFun , AsyncCallback ,
271
+ VHost );
261
272
false -> undefined
262
273
end ,
263
- msg_store_client_init (? TRANSIENT_MSG_STORE , undefined , AsyncCallback ));
274
+ msg_store_client_init (? TRANSIENT_MSG_STORE , undefined , AsyncCallback , VHost ));
264
275
265
276
% % We can be recovering a transient queue if it crashed
266
277
init (# amqqueue { name = QueueName , durable = IsDurable }, Terms ,
267
278
AsyncCallback , MsgOnDiskFun , MsgIdxOnDiskFun , MsgAndIdxOnDiskFun ) ->
268
279
{PRef , RecoveryTerms } = process_recovery_terms (Terms ),
280
+ VHost = QueueName # resource .virtual_host ,
269
281
{PersistentClient , ContainsCheckFun } =
270
282
case IsDurable of
271
283
true -> C = msg_store_client_init (? PERSISTENT_MSG_STORE , PRef ,
272
- MsgOnDiskFun , AsyncCallback ),
284
+ MsgOnDiskFun , AsyncCallback ,
285
+ VHost ),
273
286
{C , fun (MsgId ) when is_binary (MsgId ) ->
274
287
rabbit_msg_store :contains (MsgId , C );
275
288
(# basic_message {is_persistent = Persistent }) ->
@@ -278,11 +291,12 @@ init(#amqqueue { name = QueueName, durable = IsDurable }, Terms,
278
291
false -> {undefined , fun (_MsgId ) -> false end }
279
292
end ,
280
293
TransientClient = msg_store_client_init (? TRANSIENT_MSG_STORE ,
281
- undefined , AsyncCallback ),
294
+ undefined , AsyncCallback ,
295
+ VHost ),
282
296
{DeltaCount , DeltaBytes , IndexState } =
283
297
rabbit_queue_index :recover (
284
298
QueueName , RecoveryTerms ,
285
- rabbit_msg_store :successfully_recovered_state (? PERSISTENT_MSG_STORE ),
299
+ rabbit_msg_store_vhost_sup :successfully_recovered_state (? PERSISTENT_MSG_STORE ),
286
300
ContainsCheckFun , MsgIdxOnDiskFun , MsgAndIdxOnDiskFun ),
287
301
init (IsDurable , IndexState , DeltaCount , DeltaBytes , RecoveryTerms ,
288
302
PersistentClient , TransientClient ).
@@ -957,14 +971,16 @@ with_immutable_msg_store_state(MSCState, IsPersistent, Fun) ->
957
971
end ),
958
972
Res .
959
973
960
- msg_store_client_init (MsgStore , MsgOnDiskFun , Callback ) ->
974
+ msg_store_client_init (MsgStore , MsgOnDiskFun , Callback , VHost ) ->
961
975
msg_store_client_init (MsgStore , rabbit_guid :gen (), MsgOnDiskFun ,
962
- Callback ).
976
+ Callback , VHost ).
963
977
964
- msg_store_client_init (MsgStore , Ref , MsgOnDiskFun , Callback ) ->
978
+ msg_store_client_init (MsgStore , Ref , MsgOnDiskFun , Callback , VHost ) ->
965
979
CloseFDsFun = msg_store_close_fds_fun (MsgStore =:= ? PERSISTENT_MSG_STORE ),
966
- rabbit_msg_store :client_init (MsgStore , Ref , MsgOnDiskFun ,
967
- fun () -> Callback (? MODULE , CloseFDsFun ) end ).
980
+ rabbit_msg_store_vhost_sup :client_init (
981
+ MsgStore , Ref , MsgOnDiskFun ,
982
+ fun () -> Callback (? MODULE , CloseFDsFun ) end ,
983
+ VHost ).
968
984
969
985
msg_store_write (MSCState , IsPersistent , MsgId , Msg ) ->
970
986
with_immutable_msg_store_state (
0 commit comments