View Source partisan_peer_service_manager behaviour (partisan v5.0.0-rc.8)

Summary

Functions

Tries to create a new connection to a node, but only if required. If successful it stores the new connection record in the partisan_peer_connections table.

Create a new connection to a node specified by NodeSpec and options Opts. If a new connection is created it will be stored in the partisan_peer_connections table.

Internal function used by peer_service manager implementations to forward a message to a local process identified by ServerRef (or a global process when connected using disterl). Trying to send a message to a remote server reference when the process is located at a node connected with Partisan will return ok but will not succeed.
Kill all connections with node in Nodes and for each call function Fun passing the node as argument
Kill all connections with node in Nodes and for each call function Fun passing the node as argument
mynode() deprecated
myself() deprecated
Send a message to a remote peer_service_manager.
If Mod implements callback supports_capability/1 returns the result of calling the callback passing argument Arg. Otherwise, returns false.

Types

-type connect_opts() :: #{prune => boolean()}.
-type forward_opts() ::
    #{ack => boolean(),
      retransmission => boolean(),
      causal_label => atom(),
      channel => partisan:channel(),
      clock => any(),
      partition_key => non_neg_integer(),
      transitive => boolean(),
      atom() => any()} |
    [{ack, boolean()} |
     {causal_label, atom()} |
     {channel, partisan:channel()} |
     {clock, any()} |
     {partition_key, non_neg_integer()} |
     {transitive, boolean()} |
     {atom(), any()}].
-type on_event_fun() :: fun(() -> ok) | fun((node()) -> ok) | fun((node(), partisan:channel()) -> ok).
-type partitions() :: [{reference(), partisan:node_spec()}].
-type server_ref() ::
    partisan:any_pid() |
    partisan:any_name() |
    partisan_remote_ref:encoded_pid() |
    partisan_remote_ref:encoded_name() |
    {RegName :: atom(), node()} |
    {global, RegName :: atom()} |
    {via, module(), ViaName :: atom()}.

Callbacks

-callback cast_message(ServerRef :: server_ref(), Msg :: partisan:message()) -> ok.
-callback cast_message(ServerRef :: server_ref(), Msg :: partisan:message(), Opts :: forward_opts()) -> ok.
-callback cast_message(Node :: node(),
             ServerRef :: server_ref(),
             Msg :: partisan:message(),
             Opts :: forward_opts()) ->
                ok.
-callback decode(term()) -> term().
-callback forward_message(ServerRef :: server_ref(), Msg :: partisan:message()) -> ok.
-callback forward_message(ServerRef :: server_ref(), Msg :: partisan:message(), Opts :: forward_opts()) ->
                   ok.
-callback forward_message(Node :: node(),
                ServerRef :: server_ref(),
                Msg :: partisan:message(),
                Opts :: forward_opts()) ->
                   ok.
-callback get_local_state() -> term().
-callback inject_partition(partisan:node_spec(), ttl()) -> {ok, reference()} | {error, not_implemented}.
-callback join(partisan:node_spec()) -> ok.
-callback leave() -> ok.
-callback leave(partisan:node_spec()) -> ok | {error, not_implemented}.
-callback members() -> [node()].
Link to this callback

members_for_orchestration/0

View Source
-callback members_for_orchestration() -> [partisan:node_spec()].
-callback on_down(node(), on_event_fun()) -> ok | {error, not_implemented}.
-callback on_down(node(), on_event_fun(), #{channel => partisan:channel()}) -> ok | {error, not_implemented}.
-callback on_up(node(), on_event_fun()) -> ok | {error, not_implemented}.
-callback on_up(node(), on_event_fun(), #{channel => partisan:channel()}) -> ok | {error, not_implemented}.
-callback partitions() -> {ok, partitions()} | {error, not_implemented}.
-callback receive_message(node(), partisan:channel(), any()) -> ok.
-callback reserve(atom()) -> ok | {error, no_available_slots}.
-callback resolve_partition(reference()) -> ok | {error, not_implemented}.
-callback send_message(node(), partisan:message()) -> ok.
-callback start_link() -> {ok, pid()} | ignore | {error, term()}.
Link to this callback

supports_capability/1

View Source (optional)
-callback supports_capability(Arg :: atom()) -> boolean().
-callback sync_join(partisan:node_spec()) -> ok | {error, not_implemented}.
-callback update_members([node()]) -> ok | {error, not_implemented}.

Functions

-spec connect(NodeSpec :: partisan:node_spec()) -> ok.

Tries to create a new connection to a node, but only if required. If successful it stores the new connection record in the partisan_peer_connections table.

This function calls connect/2 with options #{prune => false}.
-spec connect(NodeSpec :: partisan:node_spec(), #{prune := true}) ->
           {ok, StaleSpecs :: [partisan:node_spec()]};
       (NodeSpec :: partisan:node_spec(), #{prune := false}) -> ok.

Create a new connection to a node specified by NodeSpec and options Opts. If a new connection is created it will be stored in the partisan_peer_connections table.

If option prune is true returns the tuple {ok, L :: [ partisan:node_spec()]} where list L is the list of nodes specifications for all stale nodes. Otherwise returns ok.

A specification is stale if there is another specification for the same node for which we already have one or more active connections. A stale specification will exist when a node has crashed (without leaving the cluster) and later on returned with a different IP address i.e. a normal situation on cloud orchestration platforms. In this case the membership set (partisan_membership_set) will have two node specifications for the same node (with differing values for the listen_addrs property).

See the section **Stale Specifications** in partisan_membership_set.
-spec deliver(ServerRef :: server_ref(), Msg :: any()) -> ok.
Internal function used by peer_service manager implementations to forward a message to a local process identified by ServerRef (or a global process when connected using disterl). Trying to send a message to a remote server reference when the process is located at a node connected with Partisan will return ok but will not succeed.
Kill all connections with node in Nodes and for each call function Fun passing the node as argument
Kill all connections with node in Nodes and for each call function Fun passing the node as argument
This function is deprecated. use partisan:node/0 instead.
-spec mynode() -> atom().
This function is deprecated. use partisan:node_spec/0 instead.
-spec myself() -> partisan:node_spec().
Link to this function

send_message(Node, Message)

View Source
-spec send_message(node(), partisan:message()) -> ok.
Send a message to a remote peer_service_manager.
Link to this function

supports_capability(Mode, Arg)

View Source
-spec supports_capability(Mode :: module(), Arg :: atom()) -> boolean().
If Mod implements callback supports_capability/1 returns the result of calling the callback passing argument Arg. Otherwise, returns false.