1-module(rabbit_prelaunch_cluster).
2
3-include_lib("kernel/include/logger.hrl").
4
5-include_lib("rabbit_common/include/logging.hrl").
6
7-export([setup/1]).
8
9setup(Context) ->
10    ?LOG_DEBUG(
11       "~n== Clustering ==", [],
12       #{domain => ?RMQLOG_DOMAIN_PRELAUNCH}),
13    ?LOG_DEBUG(
14       "Preparing cluster status files", [],
15       #{domain => ?RMQLOG_DOMAIN_PRELAUNCH}),
16    rabbit_node_monitor:prepare_cluster_status_files(),
17    case Context of
18        #{initial_pass := true} ->
19            ?LOG_DEBUG(
20               "Upgrading Mnesia schema", [],
21               #{domain => ?RMQLOG_DOMAIN_PRELAUNCH}),
22            ok = rabbit_upgrade:maybe_upgrade_mnesia();
23        _ ->
24            ok
25    end,
26    %% It's important that the consistency check happens after
27    %% the upgrade, since if we are a secondary node the
28    %% primary node will have forgotten us
29    ?LOG_DEBUG(
30       "Checking cluster consistency", [],
31       #{domain => ?RMQLOG_DOMAIN_PRELAUNCH}),
32    rabbit_mnesia:check_cluster_consistency(),
33    ok.
34