Use a function call effect

so that this state transition applied on the leader node only.
This commit is contained in:
Michael Klishin 2019-06-03 16:05:14 +03:00
parent e004f0bb91
commit 2613595b5e
1 changed files with 6 additions and 4 deletions

View File

@ -45,11 +45,13 @@ apply(Meta, {register, ClientId, Pid}, #state{client_ids = Ids} = State0) ->
{Effects, Ids1} = {Effects, Ids1} =
case maps:find(ClientId, Ids) of case maps:find(ClientId, Ids) of
{ok, OldPid} when Pid =/= OldPid -> {ok, OldPid} when Pid =/= OldPid ->
catch gen_server2:cast(OldPid, duplicate_id), Effects0 = [{demonitor, process, OldPid},
{[{demonitor, process, OldPid}, {monitor, process, Pid},
{monitor, process, Pid}], maps:remove(ClientId, Ids)}; {mod_call, gen_server2, cast, [OldPid, duplicate_id]}],
{Effects0, maps:remove(ClientId, Ids)};
error -> error ->
{[{monitor, process, Pid}], Ids} Effects0 = [{monitor, process, Pid}],
{Effects0, Ids}
end, end,
State = State0#state{client_ids = maps:put(ClientId, Pid, Ids1)}, State = State0#state{client_ids = maps:put(ClientId, Pid, Ids1)},
{State, ok, Effects ++ snapshot_effects(Meta, State)}; {State, ok, Effects ++ snapshot_effects(Meta, State)};