Add 'enable_session_registry' config
This commit is contained in:
parent
7fe3d59c28
commit
abe9aff062
|
@ -1898,6 +1898,11 @@ plugins.expand_plugins_dir = {{ platform_plugins_dir }}/
|
|||
## Default: 1m, 1 minute
|
||||
broker.sys_interval = 1m
|
||||
|
||||
## Enable global session registry.
|
||||
##
|
||||
## Value: on | off
|
||||
broker.enable_session_registry = on
|
||||
|
||||
## Session locking strategy in a cluster.
|
||||
##
|
||||
## Value: Enum
|
||||
|
|
|
@ -1723,6 +1723,11 @@ end}.
|
|||
{default, "1m"}
|
||||
]}.
|
||||
|
||||
{mapping, "broker.enable_session_registry", "emqx.enable_session_registry", [
|
||||
{default, on},
|
||||
{datatype, flag}
|
||||
]}.
|
||||
|
||||
{mapping, "broker.session_locking_strategy", "emqx.session_locking_strategy", [
|
||||
{default, quorum},
|
||||
{datatype, {enum, [local,one,quorum,all]}}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
-export([start_link/0]).
|
||||
-export([is_enabled/0]).
|
||||
|
||||
-export([register_session/1, lookup_session/1, unregister_session/1]).
|
||||
|
||||
%% gen_server callbacks
|
||||
|
@ -41,7 +40,8 @@ start_link() ->
|
|||
gen_server:start_link({local, ?REGISTRY}, ?MODULE, [], []).
|
||||
|
||||
-spec(is_enabled() -> boolean()).
|
||||
is_enabled() -> ets:info(?TAB, name) =/= undefined.
|
||||
is_enabled() ->
|
||||
emqx_config:get_env(enable_session_registry, true).
|
||||
|
||||
-spec(lookup_session(emqx_types:client_id())
|
||||
-> list({emqx_types:client_id(), session_pid()})).
|
||||
|
@ -50,11 +50,17 @@ lookup_session(ClientId) ->
|
|||
|
||||
-spec(register_session({emqx_types:client_id(), session_pid()}) -> ok).
|
||||
register_session({ClientId, SessPid}) when is_binary(ClientId), is_pid(SessPid) ->
|
||||
mnesia:dirty_write(?TAB, record(ClientId, SessPid)).
|
||||
case is_enabled() of
|
||||
true -> mnesia:dirty_write(?TAB, record(ClientId, SessPid));
|
||||
false -> ok
|
||||
end.
|
||||
|
||||
-spec(unregister_session({emqx_types:client_id(), session_pid()}) -> ok).
|
||||
unregister_session({ClientId, SessPid}) when is_binary(ClientId), is_pid(SessPid) ->
|
||||
mnesia:dirty_delete_object(?TAB, record(ClientId, SessPid)).
|
||||
case is_enabled() of
|
||||
true -> mnesia:dirty_delete_object(?TAB, record(ClientId, SessPid));
|
||||
false -> ok
|
||||
end.
|
||||
|
||||
record(ClientId, SessPid) ->
|
||||
#global_session{sid = ClientId, pid = SessPid}.
|
||||
|
|
Loading…
Reference in New Issue