partisan_remote_ref (partisan v5.0.2)
View SourceRemote references are Partisan's representation for remote process identifiers (pid()
), registered names and references (reference()
).
Distributed Erlang (disterl) will transform the representation of process identifiers, registered names and references when they are sent to a remote node. This is done to disambiguate between remote and local instances. Because Partisan doesn't use disterl it needs to implement this same disambiguation mechanism somehow. As disterl's implementation is done by the BEAM internally and not API is exposed, this module is required to achieve a similar result.
Representation
In cases where lots of references are stored in process state, ets
and specially where those are uses as keys, a binary format is preferable to the tuple format in order to save memory and avoid copying the term every time a message is send between processes (by leveraging off-heap binary storage).
For this reason, this module implements two alternative representations:
- references as binary URIs
- references as tuples
The representation to use is controlled by the configuration option remote_ref_as_uri`. If `true
this module will generate references as binary URIs. Otherwise it will generate them as tuples.r
URI Representation
1> partisan_remote_ref:from_term(self()).
<<"partisan:pid:nonode@nohost:0.1062.0">>
URI Padding
For those cases where the resulting references are smaller than 64 bytes ( and thus will be stored on the process heap) this module can pad the generated binary URIs to 65 bytes, thus forcing them to be stored off-heap. This is controlled with the configuration option remote_ref_binary_padding
.
1> partisan_config:set(remote_ref_binary_padding, false).
2> partisan_remote_ref:from_term(self()).
<<"partisan:pid:nonode@nohost:0.1062.0">>
3> partisan_config:set(remote_ref_binary_padding, true).
ok
4> partisan_remote_ref:from_term(self()).
<<"partisan:pid:nonode@nohost:0.1062.0:"...>>
Tuple Representation
1> partisan_remote_ref:from_term(self()).
{partisan_remote_reference,
nonode@nohost,
{partisan_process_reference,"<0.1062.0>"}}
Issues and TODOs
As opposed to erlang pid encodintg (NEW_PID_EXT`) our current representation cannot distinguished between identifiers from old (crashed) nodes from a new one. So maybe we need to adopt the `NEW_PID_EXT
Creation
attribute.
Summary
Functions
Returns the partisan-encoded representation of a process identifier, reference, local or remote registered name (atom).
Returns the partisan-encoded representation of a registered name Name
at node Node
. The function does not check Name
is an actual registered name,
Checks two refs for identity. Two refs are identical if the are equal or if one is a process reference and the other one is a registered name reference of said process. In the latter case the function uses erlang:whereis/1
which means the check can fail if the process has died (and thus is no longer registered).
Returns true if reference Ref
is located in node Node
.
Calls to_term/1
and returns the result if it is an local name i.e. atom(). Otherwise fails with badarg
Calls to_term/1
and returns the result if it is a local pid(). Otherwise fails with badarg
Calls to_term/1
and returns the result if it is an local name i.e. atom() or local pid(). Otherwise fails with badarg
Calls to_term/1
and returns the result if it is a local reference(). Otherwise fails with badarg
Types
-type encoded_name() :: {encoded_name, list()}.
-type encoded_pid() :: {encoded_pid, list()}.
-type encoded_ref() :: {encoded_ref, list()}.
-type format() :: improper_list | tuple | uri.
-type n() :: [node() | binary()] | tuple_ref(encoded_name()) | uri().
-type p() :: [node() | binary()] | tuple_ref(encoded_pid()) | uri().
-type r() :: [node() | binary()] | tuple_ref(encoded_ref()) | uri().
-type target() :: encoded_pid() | encoded_ref() | encoded_name().
-type tuple_ref(T) :: {partisan_remote_ref, node(), T}.
-type uri() :: <<_:64, _:_*8>>.
Functions
Returns the partisan-encoded representation of a process identifier, reference, local or remote registered name (atom).
In the case of a name, the function does not check Name
is an actual registered name.
Returns the partisan-encoded representation of a registered name Name
at node Node
. The function does not check Name
is an actual registered name,
Checks two refs for identity. Two refs are identical if the are equal or if one is a process reference and the other one is a registered name reference of said process. In the latter case the function uses erlang:whereis/1
which means the check can fail if the process has died (and thus is no longer registered).
Returns true if reference Ref
is located in node Node
.
Calls to_term/1
and returns the result if it is an local name i.e. atom(). Otherwise fails with badarg
Calls to_term/1
and returns the result if it is a local pid(). Otherwise fails with badarg
Calls to_term/1
and returns the result if it is an local name i.e. atom() or local pid(). Otherwise fails with badarg
Calls to_term/1
and returns the result if it is a local reference(). Otherwise fails with badarg