chore(persistent_session): make more table creation parameterized

This commit is contained in:
Tobias Lindahl 2021-11-23 16:23:47 +01:00
parent 9eaedbf246
commit df2dda2e10
3 changed files with 15 additions and 9 deletions

View File

@ -83,9 +83,10 @@
init_db_backend() ->
case is_store_enabled() of
true ->
ok = emqx_trie:create_session_trie(),
ok = emqx_session_router:create_router_tab(),
case storage_type() of
StorageType = storage_type(),
ok = emqx_trie:create_session_trie(StorageType),
ok = emqx_session_router:create_router_tab(StorageType),
case StorageType of
disc ->
emqx_persistent_session_mnesia_disc_backend:create_tables(),
persistent_term:put(?db_backend_key, emqx_persistent_session_mnesia_disc_backend);

View File

@ -25,7 +25,7 @@
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
-export([ create_init_tab/0
, create_router_tab/0
, create_router_tab/1
, start_link/2]).
%% Route APIs
@ -65,7 +65,7 @@
%% Mnesia bootstrap
%%--------------------------------------------------------------------
create_router_tab() ->
create_router_tab(disc) ->
ok = mria:create_table(?ROUTE_DISC_TAB, [
{type, bag},
{rlog_shard, ?ROUTE_SHARD},
@ -73,7 +73,8 @@ create_router_tab() ->
{record_name, route},
{attributes, record_info(fields, route)},
{storage_properties, [{ets, [{read_concurrency, true},
{write_concurrency, true}]}]}]),
{write_concurrency, true}]}]}]);
create_router_tab(ram) ->
ok = mria:create_table(?ROUTE_RAM_TAB, [
{type, bag},
{rlog_shard, ?ROUTE_SHARD},

View File

@ -20,7 +20,7 @@
%% Mnesia bootstrap
-export([ mnesia/1
, create_session_trie/0
, create_session_trie/1
]).
-boot_mnesia({mnesia, [boot]}).
@ -76,7 +76,7 @@ mnesia(boot) ->
{type, ordered_set},
{storage_properties, StoreProps}]).
create_session_trie() ->
create_session_trie(disc) ->
StoreProps = [{ets, [{read_concurrency, true},
{write_concurrency, true}
]}],
@ -86,7 +86,11 @@ create_session_trie() ->
{record_name, ?TRIE},
{attributes, record_info(fields, ?TRIE)},
{type, ordered_set},
{storage_properties, StoreProps}]),
{storage_properties, StoreProps}]);
create_session_trie(ram) ->
StoreProps = [{ets, [{read_concurrency, true},
{write_concurrency, true}
]}],
ok = mria:create_table(?SESSION_RAM_TRIE,
[{rlog_shard, ?ROUTE_SHARD},
{storage, ram_copies},