chore(authentication): Migrate to RLOG
This commit is contained in:
parent
c79e478c42
commit
6063fc72f7
|
@ -39,3 +39,5 @@
|
|||
, services :: [{service_name(), #service{}}]
|
||||
, created_at :: integer()
|
||||
}).
|
||||
|
||||
-define(AUTH_SHARD, emqx_authentication_shard).
|
||||
|
|
|
@ -56,6 +56,9 @@
|
|||
-define(CHAIN_TAB, emqx_authentication_chain).
|
||||
-define(SERVICE_TYPE_TAB, emqx_authentication_service_type).
|
||||
|
||||
-rlog_shard({?AUTH_SHARD, ?CHAIN_TAB}).
|
||||
-rlog_shard({?AUTH_SHARD, ?SERVICE_TYPE_TAB}).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Mnesia bootstrap
|
||||
%%------------------------------------------------------------------------------
|
||||
|
@ -513,7 +516,7 @@ trans(Fun) ->
|
|||
trans(Fun, []).
|
||||
|
||||
trans(Fun, Args) ->
|
||||
case mnesia:transaction(Fun, Args) of
|
||||
case ekka_mnesia:transaction(?AUTH_SHARD, Fun, Args) of
|
||||
{atomic, Res} -> Res;
|
||||
{aborted, Reason} -> {error, Reason}
|
||||
end.
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
-emqx_plugin(?MODULE).
|
||||
|
||||
-include("emqx_authentication.hrl").
|
||||
|
||||
%% Application callbacks
|
||||
-export([ start/2
|
||||
, stop/1
|
||||
|
@ -27,6 +29,7 @@
|
|||
|
||||
start(_StartType, _StartArgs) ->
|
||||
{ok, Sup} = emqx_authentication_sup:start_link(),
|
||||
ok = ekka_rlog:wait_for_shards([?AUTH_SHARD], infinity),
|
||||
ok = emqx_authentication:register_service_types(),
|
||||
{ok, Sup}.
|
||||
|
||||
|
|
|
@ -72,6 +72,8 @@
|
|||
|
||||
-define(TAB, mnesia_basic_auth).
|
||||
|
||||
-rlog_shard({?AUTH_SHARD, ?TAB}).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Mnesia bootstrap
|
||||
%%------------------------------------------------------------------------------
|
||||
|
@ -330,7 +332,7 @@ trans(Fun) ->
|
|||
trans(Fun, []).
|
||||
|
||||
trans(Fun, Args) ->
|
||||
case mnesia:transaction(Fun, Args) of
|
||||
case ekka_mnesia:transaction(?AUTH_SHARD, Fun, Args) of
|
||||
{atomic, Res} -> Res;
|
||||
{aborted, Reason} -> {error, Reason}
|
||||
end.
|
||||
|
|
|
@ -28,6 +28,7 @@ all() ->
|
|||
emqx_ct:all(?MODULE).
|
||||
|
||||
init_per_suite(Config) ->
|
||||
application:set_env(ekka, strict_mode, true),
|
||||
emqx_ct_helpers:start_apps([emqx_authentication]),
|
||||
Config.
|
||||
|
||||
|
@ -40,7 +41,7 @@ t_chain(_) ->
|
|||
?assertMatch({ok, #{id := ChainID, services := []}}, ?AUTH:create_chain(#{id => ChainID})),
|
||||
?assertEqual({error, {already_exists, {chain, ChainID}}}, ?AUTH:create_chain(#{id => ChainID})),
|
||||
?assertMatch({ok, #{id := ChainID, services := []}}, ?AUTH:lookup_chain(ChainID)),
|
||||
?assertEqual(ok, ?AUTH:delete_chain(ChainID)),
|
||||
?assertEqual(ok, ?AUTH:delete_chain(ChainID)),
|
||||
?assertMatch({error, {not_found, {chain, ChainID}}}, ?AUTH:lookup_chain(ChainID)),
|
||||
ok.
|
||||
|
||||
|
@ -186,6 +187,3 @@ t_multi_mnesia_service(_) ->
|
|||
?assertEqual(ok, ?AUTH:authenticate(ClientInfo2)),
|
||||
?assertEqual(ok, ?AUTH:delete_chain(ChainID)),
|
||||
ok.
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue