phoenix_pubsub v2.0.0 Phoenix.Tracker.State View Source

Provides an ORSWOT CRDT.

Link to this section Summary

Functions

Returns the causal context for the set.

Compacts a sets causal history.

Returns the dize of the delta.

Extracts the set's elements from ets into a mergeable list.

Returns a list of elements for the topic who belong to an online replica.

Returns all elements for the pid.

Returns the element matching the pid, topic, and key.

Returns a list of elements for the topic who belong to an online replica.

Checks if set has a non-empty delta.

Adds a new element to the set.

Removes all elements from the set for the given pid.

Removes an element from the set.

Merges two sets, or a delta into a set.

Creates a new set for the replica.

Returns a list of elements in the set belonging to an online replica.

Removes all elements for replicas that are permanently gone.

Marks a replica as down in the set and returns left users.

Marks a replica as up in the set and returns rejoined users.

Resets the set's delta.

Performs table lookup for tracked key in the topic.

Performs table lookup for tracked elements in the topic.

Link to this section Types

Link to this type

clouds()

View Source
clouds() :: %{required(name()) => cloud()}
Link to this type

context()

View Source
context() :: %{required(name()) => clock()}
Link to this type

delta()

View Source
delta() :: %Phoenix.Tracker.State{
  clouds: term(),
  context: term(),
  delta: term(),
  mode: :delta,
  pids: term(),
  range: term(),
  replica: term(),
  replicas: term(),
  values: term()
}
Link to this type

key_meta()

View Source
key_meta() :: {key(), meta()}
Link to this type

pid_lookup()

View Source
pid_lookup() :: {pid(), topic(), key()}
Link to this type

t()

View Source
t() :: %Phoenix.Tracker.State{
  clouds: clouds(),
  context: context(),
  delta: :unset | delta(),
  mode: :unset | :delta | :normal,
  pids: ets_id(),
  range: {context(), context()},
  replica: name(),
  replicas: %{required(name()) => :up | :down},
  values: values()
}
Link to this type

value()

View Source
value() :: {{topic(), pid(), key()}, meta(), tag()}
Link to this type

values()

View Source
values() ::
  ets_id()
  | :extracted
  | %{required(tag()) => {pid(), topic(), key(), meta()}}

Link to this section Functions

Link to this function

clocks(state)

View Source
clocks(t()) :: {name(), context()}

Returns the causal context for the set.

Link to this function

compact(state)

View Source
compact(t()) :: t()

Compacts a sets causal history.

Called as needed and after merges.

Link to this function

delta_size(state)

View Source
delta_size(delta()) :: pos_integer()

Returns the dize of the delta.

Link to this function

extract(state, remote_ref, remote_context)

View Source
extract(t(), remote_ref :: name(), context()) :: t() | {t(), values()}

Extracts the set's elements from ets into a mergeable list.

Used when merging two sets.

Link to this function

get_by_key(state, topic, key)

View Source
get_by_key(t(), topic(), key()) :: [key_meta()]

Returns a list of elements for the topic who belong to an online replica.

Link to this function

get_by_pid(state, pid)

View Source
get_by_pid(t(), pid()) :: [value()]

Returns all elements for the pid.

Link to this function

get_by_pid(state, pid, topic, key)

View Source
get_by_pid(t(), pid(), topic(), key()) :: value() | nil

Returns the element matching the pid, topic, and key.

Link to this function

get_by_topic(state, topic)

View Source
get_by_topic(t(), topic()) :: [key_meta()]

Returns a list of elements for the topic who belong to an online replica.

Link to this function

has_delta?(state)

View Source
has_delta?(t()) :: boolean()

Checks if set has a non-empty delta.

Link to this function

join(state, pid, topic, key, meta \\ %{})

View Source
join(t(), pid(), topic(), key(), meta()) :: t()

Adds a new element to the set.

Link to this function

leave(state, pid)

View Source
leave(t(), pid()) :: t()

Removes all elements from the set for the given pid.

Link to this function

leave(state, pid, topic, key)

View Source
leave(t(), pid(), topic(), key()) :: t()

Removes an element from the set.

Link to this function

merge(local, remote)

View Source
merge(local :: t(), {remote :: t(), values()} | delta()) ::
  {new_local :: t(), joins :: [value()], leaves :: [value()]}

Merges two sets, or a delta into a set.

Returns a 3-tuple of the updated set, and the joined and left elements.

Examples

iex> {s1, joined, left} =
     Phoenix.Tracker.State.merge(s1, Phoenix.Tracker.State.extract(s2))

{%Phoenix.Tracker.State{}, [...], [...]}
Link to this function

merge_deltas(local, remote)

View Source
Link to this function

new(replica, shard_name)

View Source
new(name(), atom()) :: t()

Creates a new set for the replica.

Examples

iex> Phoenix.Tracker.State.new(:replica1)
%Phoenix.Tracker.State{...}
Link to this function

online_list(state)

View Source
online_list(t()) :: [value()]

Returns a list of elements in the set belonging to an online replica.

Link to this function

remove_down_replicas(state, replica)

View Source
remove_down_replicas(t(), name()) :: t()

Removes all elements for replicas that are permanently gone.

Link to this function

replica_down(state, replica)

View Source
replica_down(t(), name()) :: {t(), joins :: [], leaves :: [values()]}

Marks a replica as down in the set and returns left users.

Link to this function

replica_up(state, replica)

View Source
replica_up(t(), name()) :: {t(), joins :: [values()], leaves :: []}

Marks a replica as up in the set and returns rejoined users.

Link to this function

reset_delta(state)

View Source
reset_delta(t()) :: t()

Resets the set's delta.

Link to this function

tracked_key(table, topic, key, down_replicas)

View Source

Performs table lookup for tracked key in the topic.

Filters out those present on downed replicas.

Link to this function

tracked_values(table, topic, down_replicas)

View Source

Performs table lookup for tracked elements in the topic.

Filters out those present on downed replicas.