Skip to content

Commit 1649fcf

Browse files
committed
rabbit_ra_systems: New module to configure Ra systems
There is no new code really: the code is moved from `rabbit` to `rabbit_ra_systems`. This is a non-functional change. The goal is to keep the top-level prelaunch functions minimal: they should just call other modules who do the actual work.
1 parent 7bda522 commit 1649fcf

File tree

2 files changed

+91
-19
lines changed

2 files changed

+91
-19
lines changed

deps/rabbit/src/rabbit.erl

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@
284284
%% 100 ms
285285
-define(BOOT_STATUS_CHECK_INTERVAL, 100).
286286

287-
-define(COORD_WAL_MAX_SIZE_B, 64_000_000).
288-
289287
%%----------------------------------------------------------------------------
290288

291289
-type restart_type() :: 'permanent' | 'transient' | 'temporary'.
@@ -366,25 +364,10 @@ run_prelaunch_second_phase() ->
366364
?LOG_DEBUG("Starting Mnesia"),
367365
ok = mnesia:start(),
368366

369-
?LOG_DEBUG(""),
370-
?LOG_DEBUG("== Prelaunch DONE =="),
371-
372-
?LOG_DEBUG("Starting Ra Systems"),
373-
Default = ra_system:default_config(),
374-
Quorum = Default#{name => quorum_queues},
375-
% names => ra_system:derive_names(quorum)},
376-
CoordDataDir = filename:join([rabbit_mnesia:dir(), "coordination", node()]),
377-
Coord = Default#{name => coordination,
378-
data_dir => CoordDataDir,
379-
wal_data_dir => CoordDataDir,
380-
wal_max_size_bytes => ?COORD_WAL_MAX_SIZE_B,
381-
names => ra_system:derive_names(coordination)},
382-
383-
{ok, _} = ra_system:start(Quorum),
384-
{ok, _} = ra_system:start(Coord),
367+
ok = rabbit_ra_systems:setup(Context),
385368

386369
?LOG_DEBUG(""),
387-
?LOG_DEBUG("== Ra System Start done DONE =="),
370+
?LOG_DEBUG("== Prelaunch DONE =="),
388371

389372
case IsInitialPass of
390373
true -> rabbit_prelaunch:initial_pass_finished();

deps/rabbit/src/rabbit_ra_systems.erl

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2021 VMware, Inc. or its affiliates. All rights reserved.
6+
%%
7+
8+
-module(rabbit_ra_systems).
9+
10+
-include_lib("kernel/include/logger.hrl").
11+
12+
-include_lib("rabbit_common/include/logging.hrl").
13+
14+
-export([setup/0,
15+
setup/1,
16+
all_ra_systems/0,
17+
ensure_ra_system_started/1]).
18+
19+
-type ra_system_name() :: atom().
20+
21+
-define(COORD_WAL_MAX_SIZE_B, 64_000_000).
22+
23+
-spec setup() -> ok | no_return().
24+
25+
setup() ->
26+
setup(rabbit_prelaunch:get_context()).
27+
28+
-spec setup(Context :: map()) -> ok | no_return().
29+
30+
setup(_) ->
31+
?LOG_DEBUG("Starting Ra systems"),
32+
lists:foreach(fun ensure_ra_system_started/1, all_ra_systems()),
33+
?LOG_DEBUG("Ra systems started"),
34+
ok.
35+
36+
-spec all_ra_systems() -> [ra_system_name()].
37+
38+
all_ra_systems() ->
39+
[quorum_queues,
40+
coordination].
41+
42+
-spec ensure_ra_system_started(ra_system_name()) -> ok | no_return().
43+
44+
ensure_ra_system_started(RaSystem) ->
45+
RaSystemConfig = get_config(RaSystem),
46+
?LOG_DEBUG(
47+
"Starting Ra system called \"~s\" with configuration:~n~p",
48+
[RaSystem, RaSystemConfig],
49+
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
50+
case ra_system:start(RaSystemConfig) of
51+
{ok, _} ->
52+
?LOG_DEBUG(
53+
"Ra system \"~s\" ready",
54+
[RaSystem],
55+
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
56+
ok;
57+
{error, {already_started, _}} ->
58+
?LOG_DEBUG(
59+
"Ra system \"~s\" ready",
60+
[RaSystem],
61+
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
62+
ok;
63+
Error ->
64+
?LOG_ERROR(
65+
"Failed to start Ra system \"~s\": ~p",
66+
[RaSystem, Error],
67+
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
68+
throw(Error)
69+
end.
70+
71+
-spec get_config(ra_system_name()) -> ra_system:config().
72+
73+
get_config(quorum_queues = RaSystem) ->
74+
DefaultConfig = get_default_config(),
75+
DefaultConfig#{name => RaSystem}; % names => ra_system:derive_names(quorum)
76+
get_config(coordination = RaSystem) ->
77+
DefaultConfig = get_default_config(),
78+
CoordDataDir = filename:join(
79+
[rabbit_mnesia:dir(), "coordination", node()]),
80+
DefaultConfig#{name => RaSystem,
81+
data_dir => CoordDataDir,
82+
wal_data_dir => CoordDataDir,
83+
wal_max_size_bytes => ?COORD_WAL_MAX_SIZE_B,
84+
names => ra_system:derive_names(RaSystem)}.
85+
86+
-spec get_default_config() -> ra_system:config().
87+
88+
get_default_config() ->
89+
ra_system:default_config().

0 commit comments

Comments
 (0)