Skip to content

Commit

Permalink
replace ergw_sx_node_mngr with ergw_sx_node_reg functions
Browse files Browse the repository at this point in the history
The new regine actions functionality allows us to get rid of
the extra manager process. That process was there only to
serialize and synchronize sx node process creation with the
registry.
  • Loading branch information
RoadRunnr committed Oct 21, 2021
1 parent 8332338 commit 1113111
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 90 deletions.
2 changes: 1 addition & 1 deletion apps/ergw_core/src/ergw_core.erl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ attach_tdf(SxNode, #{node_selection := NodeSelections} = Opts, _, true) ->
NodeLookup([NodeSelection | NextSelection]) ->
case ergw_node_selection:lookup(SxNode, NodeSelection) of
{Node, IP4, IP6} ->
ergw_sx_node_mngr:connect(Node, NodeSelection, IP4, IP6);
ergw_sx_node_reg:connect(Node, NodeSelection, IP4, IP6);
_Other ->
?LOG(warning, "TDF lookup for ~p failed ~p", [SxNode, _Other]),
NodeLookup(NextSelection)
Expand Down
1 change: 0 additions & 1 deletion apps/ergw_core/src/ergw_core_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ init([]) ->
?CHILD(ergw_socket_sup, supervisor, []),
?CHILD(ergw_sx_node_reg, worker, []),
?CHILD(ergw_sx_node_sup, supervisor, []),
?CHILD(ergw_sx_node_mngr, worker, []),
?CHILD(gtp_proxy_ds, worker, []),
?CHILD(ergw_ip_pool_sup, supervisor, []),
?CHILD(ergw_core, worker, [])
Expand Down
11 changes: 5 additions & 6 deletions apps/ergw_core/src/ergw_sx_node.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ add_sx_node(Name, Opts0) ->
connect_sx_node(_Node, #{connect := false}) ->
ok;
connect_sx_node(Node, #{raddr := IP4} = _Opts) when tuple_size(IP4) =:= 4 ->
ergw_sx_node_mngr:connect(Node, default, [IP4], []);
ergw_sx_node_reg:connect(Node, default, [IP4], []);
connect_sx_node(Node, #{raddr := IP6} = _Opts) when tuple_size(IP6) =:= 8 ->
ergw_sx_node_mngr:connect(Node, default, [], [IP6]);
ergw_sx_node_reg:connect(Node, default, [], [IP6]);
connect_sx_node(Node, #{node_selection := NodeSelect} = Opts) ->
case ergw_node_selection:lookup(Node, NodeSelect) of
{_, IP4, IP6} ->
ergw_sx_node_mngr:connect(Node, NodeSelect, IP4, IP6);
ergw_sx_node_reg:connect(Node, NodeSelect, IP4, IP6);
_Other ->
%% TBD
{error, {badarg, [Node, Opts]}}
Expand Down Expand Up @@ -339,7 +339,7 @@ port_message(_Server, Request, Msg, _Resent) ->
callback_mode() -> [handle_event_function, state_enter].

init([Parent, Node, NodeSelect, IP4, IP6, NotifyUp]) ->
ergw_sx_node_reg:register(Node, self()),
proc_lib:init_ack(Parent, {ok, self(), Node}),

{ok, CP, Socket, SockInfo} = ergw_sx_socket:id(),
{ok, TEI} = ergw_tei_mngr:alloc_tei(Socket),
Expand Down Expand Up @@ -384,7 +384,6 @@ init([Parent, Node, NodeSelect, IP4, IP6, NotifyUp]) ->
notify_up = NotifyUp
},
Data = init_node_cfg(Data0),
proc_lib:init_ack(Parent, {ok, self()}),

resolve_and_enter_loop(Node, IP, Data).

Expand Down Expand Up @@ -746,7 +745,7 @@ connect_node({Name, _, _, _, _}, _NodeSelect, Available, Expects)
Expects;
connect_node({Node, _, _, IP4, IP6}, NodeSelect, _Available, Expects) ->
NotifyUp = {self(), make_ref()},
ergw_sx_node_mngr:connect(Node, NodeSelect, IP4, IP6, [NotifyUp]),
ergw_sx_node_reg:connect(Node, NodeSelect, IP4, IP6, [NotifyUp]),
[NotifyUp | Expects].

notify_up(Server, [{Pid, Ref}|_] = NotifyUp) when is_pid(Pid), is_reference(Ref) ->
Expand Down
81 changes: 0 additions & 81 deletions apps/ergw_core/src/ergw_sx_node_mngr.erl

This file was deleted.

26 changes: 25 additions & 1 deletion apps/ergw_core/src/ergw_sx_node_reg.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-behaviour(regine_server).

%% API
-export([start_link/0]).
-export([start_link/0, connect/4, connect/5]).
-export([register/2, lookup/1, up/2, down/1, available/0]).
-export([all/0]).
-export([count_available/0, count_monitors/1]).
Expand Down Expand Up @@ -48,6 +48,19 @@ lookup(Key) ->
{error, not_found}
end.

connect(Node, NodeSelect, IP4, IP6) ->
connect(Node, NodeSelect, IP4, IP6, []).

connect(Node, NodeSelect, IP4, IP6, NotifyUp)
when is_list(NotifyUp) ->
case lookup(Node) of
{ok, Pid} = Result ->
ergw_sx_node:notify_up(Pid, NotifyUp),
Result;
_ ->
regine_server:call(?SERVER, {connect, Node, NodeSelect, IP4, IP6, NotifyUp})
end.

up(Key, Caps) ->
regine_server:call(?SERVER, {up, Key, Caps}).

Expand Down Expand Up @@ -95,6 +108,17 @@ handle_pid_remove(_Pid, Keys, State) ->
handle_death(_Pid, _Reason, State) ->
State.

%% serialize lockup/new
handle_call({connect, Node, NodeSelect, IP4, IP6, NotifyUp}, _From, State) ->
case lookup(Node) of
{ok, Pid} = Result ->
ergw_sx_node:notify_up(Pid, NotifyUp),
{reply, Result, State};
_ ->
{ok, Pid, RegKey} = ergw_sx_node_sup:new(Node, NodeSelect, IP4, IP6, NotifyUp),
{reply, {ok, Pid}, State, [{register, Pid, RegKey, undefined}]}
end;

handle_call({up, Key, Caps}, _From, State) ->
case lookup(Key) of
{ok, Pid} ->
Expand Down

0 comments on commit 1113111

Please sign in to comment.