partisan_peer_connections (partisan v6.0.0)

View Source

Summary

Functions

Returns the channel name of the connection

Finds connection for a node.

Finds connection for a node.

Finds connection for a node and channel.

Finds connection for a node and channel.

Returns the number of connections for node Node.

Returns the nbr of connections for node Node and channel Channel.

Sends the *same* message to several peers, encoding it once.

Return a pid to use for message dispatch.

Return a pid to use for message dispatch.

Return a {ok, Pid} where Pid is the connection pid to use for message dispatch. If channel Channel is disconnected it falls back to a default channel connection if one exists. If no connections exist returns {error, disconnected}.

Returns a tuple {ok, Value}, where Value is an instance of info() associated with Node, or error if no info is associated with Node.

Creates a new connections table. The owner of the table is the calling process and the table is protected so only the owner can write to it.

Returns true is this node is connected to NodeOrName. If Node is this node, returns true.

Returns true is this node is connected to NodeOrName. If Node is this node, returns true.

Returns true is this node has all the requested connections (parallelism configuration parameter) for all the configured channels with node NodeOrSpec.

Returns a list of all nodes specifications connected to this node.

Returns a list of all nodes connected to this node through normal connections (that is, hidden nodes are not listed).

Returns the pids for all the active connection for a node.

Returns the pids for all the active connection for a node and channel.

Prune all occurrences of a connection pid returns the node where the pruned pid was found. Equivalent to prune(Arg, undefined).

Same as prune/1 but allows passing a Reason (e.g. the connection process' exit reason) that is added to the metadata of the resulting [partisan, connection, down] telemetry event.

Types

connection/0

-type connection() ::
          #partisan_peer_connection{pid :: maybe_var(pid()),
                                    node :: maybe_var(node()),
                                    channel :: maybe_var(partisan:channel()),
                                    listen_addr ::
                                        maybe_var(partisan:listen_addr()) | listen_addr_spec(),
                                    timestamp :: maybe_var(non_neg_integer())}.

connections/0

-type connections() :: [connection()].

info/0

-type info() ::
          #partisan_peer_info{node :: maybe_var(node()),
                              node_spec :: maybe_var(partisan:node_spec()),
                              connection_count :: maybe_var(non_neg_integer()),
                              timestamp :: maybe_var(non_neg_integer())}.

listen_addr_spec/0

-type listen_addr_spec() :: #{ip := var(), port := var()}.

maybe_var/1

-type maybe_var(T) :: T | var().

optional/1

-type optional(T) :: T | undefined.

var/0

-type var() :: '_' | '$1' | '$2' | '$3'.

Functions

channel(Partisan_peer_connection)

-spec channel(connection()) -> partisan:channel().

Returns the channel name of the connection

connections()

-spec connections() -> connections().

Finds connection for a node.

connections(NodeOrSpec)

-spec connections(NodeOrSpec :: atom() | partisan:node_spec()) -> connections().

Finds connection for a node.

connections(NodeOrSpec, Channels)

-spec connections(NodeOrSpec :: maybe_var(atom() | partisan:node_spec()),
                  Channels :: maybe_var(partisan:channel() | [partisan:channel()])) ->
                     connections() | no_return().

Finds connection for a node and channel.

connections(NodeOrSpec, Channels, ListenAddr)

-spec connections(NodeOrSpec :: maybe_var(atom() | partisan:node_spec()),
                  Channels :: maybe_var(partisan:channel() | [partisan:channel()]),
                  ListenAddr :: partisan:listen_addr()) ->
                     connections() | no_return().

Finds connection for a node and channel.

count()

-spec count() -> non_neg_integer().

count(Arg)

-spec count(Arg :: partisan:node_spec() | node() | info()) -> non_neg_integer().

Returns the number of connections for node Node.

When passed a partisan:node_spec() as Arg it is equivalent to calling count/2 with a wildcard as a second argument i.e. '_'. However, when passed a node()` as `Arg is uses the more efficient ets` `lookup_element operation.

count(NodeOrSpec, Channels)

-spec count(NodeOrSpec :: maybe_var(partisan:node_spec() | node()),
            Channels :: maybe_var(partisan:channel() | [partisan:channel()])) ->
               non_neg_integer() | no_return().

Returns the nbr of connections for node Node and channel Channel.

count(Node, Channels, ListenAddr)

-spec count(Node :: maybe_var(node() | partisan:node_spec()),
            Channels :: maybe_var(partisan:channel() | [partisan:channel()]),
            ListenAddr :: partisan:listen_addr()) ->
               Count :: non_neg_integer().

dispatch(_)

-spec dispatch(any()) -> ok | {error, disconnected | not_yet_connected}.

dispatch_many(Peers, ServerRef, Message, Channel)

-spec dispatch_many(Peers :: [node()],
                    ServerRef :: partisan:server_ref(),
                    Message :: any(),
                    Channel :: partisan:channel()) ->
                       Deferred :: [node()].

Sends the *same* message to several peers, encoding it once.

