W3cubDocs

/Phoenix

Phoenix.Tracker.State

Provides an ORSWOT CRDT.

Summary

Types

clock()
cloud()
clouds()
context()
delta()
ets_id()
key()
key_meta()
meta()
name()
pid_lookup()
t()
tag()
topic()
value()
values()

Functions

clocks(state)

Returns the causal context for the set

compact(state)

Compacts a sets causal history

delta_size(state)

Returns the dize of the delta

extract(state, remote_ref, remote_context)

Extracts the set’s elements from ets into a mergeable list

get_by_key(state, topic, key)

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

get_by_pid(state, pid)

Returns all elements for the pid

get_by_pid(state, pid, topic, key)

Returns the element matching the pid, topic, and key

get_by_topic(state, topic)

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

has_delta?(state)

Checks if set has a non-empty delta

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

Adds a new element to the set

leave(state, pid)

Removes all elements from the set for the given pid

leave(state, pid, topic, key)

Removes an element from the set

merge(local, remote)

Merges two sets, or a delta into a set

merge_deltas(local, remote)
new(replica, shard_name)

Creates a new set for the replica

online_list(state)

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

remove_down_replicas(state, replica)

Removes all elements for replicas that are permanently gone

replica_down(state, replica)

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

replica_up(state, replica)

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

reset_delta(state)

Resets the set’s delta

tracked_key(table, topic, key, down_replicas)

Performs table lookup for tracked key in the topic

tracked_values(table, topic, down_replicas)

Performs table lookup for tracked elements in the topic

Types

clock()

clock() :: pos_integer()

cloud()

cloud() :: MapSet.t()

clouds()

clouds() :: %{optional(name()) => cloud()}

context()

context() :: %{optional(name()) => clock()}

delta()

delta() :: %Phoenix.Tracker.State{
  clouds: term(),
  context: term(),
  delta: term(),
  mode: :delta,
  pids: term(),
  range: term(),
  replica: term(),
  replicas: term(),
  values: term()
}

ets_id()

ets_id() :: :ets.tid()

key()

key() :: term()

key_meta()

key_meta() :: {key(), meta()}

meta()

meta() :: map()

name()

name() :: term()

pid_lookup()

pid_lookup() :: {pid(), topic(), key()}

t()

t() :: %Phoenix.Tracker.State{
  clouds: clouds(),
  context: context(),
  delta: :unset | delta(),
  mode: :unset | :delta | :normal,
  pids: ets_id(),
  range: {context(), context()},
  replica: name(),
  replicas: %{optional(name()) => :up | :down},
  values: values()
}

tag()

tag() :: {name(), clock()}

topic()

topic() :: String.t()

value()

value() :: {{topic(), pid(), key()}, meta(), tag()}

values()

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

Functions

clocks(state)

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

Returns the causal context for the set.

compact(state)

compact(t()) :: t()

Compacts a sets causal history.

Called as needed and after merges.

delta_size(state)

delta_size(delta()) :: pos_integer()

Returns the dize of the delta.

extract(state, remote_ref, remote_context)

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.

get_by_key(state, topic, key)

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

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

get_by_pid(state, pid)

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

Returns all elements for the pid.

get_by_pid(state, pid, topic, key)

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

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

get_by_topic(state, topic)

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

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

has_delta?(state)

has_delta?(t()) :: boolean()

Checks if set has a non-empty delta.

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

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

Adds a new element to the set.

leave(state, pid)

leave(t(), pid()) :: t()

Removes all elements from the set for the given pid.

leave(state, pid, topic, key)

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

Removes an element from the set.

merge(local, remote)

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{}, [...], [...]}

merge_deltas(local, remote)

new(replica, shard_name)

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

Creates a new set for the replica.

Examples

iex> Phoenix.Tracker.State.new(:replica1)
%Phoenix.Tracker.State{...}

online_list(state)

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

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

remove_down_replicas(state, replica)

remove_down_replicas(t(), name()) :: t()

Removes all elements for replicas that are permanently gone.

replica_down(state, replica)

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

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

replica_up(state, replica)

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

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

reset_delta(state)

reset_delta(t()) :: t()

Resets the set’s delta.

tracked_key(table, topic, key, down_replicas)

Performs table lookup for tracked key in the topic.

Filters out those present on downed replicas.

tracked_values(table, topic, down_replicas)

Performs table lookup for tracked elements in the topic.

Filters out those present on downed replicas.

© 2014 Chris McCord
Licensed under the MIT License.
https://hexdocs.pm/phoenix_pubsub/Phoenix.Tracker.State.html