partisan (partisan v6.0.0)

View Source

The primary Partisan API: process operations, messaging, monitoring and cluster membership over Partisan's overlay network.

Partisan replaces Erlang's built-in distribution (disterl) with a configurable overlay of TCP connections organised into channels. Many functions here are counterparts of erlang and net_kernelsend/2, monitor/2, node/1, monitor_nodes/1 and so on — but they operate over that overlay rather than disterl, and they speak in remote references rather than raw pids.

Two ideas underpin the API:

  • Remote references. A raw pid, reference or registered name is only meaningful on the node that created it. Partisan addresses a process, reference or name on a peer by a remote reference — a node-localised, serialisable handle (remote_pid/0, remote_reference/0, remote_name/0). self/0, make_ref/0 and whereis/1 return these forms; see partisan_remote_ref.
  • Channels. Traffic is carried on named channels, each with its own connections and parallelism, so unrelated streams do not queue behind one another. Messaging and monitoring take an optional channel; see channel/0 and channel_opts/0.

Where to start

Configuration is read through partisan_config.

Summary

Types

The identity (a binary) under which this node contributes entries to Partisan's membership CRDT. See partisan_membership_set.

A registered name that is either a local atom or a remote name on a peer.

A process identifier that is either a local pid or a remote pid on a peer.

A reference that is either a local reference or a remote reference on a peer.

The name of a channel: an independently connected, independently parallel class of traffic over the overlay.

A channel's configuration: its parallelism (the number of connections it opens to each peer), and whether it preserves per-sender monotonic ordering and applies compression.

An option for demonitor/2: flush discards a pending DOWN; info reports whether the monitor was still live.

Options controlling how a message is routed — the channel to use, whether to request acknowledgement, a causal label, and so on. Defined by partisan_peer_service_manager.

A key selecting one field of a peer's node info, as returned by node_spec/2.

A peer-plane listen address — an ip and a port.

An arbitrary Erlang term carried as a Partisan message.

An option for monitor_nodes/2: the standard net_kernel node-monitoring options together with a channel selector.

An option for monitor/2 and monitor/3: any standard erlang monitor option, plus {channel, Channel} to bind the monitor — and the eventual DOWN — to a channel.

The full specification of a peer: its node name, the listen_addrs it accepts connections on, and the channels it offers. This is the unit of membership Partisan gossips.

The node-set selector accepted by nodes/1, mirroring the standard erlang node types.

A node-localised, serialisable handle for a registered name on a peer. See partisan_remote_ref.

A node-localised, serialisable handle for a pid on a peer. See partisan_remote_ref.

A node-localised, serialisable handle for a reference on a peer. See partisan_remote_ref.

A message or call destination: a pid or registered name (local or remote), an encoded remote reference, or a {Name, Node}, {global, Name} or {via, Module, Name} tuple. Defined by partisan_peer_service_manager.

Functions

Broadcasts a message originating from this node.

Equivalent to cancel_timer(Ref, []).

Cancels the timer Ref — the Partisan counterpart of erlang:cancel_timer/2.

Casts message Msg to the process identified by ServerRef (a server_ref/0), returning ok. Delivery is asynchronous and best-effort.

Casts message Msg to the process identified by ServerRef, honouring Opts (forward_opts/0). Delivery is asynchronous and best-effort.

Casts message Msg to the process ServerRef on Node, honouring Opts (forward_opts/0). Delivery is asynchronous and best-effort.

Returns the options (channel_opts/0) of the channel named Channel. Fails with badarg if no such channel exists.

Returns the name of the default channel.

Removes the monitor identified by MonitorRef; equivalent to demonitor(Ref, []).

Removes the monitor identified by MonitorRef, with options — Partisan's counterpart of erlang:demonitor/2.

Disconnects the local node from Node — the counterpart of erlang:disconnect_node/1.

Sends an exit signal with reason Reason to the process identified by Pid (a local pid or a remote_pid/0) — the Partisan counterpart of erlang:exit/2. For a remote reference the signal is delivered on the owning node via partisan_rpc.

Forwards message Msg to the process identified by ServerRef (a server_ref/0).