A fan-out (plumtree's eager push to its peer set) otherwise encodes an identical payload once per peer, because each peer's send is an independent forward_message/4 call. The wire term is byte-identical for every peer — the destination is the group's registered name, which is the same atom on every node — so one encoding serves all of them.

Returns the peers this function did **not** handle. The caller must send to those by the ordinary per-peer path. A peer is deferred when it needs routing this function deliberately does not reimplement:

  • the local node, which is a direct delivery rather than a send;
  • a peer reachable over disterl while connect_disterl is set, which forward_message/4 short-circuits with erlang:send/3;
  • a peer with no connection on Channel, which has its own not-yet-connected / disconnected handling;
  • every peer, when disable_fast_forward is set — that option exists to force traffic through the peer service manager.

Message must already be in its final wire form, i.e. whatever forward_message/4 would have passed to dispatch/1 ($gen_cast-wrapped and padded as applicable).

dispatch_pid(Node)

-spec dispatch_pid(node() | partisan:node_spec()) ->
                      {ok, pid()} | {error, disconnected | not_yet_connected | notalive}.

Return a pid to use for message dispatch.

dispatch_pid(Node, Channel)

-spec dispatch_pid(Node :: node() | partisan:node_spec(), Channel :: partisan:channel()) ->
                      {ok, pid()} | {error, disconnected | not_yet_connected | notalive} | no_return().

Return a pid to use for message dispatch.

dispatch_pid(Node, Channel, PartitionKey)

-spec dispatch_pid(Node :: node() | partisan:node_spec(),
                   Channel :: partisan:channel(),
                   PartitionKey :: optional(any())) ->
                      {ok, pid()} | {error, disconnected | not_yet_connected | notalive} | no_return().

Return a {ok, Pid} where Pid is the connection pid to use for message dispatch. If channel Channel is disconnected it falls back to a default channel connection if one exists. If no connections exist returns {error, disconnected}.

encode_for_channel(Term, Channel)

erase(Pid)

-spec erase(pid() | node() | partisan:node_spec()) -> ok.

fold(Fun, AccIn)

-spec fold(Fun :: fun((partisan:node_spec(), connections(), Acc1 :: any()) -> Acc2 :: any()),
           AccIn :: any()) ->
              AccOut :: any().

foreach(Fun)

-spec foreach(Fun :: fun((info(), connections()) -> ok)) -> ok.

foreach(Fun, Node)

info(NodeOrSpec)

-spec info(NodeOrSpec :: partisan:node_spec() | node()) -> {ok, info()} | error.

Returns a tuple {ok, Value}, where Value is an instance of info() associated with Node, or error if no info is associated with Node.

init()

-spec init() -> ok.

Creates a new connections table. The owner of the table is the calling process and the table is protected so only the owner can write to it.

is_connected(NodeOrSpec)

-spec is_connected(NodeOrSpec :: partisan:node_spec() | node()) -> boolean().

Returns true is this node is connected to NodeOrName. If Node is this node, returns true.

is_connected(NodeOrSpec, Channels)

-spec is_connected(NodeOrSpec :: partisan:node_spec() | node(),
                   Channels :: maybe_var(partisan:channel() | [partisan:channel()])) ->
                      boolean() | no_return().

Returns true is this node is connected to NodeOrName. If Node is this node, returns true.

is_fully_connected(Peer)

-spec is_fully_connected(Peer :: partisan:node_spec() | node()) -> boolean().

Returns true is this node has all the requested connections (parallelism configuration parameter) for all the configured channels with node NodeOrSpec.

kill(Node)

-spec kill(node()) -> ok.

kill_all()

-spec kill_all() -> ok.

listen_addr(Partisan_peer_connection)

-spec listen_addr(connection()) -> partisan:listen_addr() | no_return().

node(Partisan_peer_info)

-spec node(info() | connection()) -> node() | no_return().

node_spec(Partisan_peer_info)

-spec node_spec(info() | connection()) -> partisan:node_spec() | no_return().

node_specs()

Returns a list of all nodes specifications connected to this node.

nodes()

-spec nodes() -> [node()].

Returns a list of all nodes connected to this node through normal connections (that is, hidden nodes are not listed).

pid(Partisan_peer_connection)

-spec pid(connection()) -> pid().

processes(NodeOrSpec)

-spec processes(NodeOrSpec :: atom() | partisan:node_spec()) -> [pid()].

Returns the pids for all the active connection for a node.

processes(NodeOrSpec, Channel)

-spec processes(NodeOrSpec :: node() | partisan:node_spec(), Channel :: maybe_var(partisan:channel())) ->
                   [pid()].

Returns the pids for all the active connection for a node and channel.

prune(Arg)

-spec prune(pid() | node() | partisan:node_spec()) -> {info(), connections()} | no_return().

Prune all occurrences of a connection pid returns the node where the pruned pid was found. Equivalent to prune(Arg, undefined).

prune(Node, Reason)

-spec prune(pid() | node() | partisan:node_spec(), Reason :: term()) ->
               {info(), connections()} | no_return().

Same as prune/1 but allows passing a Reason (e.g. the connection process' exit reason) that is added to the metadata of the resulting [partisan, connection, down] telemetry event.

store(Node, Pid, Channel, LitenAddr)

-spec store(Node :: partisan:node_spec(),
            Pid :: pid(),
            Channel :: partisan:channel(),
            LitenAddr :: partisan:listen_addr()) ->
               ok | no_return().

Store a connection

timestamp(Partisan_peer_info)

-spec timestamp(info() | connection()) -> non_neg_integer() | no_return().