refactor(emqx_gateway_cm): no need to keep locker pid in state

For two reasons
1. Every other places computes the process register name from gwname
2. The ekka_locker api spec only accepts atom but not pid
This commit is contained in:
Zaiming (Stone) Shi 2023-12-06 10:37:07 +01:00
parent c44d4e7bd4
commit 6affda8194
1 changed files with 4 additions and 6 deletions

View File

@ -96,8 +96,6 @@
-record(state, { -record(state, {
%% Gateway Name %% Gateway Name
gwname :: gateway_name(), gwname :: gateway_name(),
%% ClientId Locker for CM
locker :: pid(),
%% ClientId Registry server %% ClientId Registry server
registry :: pid(), registry :: pid(),
chan_pmon :: emqx_pmon:pmon() chan_pmon :: emqx_pmon:pmon()
@ -776,7 +774,8 @@ init(Options) ->
{ok, Registry} = emqx_gateway_cm_registry:start_link(GwName), {ok, Registry} = emqx_gateway_cm_registry:start_link(GwName),
%% Start locker process %% Start locker process
{ok, Locker} = ekka_locker:start_link(lockername(GwName)), LockerName = lockername(GwName),
{ok, _LockerPid} = ekka_locker:start_link(lockername(GwName)),
%% Interval update stats %% Interval update stats
%% TODO: v0.2 %% TODO: v0.2
@ -784,7 +783,6 @@ init(Options) ->
{ok, #state{ {ok, #state{
gwname = GwName, gwname = GwName,
locker = Locker,
registry = Registry, registry = Registry,
chan_pmon = emqx_pmon:new() chan_pmon = emqx_pmon:new()
}}. }}.
@ -812,9 +810,9 @@ handle_info(
handle_info(_Info, State) -> handle_info(_Info, State) ->
{noreply, State}. {noreply, State}.
terminate(_Reason, #state{registry = Registry, locker = Locker}) -> terminate(_Reason, #state{registry = Registry, gwname = GwName}) ->
_ = gen_server:stop(Registry), _ = gen_server:stop(Registry),
_ = ekka_locker:stop(Locker), _ = ekka_locker:stop(lockername(GwName)),
ok. ok.
code_change(_OldVsn, State, _Extra) -> code_change(_OldVsn, State, _Extra) ->