Forwards message Msg to the process identified by ServerRef, honouring Opts (forward_opts/0).

Forwards message Msg to the process ServerRef on Node, honouring Opts (forward_opts/0).

Returns true if the local node is alive — that is, the peer service manager is running and the node can take part in a cluster.

Returns true if this node currently has a connection to NodeOrSpec.

Returns true if this node currently has a connection to NodeOrSpec on Channel.

Returns true if every expected connection to NodeOrSpec is established — one per configured channel at its configured parallelism.

Returns true if Arg belongs to the local node.

Returns true if Arg refers to a name on the local node.

Returns true if Arg refers to the locally registered name Name.

Returns true if Arg (a pid or remote_pid/0) is a pid on the local node.

Returns true if Arg refers to the local pid Pid.

Returns true if Arg (a reference or remote_reference/0) was created on the local node.

Returns true if Arg refers to the local reference LocalRef.

Returns true if Arg is a local process identifier or a remote_pid/0, false otherwise.

Returns true if the process identified by Arg (a local pid or a remote_pid/0) is alive, false otherwise. For a remote reference the check runs on the owning node via partisan_rpc.

Returns true if Arg is a local reference or a remote_reference/0, false otherwise.

Returns true if Arg (a pid or remote_pid/0) is the calling process.

Adds a peer to the cluster; a shortcut for partisan_peer_service:join/1.

Drops the peer connections to Nodes (a node name or a list of them).

Removes the local node from the cluster; a shortcut for partisan_peer_service:leave/0.

Returns a fresh remote reference — the Partisan counterpart of erlang:make_ref/0.

Monitors Term as a process; equivalent to monitor(process, Term).

Sends a monitor request of type Type for the entity identified by Item; equivalent to monitor(Type, Item, []).

Sends a monitor request of type Type for the entity identified by Item, with options.

Turns node-status monitoring of Node on (Flag = true) or off (false); equivalent to monitor_node(Node, Flag, []). Node may be a node name or a node_spec/0.

Turns node-status monitoring of Node on or off, with options.

Subscribes (Flag = true) or unsubscribes (false) the calling process to node-status change messages; equivalent to monitor_nodes(Flag, []).

Subscribes (Flag = true) or unsubscribes (false) the calling process to node-status change messages, with options.

Returns the name of the local node.

Returns the node on which Arg originates.

Returns the node specification (node_spec/0) of the local node.

