feat(emqx): manage mria tables explicitly during startup
This commit is contained in:
parent
edd28be090
commit
21a5751575
|
@ -21,12 +21,9 @@
|
|||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
|
||||
%% Mnesia bootstrap
|
||||
-export([mnesia/1]).
|
||||
|
||||
-boot_mnesia({mnesia, [boot]}).
|
||||
|
||||
-export([create_tables/0]).
|
||||
-export([start_link/0]).
|
||||
|
||||
%% API
|
||||
-export([
|
||||
activate/1,
|
||||
|
@ -86,7 +83,7 @@
|
|||
%% Mnesia bootstrap
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
mnesia(boot) ->
|
||||
create_tables() ->
|
||||
ok = mria:create_table(
|
||||
?ACTIVATED_ALARM,
|
||||
[
|
||||
|
@ -106,7 +103,8 @@ mnesia(boot) ->
|
|||
{record_name, deactivated_alarm},
|
||||
{attributes, record_info(fields, deactivated_alarm)}
|
||||
]
|
||||
).
|
||||
),
|
||||
[?ACTIVATED_ALARM, ?DEACTIVATED_ALARM].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% API
|
||||
|
|
|
@ -25,9 +25,7 @@
|
|||
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||
|
||||
%% Mnesia bootstrap
|
||||
-export([mnesia/1]).
|
||||
|
||||
-boot_mnesia({mnesia, [boot]}).
|
||||
-export([create_tables/0]).
|
||||
|
||||
-export([start_link/0, stop/0]).
|
||||
|
||||
|
@ -79,7 +77,7 @@
|
|||
%% Mnesia bootstrap
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
mnesia(boot) ->
|
||||
create_tables() ->
|
||||
Options = [
|
||||
{type, set},
|
||||
{rlog_shard, ?COMMON_SHARD},
|
||||
|
@ -89,7 +87,8 @@ mnesia(boot) ->
|
|||
{storage_properties, [{ets, [{read_concurrency, true}]}]}
|
||||
],
|
||||
ok = mria:create_table(?BANNED_INDIVIDUAL_TAB, Options),
|
||||
ok = mria:create_table(?BANNED_RULE_TAB, Options).
|
||||
ok = mria:create_table(?BANNED_RULE_TAB, Options),
|
||||
[?BANNED_INDIVIDUAL_TAB, ?BANNED_RULE_TAB].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Data backup
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
-export([init/1]).
|
||||
|
||||
start_link() ->
|
||||
ok = mria:wait_for_tables(
|
||||
emqx_shared_sub:create_tables() ++
|
||||
emqx_exclusive_subscription:create_tables()
|
||||
),
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
start_link() ->
|
||||
ok = mria:wait_for_tables(emqx_banned:create_tables()),
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -22,14 +22,11 @@
|
|||
-logger_header("[exclusive]").
|
||||
|
||||
%% Mnesia bootstrap
|
||||
-export([mnesia/1]).
|
||||
-export([create_tables/0]).
|
||||
|
||||
%% For upgrade
|
||||
-export([on_add_module/0, on_delete_module/0]).
|
||||
|
||||
-boot_mnesia({mnesia, [boot]}).
|
||||
-copy_mnesia({mnesia, [copy]}).
|
||||
|
||||
-export([
|
||||
check_subscribe/2,
|
||||
unsubscribe/2,
|
||||
|
@ -53,7 +50,7 @@
|
|||
%% Mnesia bootstrap
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
mnesia(boot) ->
|
||||
create_tables() ->
|
||||
StoreProps = [
|
||||
{ets, [
|
||||
{read_concurrency, true},
|
||||
|
@ -68,14 +65,14 @@ mnesia(boot) ->
|
|||
{attributes, record_info(fields, exclusive_subscription)},
|
||||
{storage_properties, StoreProps}
|
||||
]),
|
||||
ok = mria_rlog:wait_for_shards([?EXCLUSIVE_SHARD], infinity).
|
||||
[?TAB].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Upgrade
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
on_add_module() ->
|
||||
mnesia(boot).
|
||||
mria:wait_for_tables(create_tables()).
|
||||
|
||||
on_delete_module() ->
|
||||
clear().
|
||||
|
|
|
@ -24,9 +24,7 @@
|
|||
-include_lib("emqx/include/emqx_router.hrl").
|
||||
|
||||
%% Mnesia bootstrap
|
||||
-export([mnesia/1]).
|
||||
|
||||
-boot_mnesia({mnesia, [boot]}).
|
||||
-export([create_tables/0]).
|
||||
|
||||
-export([start_link/2]).
|
||||
|
||||
|
@ -123,7 +121,7 @@
|
|||
%% Mnesia bootstrap
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
mnesia(boot) ->
|
||||
create_tables() ->
|
||||
mria_config:set_dirty_shard(?ROUTE_SHARD, true),
|
||||
ok = mria:create_table(?ROUTE_TAB, [
|
||||
{type, bag},
|
||||
|
@ -151,7 +149,8 @@ mnesia(boot) ->
|
|||
{decentralized_counters, true}
|
||||
]}
|
||||
]}
|
||||
]).
|
||||
]),
|
||||
[?ROUTE_TAB, ?ROUTE_TAB_FILTERS].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Start a router
|
||||
|
|
|
@ -25,9 +25,7 @@
|
|||
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||
|
||||
%% Mnesia bootstrap
|
||||
-export([mnesia/1]).
|
||||
|
||||
-boot_mnesia({mnesia, [boot]}).
|
||||
-export([create_tables/0]).
|
||||
|
||||
%% API
|
||||
-export([
|
||||
|
@ -63,7 +61,7 @@
|
|||
%% Mnesia bootstrap
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
mnesia(boot) ->
|
||||
create_tables() ->
|
||||
ok = mria:create_table(?ROUTING_NODE, [
|
||||
{type, set},
|
||||
{rlog_shard, ?ROUTE_SHARD},
|
||||
|
@ -71,7 +69,8 @@ mnesia(boot) ->
|
|||
{record_name, routing_node},
|
||||
{attributes, record_info(fields, routing_node)},
|
||||
{storage_properties, [{ets, [{read_concurrency, true}]}]}
|
||||
]).
|
||||
]),
|
||||
[?ROUTING_NODE].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% API
|
||||
|
|
|
@ -24,6 +24,11 @@
|
|||
|
||||
start_link() ->
|
||||
%% Init and log routing table type
|
||||
ok = mria:wait_for_tables(
|
||||
emqx_trie:create_trie() ++
|
||||
emqx_router:create_tables() ++
|
||||
emqx_router_helper:create_tables()
|
||||
),
|
||||
ok = emqx_router:init_schema(),
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
|
|
|
@ -25,9 +25,7 @@
|
|||
-include("types.hrl").
|
||||
|
||||
%% Mnesia bootstrap
|
||||
-export([mnesia/1]).
|
||||
|
||||
-boot_mnesia({mnesia, [boot]}).
|
||||
-export([create_tables/0]).
|
||||
|
||||
%% APIs
|
||||
-export([start_link/0]).
|
||||
|
@ -107,14 +105,15 @@
|
|||
%% Mnesia bootstrap
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
mnesia(boot) ->
|
||||
create_tables() ->
|
||||
ok = mria:create_table(?TAB, [
|
||||
{type, bag},
|
||||
{rlog_shard, ?SHARED_SUB_SHARD},
|
||||
{storage, ram_copies},
|
||||
{record_name, emqx_shared_subscription},
|
||||
{attributes, record_info(fields, emqx_shared_subscription)}
|
||||
]).
|
||||
]),
|
||||
[?TAB].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% API
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
-export([init/1]).
|
||||
|
||||
start_link() ->
|
||||
_ = mria:wait_for_tables(emqx_alarm:create_tables()),
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
init([]) ->
|
||||
|
|
|
@ -20,13 +20,11 @@
|
|||
|
||||
%% Mnesia bootstrap
|
||||
-export([
|
||||
mnesia/1,
|
||||
create_trie/0,
|
||||
wait_for_tables/0,
|
||||
create_session_trie/1
|
||||
]).
|
||||
|
||||
-boot_mnesia({mnesia, [boot]}).
|
||||
|
||||
%% Trie APIs
|
||||
-export([
|
||||
insert/1,
|
||||
|
@ -65,8 +63,8 @@
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
%% @doc Create or replicate topics table.
|
||||
-spec mnesia(boot | copy) -> ok.
|
||||
mnesia(boot) ->
|
||||
-spec create_trie() -> [mria:table()].
|
||||
create_trie() ->
|
||||
%% Optimize storage
|
||||
StoreProps = [
|
||||
{ets, [
|
||||
|
@ -80,7 +78,8 @@ mnesia(boot) ->
|
|||
{attributes, record_info(fields, ?TRIE)},
|
||||
{type, ordered_set},
|
||||
{storage_properties, StoreProps}
|
||||
]).
|
||||
]),
|
||||
[?TRIE].
|
||||
|
||||
create_session_trie(Type) ->
|
||||
Storage =
|
||||
|
|
Loading…
Reference in New Issue