Skip to content

Commit 84597ab

Browse files
author
Daniil Fedotov
committed
Moved directory selection to vhost_dir function
1 parent 76ee321 commit 84597ab

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

src/rabbit_msg_store_vhost_sup.erl

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@
22

33
-behaviour(supervisor2).
44

5-
-export([start_link/4, init/1, add_vhost/2, client_init/5, start_vhost/5, successfully_recovered_state/2]).
5+
-export([start_link/3, init/1, add_vhost/2, client_init/5, successfully_recovered_state/2]).
66

7-
start_link(Name, Dir, ClientRefs, StartupFunState) ->
7+
%% Internal
8+
-export([start_vhost/4]).
9+
10+
start_link(Name, ClientRefs, StartupFunState) ->
811
supervisor2:start_link({local, Name}, ?MODULE,
9-
[Name, Dir, ClientRefs, StartupFunState]).
12+
[Name, ClientRefs, StartupFunState]).
1013

11-
init([Name, Dir, ClientRefs, StartupFunState]) ->
14+
init([Name, ClientRefs, StartupFunState]) ->
1215
{ok, {{simple_one_for_one, 0, 1},
13-
[{rabbit_msg_store_vhost, {rabbit_msg_store_vhost_sup, start_vhost,
14-
[Name, Dir, ClientRefs, StartupFunState]},
16+
[{rabbit_msg_store_vhost, {rabbit_msg_store_vhost_sup, start_vhost,
17+
[Name, ClientRefs, StartupFunState]},
1518
transient, infinity, supervisor, [rabbit_msg_store]}]}}.
1619

1720

1821
add_vhost(Name, VHost) ->
1922
supervisor2:start_child(Name, [VHost]).
2023

21-
start_vhost(Name, Dir, ClientRefs, StartupFunState, VHost) ->
22-
VHostName = get_vhost_name(Name, VHost),
23-
VHostDir = get_vhost_dir(Dir, VHost),
24+
start_vhost(Name, ClientRefs, StartupFunState, VHost) ->
25+
VHostName = vhost_store_name(Name, VHost),
26+
VHostDir = vhost_store_dir(VHost),
2427
ok = rabbit_file:ensure_dir(VHostDir),
25-
rabbit_msg_store:start_link(VHostName, VHostDir,
28+
rabbit_msg_store:start_link(VHostName, VHostDir,
2629
ClientRefs, StartupFunState).
2730

2831

@@ -31,27 +34,29 @@ client_init(Server, Ref, MsgOnDiskFun, CloseFDsFun, VHost) ->
3134
rabbit_msg_store:client_init(VHostName, Ref, MsgOnDiskFun, CloseFDsFun).
3235

3336
maybe_start_vhost(Server, VHost) ->
34-
VHostName = get_vhost_name(Server, VHost),
35-
Trace = try throw(42) catch 42 -> erlang:get_stacktrace() end,
37+
VHostName = vhost_store_name(Server, VHost),
3638
case whereis(VHostName) of
3739
undefined -> add_vhost(Server, VHost);
3840
_ -> ok
3941
end,
4042
VHostName.
4143

42-
get_vhost_name(Name, VHost) ->
43-
VhostEncoded = encode_vhost(VHost),
44-
binary_to_atom(<<(atom_to_binary(Name, utf8))/binary, "_", VhostEncoded/binary>>, utf8).
44+
vhost_store_name(Name, VHost) ->
45+
VhostEncoded = encode_vhost_name(VHost),
46+
binary_to_atom(<<(atom_to_binary(Name, utf8))/binary, "_",
47+
VhostEncoded/binary>>,
48+
utf8).
4549

46-
get_vhost_dir(Dir, VHost) ->
47-
VhostEncoded = encode_vhost(VHost),
50+
vhost_store_dir(VHost) ->
51+
Dir = rabbit_mnesia:dir(),
52+
VhostEncoded = encode_vhost_name(VHost),
4853
binary_to_list(filename:join([Dir, VhostEncoded])).
4954

50-
encode_vhost(VHost) ->
55+
encode_vhost_name(VHost) ->
5156
base64:encode(VHost).
5257

5358
successfully_recovered_state(Name, VHost) ->
54-
VHostName = get_vhost_name(Name, VHost),
59+
VHostName = vhost_store_name(Name, VHost),
5560
rabbit_msg_store:successfully_recovered_state(VHostName).
5661

5762
% force_recovery

src/rabbit_variable_queue.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,13 @@ stop() ->
463463
ok = rabbit_queue_index:stop().
464464

465465
start_msg_store(Refs, StartFunState) ->
466-
VHosts = rabbit_vhost:list(),
467466
ok = rabbit_sup:start_child(?TRANSIENT_MSG_STORE_SUP, rabbit_msg_store_vhost_sup,
468-
[?TRANSIENT_MSG_STORE_SUP, rabbit_mnesia:dir(),
467+
[?TRANSIENT_MSG_STORE_SUP,
469468
undefined, {fun (ok) -> finished end, ok}]),
470469
ok = rabbit_sup:start_child(?PERSISTENT_MSG_STORE_SUP, rabbit_msg_store_vhost_sup,
471-
[?PERSISTENT_MSG_STORE_SUP, rabbit_mnesia:dir(),
472-
Refs, StartFunState]),
470+
[?PERSISTENT_MSG_STORE_SUP, Refs, StartFunState]),
471+
%% Start message store for all known vhosts
472+
VHosts = rabbit_vhost:list(),
473473
lists:foreach(
474474
fun(VHost) ->
475475
rabbit_msg_store_vhost_sup:add_vhost(?TRANSIENT_MSG_STORE_SUP, VHost),
@@ -2765,7 +2765,7 @@ start_new_store_sup() ->
27652765
% Start persistent store sup without recovery.
27662766
ok = rabbit_sup:start_child(?PERSISTENT_MSG_STORE_SUP,
27672767
rabbit_msg_store_vhost_sup,
2768-
[?PERSISTENT_MSG_STORE_SUP, rabbit_mnesia:dir(),
2768+
[?PERSISTENT_MSG_STORE_SUP,
27692769
undefined, {fun (ok) -> finished end, ok}]),
27702770
?PERSISTENT_MSG_STORE_SUP.
27712771

0 commit comments

Comments
 (0)