Returns {ok, NodeSpec} for the node named Node, or {error, Reason}. Equivalent to node_spec(Node, #{}); see node_spec/2 for how the specification is resolved.

Returns {ok, NodeSpec} for the node named Node, or {error, Reason}.

Returns the peers connected to this node over Partisan; equivalent to nodes(visible) and the counterpart of erlang:nodes/0.

Returns nodes of the given type — the counterpart of erlang:nodes/1. When Arg is a list, returns the nodes satisfying any of its elements.

Returns the name of the local node as a binary string.

Returns information about the process Arg (a pid or remote_pid/0), or undefined — the counterpart of erlang:process_info/1.

Returns the requested information Item (an item or a list of items) about the process Arg (a pid or remote_pid/0), or undefined — the counterpart of erlang:process_info/2.

Returns the remote-reference form of the calling process's pid.

Returns the remote-reference form of the calling process's pid, optionally caching it.

Sends message Msg to the destination Dest and returns Msg. Equivalent to send(Dest, Msg, []).

Sends message Msg to the destination Dest.

Equivalent to send_after(Time, Dest, Msg, []).

Spawns Fun on Node and returns a remote_pid/0 for the new process — the Partisan counterpart of erlang:spawn/2. A remote spawn is carried out with partisan_rpc.

Spawns Module:Function(Args) on Node and returns a remote_pid/0 for the new process — the Partisan counterpart of erlang:spawn/4. A remote spawn is carried out with partisan_rpc.

Spawns Fun on Node and monitors it, returning {Pid, MonitorRef} — the Partisan counterpart of erlang:spawn_monitor/2. See monitor/2 for the shape of the reference and the DOWN message.

Spawns Module:Function(Args) on Node and monitors it, returning {Pid, MonitorRef} — the Partisan counterpart of erlang:spawn_monitor/4. See monitor/2 for the shape of the reference and the DOWN message.

Starts the partisan application and all of its dependencies.

Stops the partisan application.

Returns the pid or port registered under Arg, or undefined — the counterpart of erlang:whereis/1.

Types

actor()

-type actor() :: binary().

The identity (a binary) under which this node contributes entries to Partisan's membership CRDT. See partisan_membership_set.

any_name()

-type any_name() :: remote_name() | atom().

A registered name that is either a local atom or a remote name on a peer.

any_pid()

-type any_pid() :: remote_pid() | pid().

A process identifier that is either a local pid or a remote pid on a peer.

any_reference()

-type any_reference() :: remote_reference() | reference().

A reference that is either a local reference or a remote reference on a peer.

channel()

-type channel() :: atom().

The name of a channel: an independently connected, independently parallel class of traffic over the overlay.

channel_opt()

-type channel_opt() :: net_kernel_opt() | {channel, channel()} | {channel_fallback, boolean()}.

channel_opts()

-type channel_opts() ::
          #{parallelism := non_neg_integer(), monotonic => boolean(), compression => boolean() | 0..9}.

A channel's configuration: its parallelism (the number of connections it opens to each peer), and whether it preserves per-sender monotonic ordering and applies compression.

demonitor_opt()

-type demonitor_opt() :: flush | info.

An option for demonitor/2: flush discards a pending DOWN; info reports whether the monitor was still live.

forward_opts()

-type forward_opts() :: partisan_peer_service_manager:forward_opts().

Options controlling how a message is routed — the channel to use, whether to request acknowledgement, a causal label, and so on. Defined by partisan_peer_service_manager.

info_opt()

-type info_opt() ::
          metadata | name | channels | listen_addrs | listen_ip | listen_port | connection_count.

A key selecting one field of a peer's node info, as returned by node_spec/2.

listen_addr()

-type listen_addr() :: #{ip := inet:ip_address(), port := 1..65535}.

A peer-plane listen address — an ip and a port.

message()

-type message() :: term().

An arbitrary Erlang term carried as a Partisan message.

monitor_nodes_opt()

-type monitor_nodes_opt() :: net_kernel_opt() | channel_opt().

An option for monitor_nodes/2: the standard net_kernel node-monitoring options together with a channel selector.

monitor_opt()

-type monitor_opt() :: erlang:monitor_option() | {channel, channel()}.

An option for monitor/2 and monitor/3: any standard erlang monitor option, plus {channel, Channel} to bind the monitor — and the eventual DOWN — to a channel.

net_kernel_opt()

-type net_kernel_opt() :: nodedown_reason | connection_id | {node_type, visible | hidden | all}.

node_spec()

-type node_spec() ::
          #{name := node(), listen_addrs := [listen_addr()], channels := #{channel() => channel_opts()}}.

The full specification of a peer: its node name, the listen_addrs it accepts connections on, and the channels it offers. This is the unit of membership Partisan gossips.

node_type()

-type node_type() :: this | known | visible | connected | hidden.

The node-set selector accepted by nodes/1, mirroring the standard erlang node types.

remote_name()

-type remote_name() :: partisan_remote_ref:n().

A node-localised, serialisable handle for a registered name on a peer. See partisan_remote_ref.

remote_pid()

-type remote_pid() :: partisan_remote_ref:p().

A node-localised, serialisable handle for a pid on a peer. See partisan_remote_ref.

remote_reference()

-type remote_reference() :: partisan_remote_ref:r().

A node-localised, serialisable handle for a reference on a peer. See partisan_remote_ref.

send_after_dst()

-type send_after_dst() ::
          pid() | (RegName :: atom()) | (Pid :: remote_pid()) | (RegName :: remote_name()).

send_after_opts()

-type send_after_opts() :: forward_opts() | [{abs, boolean()}].

send_dst()

-type send_dst() :: erlang:send_destination() | server_ref().

server_ref()

-type server_ref() :: partisan_peer_service_manager:server_ref().

A message or call destination: a pid or registered name (local or remote), an encoded remote reference, or a {Name, Node}, {global, Name} or {via, Module, Name} tuple. Defined by partisan_peer_service_manager.

time()

-type time() :: non_neg_integer().

Functions

broadcast(Broadcast, Mod)

-spec broadcast(any(), module()) -> ok.

Broadcasts a message originating from this node.

The message is delivered to every node at least once. Mod is responsible for handling the message on remote nodes and for supplying the related information the broadcast substrate needs, both locally and on other nodes. Mod must be loaded on every member of the cluster and implement the partisan_plumtree_broadcast_handler behaviour.

cancel_timer(Ref)

-spec cancel_timer(Ref :: reference()) -> ok | time() | false.

Equivalent to cancel_timer(Ref, []).

cancel_timer(Ref, Opts)

-spec cancel_timer(Ref :: reference(), Opts :: list()) -> ok | time() | false.

Cancels the timer Ref — the Partisan counterpart of erlang:cancel_timer/2.

Opts accepts {async, boolean()} and {info, boolean()} with the same meaning as in erlang:cancel_timer/2. Works for both native timers and the emulated timers send_after/4 creates for remote destinations.

cast_message(ServerRef, Msg)

-spec cast_message(ServerRef :: server_ref(), Msg :: message()) -> ok.

Casts message Msg to the process identified by ServerRef (a server_ref/0), returning ok. Delivery is asynchronous and best-effort.

cast_message(ServerRef, Msg, Opts)

-spec cast_message(ServerRef :: server_ref(), Msg :: message(), Opts :: forward_opts()) -> ok.

Casts message Msg to the process identified by ServerRef, honouring Opts (forward_opts/0). Delivery is asynchronous and best-effort.

cast_message(Node, ServerRef, Msg, Opts)

-spec cast_message(Node :: node(), ServerRef :: server_ref(), Msg :: message(), Opts :: forward_opts()) ->
                      ok.

Casts message Msg to the process ServerRef on Node, honouring Opts (forward_opts/0). Delivery is asynchronous and best-effort.

channel_opts(Channel)

-spec channel_opts(Channel :: channel()) -> channel_opts() | no_return().

Returns the options (channel_opts/0) of the channel named Channel. Fails with badarg if no such channel exists.

default_channel()

-spec default_channel() -> channel().

Returns the name of the default channel.

demonitor(MonitorRef)

-spec demonitor(MonitorRef :: reference() | remote_reference()) -> true.

Removes the monitor identified by MonitorRef; equivalent to demonitor(Ref, []).

Unlike erlang:demonitor/1, it does not fail if MonitorRef refers to a monitor started by another process.

demonitor(MonitorRef, OptionList)

-spec demonitor(MonitorRef :: reference() | remote_reference(), OptionList :: [demonitor_opt()]) ->
                   boolean().

Removes the monitor identified by MonitorRef, with options — Partisan's counterpart of erlang:demonitor/2.

flush removes a pending DOWN for this monitor from the caller's mailbox; info makes the call return whether the monitor was still live when removed.

disconnect_node(Node)

-spec disconnect_node(Node :: node()) -> boolean() | ignored.

Disconnects the local node from Node — the counterpart of erlang:disconnect_node/1.

If Node is the local node, the node leaves the cluster; otherwise it leaves the peer identified by Node. Returns true on success and false if Node is not a known peer.

exit(Pid, Reason)

-spec exit(Pid :: pid() | remote_pid(), Reason :: term()) -> true.

Sends an exit signal with reason Reason to the process identified by Pid (a local pid or a remote_pid/0) — the Partisan counterpart of erlang:exit/2. For a remote reference the signal is delivered on the owning node via partisan_rpc.

forward_message(ServerRef, Msg)

-spec forward_message(ServerRef :: server_ref(), Msg :: message()) ->
                         partisan_peer_service_manager:forward_result().

Forwards message Msg to the process identified by ServerRef (a server_ref/0).

Forwarding is best-effort. It returns {error, Reason} — it does not raise — when the message could not be handed to a connection, most commonly because there is no usable connection to the target node on the requested channel. See partisan_peer_service_manager:forward_result/0 for the reasons Partisan's own managers report.

Check the return value

Before 6.0.0 this function was specced -> ok, which was never true of the implementations. Code written against that spec drops messages silently.

forward_message(ServerRef, Msg, Opts)

-spec forward_message(ServerRef :: server_ref(), Msg :: message(), Opts :: forward_opts()) ->
                         partisan_peer_service_manager:forward_result().

Forwards message Msg to the process identified by ServerRef, honouring Opts (forward_opts/0).

Best-effort; see forward_message/2 on the return value.

forward_message(Node, ServerRef, Msg, Opts)

-spec forward_message(Node :: node(),
                      ServerRef :: server_ref(),
                      Msg :: message(),
                      Opts :: forward_opts()) ->
                         partisan_peer_service_manager:forward_result().

Forwards message Msg to the process ServerRef on Node, honouring Opts (forward_opts/0).

Best-effort; see forward_message/2 on the return value.

is_alive()

-spec is_alive() -> boolean().

Returns true if the local node is alive — that is, the peer service manager is running and the node can take part in a cluster.

is_connected(NodeOrSpec)

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

Returns true if this node currently has a connection to NodeOrSpec.

is_connected(NodeOrSpec, Channel)

-spec is_connected(NodeOrSpec :: node_spec() | node(), Channel :: channel()) -> boolean().

Returns true if this node currently has a connection to NodeOrSpec on Channel.

is_fully_connected(NodeOrSpec)

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

Returns true if every expected connection to NodeOrSpec is established — one per configured channel at its configured parallelism.

is_local(Arg)

-spec is_local(Arg) -> Result
                  when
                      Arg :: pid() | port() | reference() | remote_pid() | remote_reference(),
                      Result :: boolean().

Returns true if Arg belongs to the local node.

Arg may be a pid, port or reference, or one of their remote forms (remote_pid/0, remote_reference/0).

is_local_name(Arg)

-spec is_local_name(Arg :: atom() | remote_name()) -> boolean() | no_return().

Returns true if Arg refers to a name on the local node.

A plain atom is always a local name; a remote_name/0 is checked against the local node.

is_local_name(Arg, Name)

-spec is_local_name(Arg :: atom() | remote_name(), Name :: atom()) -> boolean() | no_return().

Returns true if Arg refers to the locally registered name Name.

is_local_pid(Arg)

-spec is_local_pid(Arg :: pid() | remote_pid()) -> boolean() | no_return().

Returns true if Arg (a pid or remote_pid/0) is a pid on the local node.

is_local_pid(Arg, Pid)

-spec is_local_pid(Arg :: pid() | remote_pid(), Pid :: pid()) -> boolean() | no_return().

Returns true if Arg refers to the local pid Pid.

is_local_reference(Arg)

-spec is_local_reference(Arg :: reference() | remote_reference()) -> boolean() | no_return().

Returns true if Arg (a reference or remote_reference/0) was created on the local node.

is_local_reference(Arg, LocalRef)

-spec is_local_reference(Arg :: reference() | remote_reference(), LocalRef :: reference()) ->
                            boolean() | no_return().

Returns true if Arg refers to the local reference LocalRef.

is_pid/1

-spec is_pid(any()) -> boolean() | no_return().

Returns true if Arg is a local process identifier or a remote_pid/0, false otherwise.

is_process_alive/1

-spec is_process_alive(pid() | remote_pid()) -> boolean() | no_return().

Returns true if the process identified by Arg (a local pid or a remote_pid/0) is alive, false otherwise. For a remote reference the check runs on the owning node via partisan_rpc.

is_reference/1

-spec is_reference(reference() | remote_reference()) -> boolean() | no_return().

Returns true if Arg is a local reference or a remote_reference/0, false otherwise.

is_self(Arg)

-spec is_self(Arg) -> Result when Arg :: pid() | remote_pid(), Result :: boolean().

Returns true if Arg (a pid or remote_pid/0) is the calling process.

join(NodeSpec)

-spec join(node_spec()) -> ok.

Adds a peer to the cluster; a shortcut for partisan_peer_service:join/1.

kill_connections/1

Drops the peer connections to Nodes (a node name or a list of them).

The membership protocol re-establishes them if the nodes are still members, so this forces a reconnect rather than removing a node from the cluster.

leave()

-spec leave() -> ok.

Removes the local node from the cluster; a shortcut for partisan_peer_service:leave/0.

make_ref()

-spec make_ref() -> remote_reference() | no_return().

Returns a fresh remote reference — the Partisan counterpart of erlang:make_ref/0.

Equivalent to partisan_remote_ref:from_term(erlang:make_ref()).

monitor(Term)

Monitors Term as a process; equivalent to monitor(process, Term).

Deprecated: use monitor/2 instead.

monitor(Type, Item)

-spec monitor(process, pid() | atom() | {atom(), node()}) -> reference();
             (process, remote_pid() | remote_name()) -> remote_reference() | no_return();
             (port, port() | atom()) -> reference() | no_return();
             (time_offset, clock_service) -> reference() | no_return().

Sends a monitor request of type Type for the entity identified by Item; equivalent to monitor(Type, Item, []).

If the monitored entity does not exist, or later changes monitored state, the caller receives a {Tag, MonitorRef, Type, Object, Info} message. This is Partisan's counterpart of erlang:monitor/2.

Fails with notalive if the partisan_monitor server is not running.

monitor/3

-spec monitor(process, pid() | atom(), [monitor_opt()]) -> reference();
             (port, port() | atom(), [erlang:monitor_option()]) -> reference();
             (time_offset, clock_service, [erlang:monitor_option()]) -> reference();
             (process, {atom(), node()}, [monitor_opt()]) -> reference() | remote_reference();
             (process, remote_pid(), [monitor_opt()]) -> remote_reference();
             (process, remote_name(), [monitor_opt()]) -> remote_reference().

Sends a monitor request of type Type for the entity identified by Item, with options.

If the monitored entity does not exist, or later changes monitored state, the caller receives a {Tag, MonitorRef, Type, Object, Info} message. This differs from the message erlang:monitor/3 sends only when the monitored item is a remote process, in which case MonitorRef is a remote_reference/0 and Object is a remote_pid/0 or remote_name/0.

This is Partisan's counterpart of erlang:monitor/3 and differs from it only when monitoring a process; for a port or time_offset it calls erlang:monitor/3 directly. Unlike erlang:monitor/3, it does not support aliases.

Monitoring a process

Creates a monitor between the calling process and the process identified by Item — a local or remote pid, a registered-name atom, or a {RegisteredName, Node} tuple for a process registered on another node. A monitor by name resolves the name to a pid once, at creation; later changes to the registration do not affect the existing monitor.

Pass {channel, Channel} in Opts to bind the monitor to a channel: the eventual DOWN is then delivered on that channel, in order with other traffic on it (see the channel-ordering note in the module documentation).

Fails soft: if the partisan_monitor server is not running, the returned reference receives an immediate DOWN with reason notalive.

monitor_node/2

-spec monitor_node(node() | node_spec(), boolean()) -> boolean().

Turns node-status monitoring of Node on (Flag = true) or off (false); equivalent to monitor_node(Node, Flag, []). Node may be a node name or a node_spec/0.

Calling monitor_node(Node, true) repeatedly is not an error: each calling process gets one independent monitor, so a process that called it twice still receives a single {nodedown, Node} if Node goes down — this differs from erlang:monitor_node/2.

{nodedown, Node} is delivered if Node fails, does not exist, or is not connected. Under a membership strategy with a partial view you therefore cannot monitor nodes outside your view. Monitoring the caller's own node returns false.

monitor_node(Node, Flag, Options)

-spec monitor_node(Node :: node(), Flag :: boolean(), Options :: [allow_passive_connect]) -> true.

Turns node-status monitoring of Node on or off, with options.

Behaves as monitor_node/2 — see there for the repeated-call, delivery and partial-view semantics. Options accepts allow_passive_connect, which applies only on the Erlang-distribution path (connect_disterl = true); with the default overlay transport the options are ignored.

monitor_nodes(Flag)

-spec monitor_nodes(Flag :: boolean()) -> ok | error | {error, term()}.

Subscribes (Flag = true) or unsubscribes (false) the calling process to node-status change messages; equivalent to monitor_nodes(Flag, []).

monitor_nodes(Flag, Opts)

-spec monitor_nodes(Flag :: boolean(), [monitor_nodes_opt()]) -> ok | error | {error, term()}.

Subscribes (Flag = true) or unsubscribes (false) the calling process to node-status change messages, with options.

While subscribed, the process receives a {nodeup, Node} message when a peer connects and a {nodedown, Node} message when one disconnects. Opts mirrors the net_kernel node-monitoring options and may also carry a channel selector.

node()

-spec node() -> node().

Returns the name of the local node.

node/1

-spec node(pid() | port() | reference()) -> node();
          (partisan_remote_ref:t()) -> node() | no_return().

Returns the node on which Arg originates.

Arg may be a pid, port or reference, or a Partisan remote reference. For a remote reference the node is read from the reference; for a local pid, port or reference it is erlang:node(Arg), falling back to node/0 when Erlang distribution is disabled.

node_spec()

-spec node_spec() -> node_spec().

Returns the node specification (node_spec/0) of the local node.

This is the information another node needs in order to join this one (see partisan_peer_service:join/1). The values of the map's keys must be sorted so the peer service can compare specifications and keep the membership view free of duplicates — relevant when you build a specification by hand for a custom orchestration strategy. Erlang maps are already sorted, so the only field you must keep sorted yourself is listen_addrs, which is a list.

node_spec(Node)

-spec node_spec(node()) -> {ok, node_spec()} | {error, Reason :: any()}.

Returns {ok, NodeSpec} for the node named Node, or {error, Reason}. Equivalent to node_spec(Node, #{}); see node_spec/2 for how the specification is resolved.

node_spec(Node, Opts)

-spec node_spec(Node :: binary() | list() | node(), Opts :: #{rpc_timeout => timeout()}) ->
                   {ok, node_spec()} | {error, Reason :: any()}.

Returns {ok, NodeSpec} for the node named Node, or {error, Reason}.

If a Partisan connection to Node already exists, the cached specification used to establish that connection is returned. Otherwise — the case under a peer-to-peer topology — the specification is fetched from the remote node with partisan_rpc, which requires the forward_opts configuration to enable broadcast and transitive. Opts may set rpc_timeout (default 5000 ms).

Peer-to-peer topologies

partisan_rpc may not resolve a specification reliably under a peer-to-peer topology.

nodes()

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

Returns the peers connected to this node over Partisan; equivalent to nodes(visible) and the counterpart of erlang:nodes/0.

If connect_disterl is true (as in some test setups) this does not include Erlang-distribution nodes — use erlang:nodes/0 for those.

nodes(Arg)

-spec nodes(Arg :: node_type() | [node_type()]) -> [node()].

Returns nodes of the given type — the counterpart of erlang:nodes/1. When Arg is a list, returns the nodes satisfying any of its elements.

The node types differ from Erlang as follows:

  • hidden — always []; Partisan has no hidden nodes.
  • this — the list containing node/0.
  • known — the nodes known to partisan_peer_service (its partisan_peer_service:members/0), not the nodes of pids, ports and references located on this node.
  • visible — as in Erlang.

nodestring()

-spec nodestring() -> binary().

Returns the name of the local node as a binary string.

process_info(Arg)

-spec process_info(Arg :: pid() | remote_pid()) -> [tuple()] | undefined.

Returns information about the process Arg (a pid or remote_pid/0), or undefined — the counterpart of erlang:process_info/1.

process_info(Arg, Item)

-spec process_info(Arg :: pid() | remote_pid(), Item :: atom() | [atom()]) -> [tuple()] | undefined.

Returns the requested information Item (an item or a list of items) about the process Arg (a pid or remote_pid/0), or undefined — the counterpart of erlang:process_info/2.

remote_ref_to_disterl(Ref)

self()

-spec self() -> remote_pid().

Returns the remote-reference form of the calling process's pid.

Equivalent to partisan_remote_ref:from_term(self()). This is more expensive than erlang:self/0, so you may want to cache the result in your process state — see self/1, which can cache it in the process dictionary (and note the shell caveat described there).

self(Opts)

-spec self(Opts :: [cache]) -> remote_pid().

Returns the remote-reference form of the calling process's pid, optionally caching it.

With Opts = [] this is equivalent to self/0. With Opts = [cache] the result is computed once and stored in the process dictionary, then returned from there on subsequent calls.

Warning

Avoid [cache] in the Erlang shell. When a shell process crashes it copies its dictionary to the replacement shell, so you would carry over a remote reference that no longer matches the running process.

send(Dest, Msg)

-spec send(Dest :: send_dst(), Msg :: message()) -> message().

Sends message Msg to the destination Dest and returns Msg. Equivalent to send(Dest, Msg, []).

Follows erlang:send/2: delivery is best-effort and the message is returned whether or not it could be delivered. An unreachable destination is not an error here — it is not one for erlang:send/2 either, where sending to a dead process or an unreachable node simply returns.

Use send/3 when you need to know: it reports {error, Reason} rather than discarding the outcome.

send(Dest, Msg, Opts)

-spec send(Dest :: send_dst(), Msg :: message(), Opts :: forward_opts()) ->
              ok | nosuspend | noconnect | {error, Reason :: any()}.

Sends message Msg to the destination Dest.

When distributed Erlang is enabled (connect_disterl is true) the message is delivered with erlang:send/3. Otherwise it is forwarded over Partisan with forward_message/3, honouring Opts (forward_opts/0) — and then a failure to reach the target is reported as {error, Reason} rather than raised.

send_after(Time, Destination, Msg)

-spec send_after(Time :: time(), Destination :: send_after_dst(), Msg :: message()) ->
                    TRef :: reference().

Equivalent to send_after(Time, Dest, Msg, []).

send_after(Time, Destination, Message, Opts)

-spec send_after(Time :: time(),
                 Destination :: send_after_dst(),
                 Message :: message(),
                 Opts :: send_after_opts()) ->
                    TRef :: reference().

The Partisan counterpart of erlang:send_after/4.

For a local destination it calls the native implementation. For a remote destination it spawns a process that holds the timer and accepts cancellation (via cancel_timer/1,2); this is less efficient than the native implementation.

spawn(Node, Fun)

-spec spawn(Node :: node(), Fun :: fun(() -> any())) -> remote_pid().

Spawns Fun on Node and returns a remote_pid/0 for the new process — the Partisan counterpart of erlang:spawn/2. A remote spawn is carried out with partisan_rpc.

spawn(Node, Mod, Function, Args)

-spec spawn(Node :: node(), Mod :: module(), Function :: atom(), Args :: [term()]) -> remote_pid().

Spawns Module:Function(Args) on Node and returns a remote_pid/0 for the new process — the Partisan counterpart of erlang:spawn/4. A remote spawn is carried out with partisan_rpc.

spawn_monitor(Node, Fun)

-spec spawn_monitor(Node :: node(), Fun :: fun(() -> any())) ->
                       {remote_pid(), remote_reference()} | {pid(), reference()}.

Spawns Fun on Node and monitors it, returning {Pid, MonitorRef} — the Partisan counterpart of erlang:spawn_monitor/2. See monitor/2 for the shape of the reference and the DOWN message.

spawn_monitor(Node, Mod, Function, Args)

-spec spawn_monitor(Node :: node(), Mod :: module(), Function :: atom(), Args :: [term()]) ->
                       {remote_pid(), remote_reference()} | {pid(), reference()}.

Spawns Module:Function(Args) on Node and monitors it, returning {Pid, MonitorRef} — the Partisan counterpart of erlang:spawn_monitor/4. See monitor/2 for the shape of the reference and the DOWN message.

start()

Starts the partisan application and all of its dependencies.

stop()

Stops the partisan application.

whereis(Arg)

-spec whereis(Arg :: atom() | remote_name()) -> pid() | port() | undefined.

Returns the pid or port registered under Arg, or undefined — the counterpart of erlang:whereis/1.

Arg is a local name (an atom) or a remote_name/0 for the local node. Fails with badarg if Arg is a remote name for another node.