feat(emqx-conf): manage mria tables explicitly during startup
This commit is contained in:
parent
eff149e676
commit
21780e2126
|
@ -17,7 +17,7 @@
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/0, mnesia/1]).
|
-export([start_link/0, create_tables/0]).
|
||||||
|
|
||||||
%% Note: multicall functions are statically checked by
|
%% Note: multicall functions are statically checked by
|
||||||
%% `emqx_bapi_trans' and `emqx_bpapi_static_checks' modules. Don't
|
%% `emqx_bapi_trans' and `emqx_bpapi_static_checks' modules. Don't
|
||||||
|
@ -65,8 +65,6 @@
|
||||||
|
|
||||||
-export_type([tnx_id/0, succeed_num/0]).
|
-export_type([tnx_id/0, succeed_num/0]).
|
||||||
|
|
||||||
-boot_mnesia({mnesia, [boot]}).
|
|
||||||
|
|
||||||
-include_lib("emqx/include/logger.hrl").
|
-include_lib("emqx/include/logger.hrl").
|
||||||
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||||
-include("emqx_conf.hrl").
|
-include("emqx_conf.hrl").
|
||||||
|
@ -99,7 +97,8 @@
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
mnesia(boot) ->
|
|
||||||
|
create_tables() ->
|
||||||
ok = mria:create_table(?CLUSTER_MFA, [
|
ok = mria:create_table(?CLUSTER_MFA, [
|
||||||
{type, ordered_set},
|
{type, ordered_set},
|
||||||
{rlog_shard, ?CLUSTER_RPC_SHARD},
|
{rlog_shard, ?CLUSTER_RPC_SHARD},
|
||||||
|
@ -113,7 +112,11 @@ mnesia(boot) ->
|
||||||
{storage, disc_copies},
|
{storage, disc_copies},
|
||||||
{record_name, cluster_rpc_commit},
|
{record_name, cluster_rpc_commit},
|
||||||
{attributes, record_info(fields, cluster_rpc_commit)}
|
{attributes, record_info(fields, cluster_rpc_commit)}
|
||||||
]).
|
]),
|
||||||
|
[
|
||||||
|
?CLUSTER_MFA,
|
||||||
|
?CLUSTER_COMMIT
|
||||||
|
].
|
||||||
|
|
||||||
start_link() ->
|
start_link() ->
|
||||||
start_link(node(), ?MODULE, get_retry_ms()).
|
start_link(node(), ?MODULE, get_retry_ms()).
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{vsn, "0.1.34"},
|
{vsn, "0.1.34"},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{mod, {emqx_conf_app, []}},
|
{mod, {emqx_conf_app, []}},
|
||||||
{applications, [kernel, stdlib, emqx_ctl]},
|
{applications, [kernel, stdlib]},
|
||||||
{env, []},
|
{env, []},
|
||||||
{modules, []}
|
{modules, []}
|
||||||
]}.
|
]}.
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
-include("emqx_conf.hrl").
|
-include("emqx_conf.hrl").
|
||||||
|
|
||||||
start(_StartType, _StartArgs) ->
|
start(_StartType, _StartArgs) ->
|
||||||
|
ok = mria:wait_for_tables(emqx_cluster_rpc:create_tables()),
|
||||||
try
|
try
|
||||||
ok = init_conf()
|
ok = init_conf()
|
||||||
catch
|
catch
|
||||||
|
|
|
@ -47,8 +47,6 @@ common_tests() ->
|
||||||
emqx_common_test_helpers:all(?MODULE) -- [t_reindex].
|
emqx_common_test_helpers:all(?MODULE) -- [t_reindex].
|
||||||
|
|
||||||
-define(BASE_CONF, <<
|
-define(BASE_CONF, <<
|
||||||
""
|
|
||||||
"\n"
|
|
||||||
"retainer {\n"
|
"retainer {\n"
|
||||||
" enable = true\n"
|
" enable = true\n"
|
||||||
" msg_clear_interval = 0s\n"
|
" msg_clear_interval = 0s\n"
|
||||||
|
@ -64,7 +62,6 @@ common_tests() ->
|
||||||
" max_retained_messages = 0\n"
|
" max_retained_messages = 0\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}"
|
"}"
|
||||||
""
|
|
||||||
>>).
|
>>).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -72,18 +69,14 @@ common_tests() ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
emqx_common_test_helpers:start_apps([emqx_conf]),
|
Apps = emqx_cth_suite:start(
|
||||||
load_conf(),
|
[emqx, emqx_conf, app_spec()],
|
||||||
emqx_limiter_sup:start_link(),
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
timer:sleep(200),
|
),
|
||||||
ok = application:ensure_started(?APP),
|
[{suite_apps, Apps} | Config].
|
||||||
Config.
|
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(Config) ->
|
||||||
ekka:stop(),
|
emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||||
mria:stop(),
|
|
||||||
mria_mnesia:delete_schema(),
|
|
||||||
emqx_common_test_helpers:stop_apps([?APP, emqx_conf]).
|
|
||||||
|
|
||||||
init_per_group(mnesia_without_indices, Config) ->
|
init_per_group(mnesia_without_indices, Config) ->
|
||||||
mnesia:clear_table(?TAB_INDEX_META),
|
mnesia:clear_table(?TAB_INDEX_META),
|
||||||
|
@ -113,10 +106,8 @@ init_per_testcase(t_get_basic_usage_info, Config) ->
|
||||||
init_per_testcase(_TestCase, Config) ->
|
init_per_testcase(_TestCase, Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
load_conf() ->
|
app_spec() ->
|
||||||
ok = emqx_config:delete_override_conf_files(),
|
{emqx_retainer, ?BASE_CONF}.
|
||||||
emqx_ratelimiter_SUITE:init_config(),
|
|
||||||
ok = emqx_config:init_load(emqx_retainer_schema, ?BASE_CONF).
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Test Cases
|
%% Test Cases
|
||||||
|
|
|
@ -22,18 +22,20 @@
|
||||||
-include("emqx_retainer.hrl").
|
-include("emqx_retainer.hrl").
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
-include_lib("common_test/include/ct.hrl").
|
||||||
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||||
|
|
||||||
all() -> emqx_common_test_helpers:all(?MODULE).
|
all() -> emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
emqx_retainer_SUITE:load_conf(),
|
Apps = emqx_cth_suite:start(
|
||||||
%% Start Apps
|
[emqx, emqx_conf, emqx_retainer_SUITE:app_spec()],
|
||||||
emqx_common_test_helpers:start_apps([emqx_retainer]),
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
Config.
|
),
|
||||||
|
[{suite_apps, Apps} | Config].
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(Config) ->
|
||||||
emqx_common_test_helpers:stop_apps([emqx_retainer]).
|
emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||||
|
|
||||||
t_reindex_status(_Config) ->
|
t_reindex_status(_Config) ->
|
||||||
ok = emqx_retainer_mnesia_cli:retainer(["reindex", "status"]).
|
ok = emqx_retainer_mnesia_cli:retainer(["reindex", "status"]).
|
||||||
|
|
|
@ -20,17 +20,19 @@
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
|
||||||
all() -> emqx_common_test_helpers:all(?MODULE).
|
all() -> emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
emqx_retainer_SUITE:load_conf(),
|
Apps = emqx_cth_suite:start(
|
||||||
%% Start Apps
|
[emqx, emqx_conf, emqx_retainer_SUITE:app_spec()],
|
||||||
emqx_common_test_helpers:start_apps([emqx_retainer]),
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
Config.
|
),
|
||||||
|
[{suite_apps, Apps} | Config].
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(Config) ->
|
||||||
emqx_common_test_helpers:stop_apps([emqx_retainer]).
|
emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||||
|
|
||||||
client_info(Key, Client) ->
|
client_info(Key, Client) ->
|
||||||
maps:get(Key, maps:from_list(emqtt:info(Client)), undefined).
|
maps:get(Key, maps:from_list(emqtt:info(Client)), undefined).
|
||||||
|
|
Loading…
Reference in New Issue