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