Skip to content

Commit

Permalink
Use erpc:multicall in cets_status
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Sep 14, 2023
1 parent d831ec6 commit ca6ca36
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions src/cets_status.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,24 @@ status(Disco) when is_atom(Disco) ->
%% Nodes, that host the discovery process
-spec available_nodes(disco_name(), [node(), ...]) -> [node()].
available_nodes(Disco, OnlineNodes) ->
lists:filter(fun(Node) -> is_disco_running_on(Node, Disco) end, OnlineNodes).
Results = erpc:multicall(OnlineNodes, erlang, whereis, [Disco], infinity),
[Node || {Node, {ok, Pid}} <- lists:zip(OnlineNodes, Results), is_pid(Pid)].

remote_nodes_without_disco(DiscoNodes, AvailNodes, OnlineNodes) ->
lists:filter(fun(Node) -> is_node_without_disco(Node, AvailNodes, OnlineNodes) end, DiscoNodes).

is_node_without_disco(Node, AvailNodes, OnlineNodes) ->
lists:member(Node, OnlineNodes) andalso not lists:member(Node, AvailNodes).

-spec is_disco_running_on(node(), disco_name()) -> boolean().
is_disco_running_on(Node, Disco) ->
is_pid(rpc:call(Node, erlang, whereis, [Disco])).

-spec get_node_to_tab_nodes_map(AvailNodes, Disco) -> OtherTabNodes when
AvailNodes :: [node()],
Disco :: disco_name(),
OtherTabNodes :: node_to_tab_nodes_map().
get_node_to_tab_nodes_map(AvailNodes, Disco) ->
OtherNodes = lists:delete(node(), AvailNodes),
OtherTabNodes = [
{Node, get_table_to_other_nodes_map_from_disco(Node, Disco)}
|| Node <- OtherNodes
],
F = get_local_table_to_other_nodes_map_from_disco,
Results = erpc:multicall(OtherNodes, ?MODULE, F, [Disco], infinity),
OtherTabNodes = [{Node, Result} || {Node, {ok, Result}} <- lists:zip(OtherNodes, Results)],
maps:from_list(OtherTabNodes).

%% Nodes that has our local tables running (but could also have some unknown tables).
Expand Down Expand Up @@ -179,21 +175,7 @@ all_tables(Expected, OtherTabNodes) ->
ordsets:union(TableVariants).

%% Returns nodes for each table hosted on node()
-spec get_table_to_other_nodes_map_from_disco(node(), disco_name()) -> tab_nodes_map().
get_table_to_other_nodes_map_from_disco(Node, Disco) ->
try
erpc:call(Node, ?MODULE, get_local_table_to_other_nodes_map_from_disco, [Disco])
catch
Class:Reason ->
?LOG_ERROR(#{
what => get_table_to_other_nodes_map_failed,
node => Node,
class => Class,
reason => Reason
}),
#{}
end.

-spec get_local_table_to_other_nodes_map_from_disco(disco_name()) -> tab_nodes_map().
get_local_table_to_other_nodes_map_from_disco(Disco) ->
{ok, Tables} = cets_discovery:get_tables(Disco),
get_local_table_to_other_nodes_map(Tables).
Expand Down

0 comments on commit ca6ca36

Please sign in to comment.