feat(emqx-conf): manage mria tables explicitly during startup

This commit is contained in:
Andrew Mayorov 2024-01-30 20:45:01 +01:00
parent eff149e676
commit 21780e2126
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
6 changed files with 35 additions and 36 deletions

View File

@ -17,7 +17,7 @@
-behaviour(gen_server).
%% API
-export([start_link/0, mnesia/1]).
-export([start_link/0, create_tables/0]).
%% Note: multicall functions are statically checked by
%% `emqx_bapi_trans' and `emqx_bpapi_static_checks' modules. Don't
@ -65,8 +65,6 @@
-export_type([tnx_id/0, succeed_num/0]).
-boot_mnesia({mnesia, [boot]}).
-include_lib("emqx/include/logger.hrl").
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
-include("emqx_conf.hrl").
@ -99,7 +97,8 @@
%%%===================================================================
%%% API
%%%===================================================================
mnesia(boot) ->
create_tables() ->
ok = mria:create_table(?CLUSTER_MFA, [
{type, ordered_set},
{rlog_shard, ?CLUSTER_RPC_SHARD},
@ -113,7 +112,11 @@ mnesia(boot) ->
{storage, disc_copies},
{record_name, cluster_rpc_commit},
{attributes, record_info(fields, cluster_rpc_commit)}
]).
]),
[
?CLUSTER_MFA,
?CLUSTER_COMMIT
].
start_link() ->
start_link(node(), ?MODULE, get_retry_ms()).

View File

@ -3,7 +3,7 @@
{vsn, "0.1.34"},
{registered, []},
{mod, {emqx_conf_app, []}},
{applications, [kernel, stdlib, emqx_ctl]},
{applications, [kernel, stdlib]},
{env, []},
{modules, []}
]}.

View File

@ -27,6 +27,7 @@
-include("emqx_conf.hrl").
start(_StartType, _StartArgs) ->
ok = mria:wait_for_tables(emqx_cluster_rpc:create_tables()),
try
ok = init_conf()
catch

View File

@ -47,8 +47,6 @@ common_tests() ->
emqx_common_test_helpers:all(?MODULE) -- [t_reindex].
-define(BASE_CONF, <<
""
"\n"
"retainer {\n"
" enable = true\n"
" msg_clear_interval = 0s\n"
@ -64,7 +62,6 @@ common_tests() ->
" max_retained_messages = 0\n"
" }\n"
"}"
""
>>).
%%--------------------------------------------------------------------
@ -72,18 +69,14 @@ common_tests() ->
%%--------------------------------------------------------------------
init_per_suite(Config) ->
emqx_common_test_helpers:start_apps([emqx_conf]),
load_conf(),
emqx_limiter_sup:start_link(),
timer:sleep(200),
ok = application:ensure_started(?APP),
Config.
Apps = emqx_cth_suite:start(
[emqx, emqx_conf, app_spec()],
#{work_dir => emqx_cth_suite:work_dir(Config)}
),
[{suite_apps, Apps} | Config].
end_per_suite(_Config) ->
ekka:stop(),
mria:stop(),
mria_mnesia:delete_schema(),
emqx_common_test_helpers:stop_apps([?APP, emqx_conf]).
end_per_suite(Config) ->
emqx_cth_suite:stop(?config(suite_apps, Config)).
init_per_group(mnesia_without_indices, Config) ->
mnesia:clear_table(?TAB_INDEX_META),
@ -113,10 +106,8 @@ init_per_testcase(t_get_basic_usage_info, Config) ->
init_per_testcase(_TestCase, Config) ->
Config.
load_conf() ->
ok = emqx_config:delete_override_conf_files(),
emqx_ratelimiter_SUITE:init_config(),
ok = emqx_config:init_load(emqx_retainer_schema, ?BASE_CONF).
app_spec() ->
{emqx_retainer, ?BASE_CONF}.
%%--------------------------------------------------------------------
%% Test Cases

View File

@ -22,18 +22,20 @@
-include("emqx_retainer.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
all() -> emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) ->
emqx_retainer_SUITE:load_conf(),
%% Start Apps
emqx_common_test_helpers:start_apps([emqx_retainer]),
Config.
Apps = emqx_cth_suite:start(
[emqx, emqx_conf, emqx_retainer_SUITE:app_spec()],
#{work_dir => emqx_cth_suite:work_dir(Config)}
),
[{suite_apps, Apps} | Config].
end_per_suite(_Config) ->
emqx_common_test_helpers:stop_apps([emqx_retainer]).
end_per_suite(Config) ->
emqx_cth_suite:stop(?config(suite_apps, Config)).
t_reindex_status(_Config) ->
ok = emqx_retainer_mnesia_cli:retainer(["reindex", "status"]).

View File

@ -20,17 +20,19 @@
-compile(nowarn_export_all).
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
all() -> emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) ->
emqx_retainer_SUITE:load_conf(),
%% Start Apps
emqx_common_test_helpers:start_apps([emqx_retainer]),
Config.
Apps = emqx_cth_suite:start(
[emqx, emqx_conf, emqx_retainer_SUITE:app_spec()],
#{work_dir => emqx_cth_suite:work_dir(Config)}
),
[{suite_apps, Apps} | Config].
end_per_suite(_Config) ->
emqx_common_test_helpers:stop_apps([emqx_retainer]).
end_per_suite(Config) ->
emqx_cth_suite:stop(?config(suite_apps, Config)).
client_info(Key, Client) ->
maps:get(Key, maps:from_list(emqtt:info(Client)), undefined).