View Source partisan_remote_ref (partisan v5.0.0-rc.8)

Remote 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_EXTCreation 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 t() :: p() | r() | n().
-type target() :: encoded_pid() | encoded_ref() | encoded_name().
-type tuple_ref(T) :: {partisan_remote_ref, node(), T}.
-type uri() :: <<_:64, _:_*8>>.

Functions

-spec from_term(pid() | reference() | atom() | {atom(), node()}) -> t() | no_return().

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.
-spec from_term(Term :: pid() | reference() | atom(), Node :: node()) -> t() | no_return().
Returns the partisan-encoded representation of a registered name Name at node Node. The function does not check Name is an actual registered name,
-spec is_identical(A :: t(), B :: t()) -> boolean().
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).
-spec is_local(PRef :: t()) -> boolean() | no_return().
-spec is_local(PRef :: t(), Node :: node()) -> boolean() | no_return().
Returns true if reference Ref is located in node Node.
-spec is_local_name(PRef :: t()) -> boolean() | no_return().
Link to this function

is_local_name(PRef, Name)

View Source
-spec is_local_name(PRef :: t(), Name :: atom()) -> boolean() | no_return().
-spec is_local_pid(PRef :: t()) -> boolean() | no_return().
-spec is_local_pid(PRef :: t(), Pid :: pid()) -> boolean() | no_return().
Link to this function

is_local_reference(PRef)

View Source
-spec is_local_reference(PRef :: t()) -> boolean() | no_return().
Link to this function

is_local_reference(PRef, LocalRef)

View Source
-spec is_local_reference(PRef :: t(), LocalRef :: reference()) -> boolean() | no_return().
-spec is_name(any()) -> boolean().
-spec is_name(Ref :: any(), Name :: atom()) -> boolean().
-spec is_pid(any()) -> boolean().
-spec is_reference(any()) -> boolean().
-spec is_type(any()) -> boolean().
-spec node(PRef :: t()) -> node() | no_return().
-spec nodestring(PRef :: t()) -> binary() | no_return().
-spec target(PRef :: t()) -> target() | no_return().
-spec to_name(Arg :: n()) -> atom() | no_return().
Calls to_term/1 and returns the result if it is an local name i.e. atom(). Otherwise fails with badarg
-spec to_pid(Arg :: p()) -> pid() | no_return().
Calls to_term/1 and returns the result if it is a local pid(). Otherwise fails with badarg
-spec to_pid_or_name(Arg :: p() | n()) -> atom() | pid() | no_return().
Calls to_term/1 and returns the result if it is an local name i.e. atom() or local pid(). Otherwise fails with badarg
-spec to_reference(Arg :: r()) -> reference() | no_return().
Calls to_term/1 and returns the result if it is a local reference(). Otherwise fails with badarg
-spec to_term(t()) -> pid() | reference() | atom() | no_return().