fix(persistent_sessions): postpone table creation until configs are loaded
This commit is contained in:
parent
fe4d14303c
commit
9188f5b67e
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
start(_Type, _Args) ->
|
start(_Type, _Args) ->
|
||||||
ok = maybe_load_config(),
|
ok = maybe_load_config(),
|
||||||
|
ok = emqx_persistent_session:init_db_backend(),
|
||||||
ok = maybe_start_quicer(),
|
ok = maybe_start_quicer(),
|
||||||
wait_boot_shards(),
|
wait_boot_shards(),
|
||||||
{ok, Sup} = emqx_sup:start_link(),
|
{ok, Sup} = emqx_sup:start_link(),
|
||||||
|
|
|
@ -80,15 +80,14 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
init_db_backend() ->
|
init_db_backend() ->
|
||||||
case persistent_term:get({?MODULE, backend_init_done}, undefined) of
|
case is_store_enabled() of
|
||||||
undefined ->
|
true ->
|
||||||
Backend = case is_store_enabled() of
|
ok = emqx_trie:create_session_trie(),
|
||||||
true -> emqx_persistent_session_mnesia_backend;
|
emqx_persistent_session_mnesia_backend:create_tables(),
|
||||||
false -> emqx_persistent_session_dummy_backend
|
persistent_term:put(?db_backend_key, emqx_persistent_session_mnesia_backend),
|
||||||
end,
|
ok;
|
||||||
persistent_term:put(?db_backend_key, Backend),
|
false ->
|
||||||
persistent_term:put(backend_init_done, true);
|
persistent_term:put(?db_backend_key, emqx_persistent_session_dummy_backend),
|
||||||
true ->
|
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -16,15 +16,11 @@
|
||||||
|
|
||||||
-module(emqx_persistent_session_mnesia_backend).
|
-module(emqx_persistent_session_mnesia_backend).
|
||||||
|
|
||||||
-boot_mnesia({mnesia, [boot]}).
|
|
||||||
|
|
||||||
-include("emqx.hrl").
|
-include("emqx.hrl").
|
||||||
-include("emqx_persistent_session.hrl").
|
-include("emqx_persistent_session.hrl").
|
||||||
|
|
||||||
-export([ mnesia/1
|
-export([ create_tables/0
|
||||||
]).
|
, first_message_id/0
|
||||||
|
|
||||||
-export([ first_message_id/0
|
|
||||||
, next_message_id/1
|
, next_message_id/1
|
||||||
, delete_message/1
|
, delete_message/1
|
||||||
, first_session_message/0
|
, first_session_message/0
|
||||||
|
@ -39,14 +35,7 @@
|
||||||
, ro_transaction/1
|
, ro_transaction/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
create_tables() ->
|
||||||
mnesia(Action) ->
|
|
||||||
emqx_persistent_session:init_db_backend(),
|
|
||||||
mnesia_opt(?db_backend =:= ?MODULE, Action).
|
|
||||||
|
|
||||||
mnesia_opt(false, _) ->
|
|
||||||
ok;
|
|
||||||
mnesia_opt(true, boot) ->
|
|
||||||
ok = mria:create_table(?SESSION_STORE, [
|
ok = mria:create_table(?SESSION_STORE, [
|
||||||
{type, set},
|
{type, set},
|
||||||
{rlog_shard, ?PERSISTENT_SESSION_SHARD},
|
{rlog_shard, ?PERSISTENT_SESSION_SHARD},
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
-include("emqx.hrl").
|
-include("emqx.hrl").
|
||||||
|
|
||||||
%% Mnesia bootstrap
|
%% Mnesia bootstrap
|
||||||
-export([mnesia/1]).
|
-export([ mnesia/1
|
||||||
|
, create_session_trie/0
|
||||||
|
]).
|
||||||
|
|
||||||
-boot_mnesia({mnesia, [boot]}).
|
-boot_mnesia({mnesia, [boot]}).
|
||||||
|
|
||||||
|
@ -71,20 +73,19 @@ mnesia(boot) ->
|
||||||
{record_name, ?TRIE},
|
{record_name, ?TRIE},
|
||||||
{attributes, record_info(fields, ?TRIE)},
|
{attributes, record_info(fields, ?TRIE)},
|
||||||
{type, ordered_set},
|
{type, ordered_set},
|
||||||
{storage_properties, StoreProps}]),
|
{storage_properties, StoreProps}]).
|
||||||
|
|
||||||
case emqx_persistent_session:is_store_enabled() of
|
create_session_trie() ->
|
||||||
true ->
|
StoreProps = [{ets, [{read_concurrency, true},
|
||||||
ok = mria:create_table(?SESSION_TRIE, [
|
{write_concurrency, true}
|
||||||
{rlog_shard, ?ROUTE_SHARD},
|
]}],
|
||||||
{storage, disc_copies},
|
ok = mria:create_table(?SESSION_TRIE,
|
||||||
{record_name, ?TRIE},
|
[{rlog_shard, ?ROUTE_SHARD},
|
||||||
{attributes, record_info(fields, ?TRIE)},
|
{storage, disc_copies},
|
||||||
{type, ordered_set},
|
{record_name, ?TRIE},
|
||||||
{storage_properties, StoreProps}]);
|
{attributes, record_info(fields, ?TRIE)},
|
||||||
false ->
|
{type, ordered_set},
|
||||||
ok
|
{storage_properties, StoreProps}]).
|
||||||
end.
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Topics APIs
|
%% Topics APIs
|
||||||
|
|
Loading…
Reference in New Issue