phoenix_pubsub v1.0.2 Phoenix.Tracker.State

Provides an ORSWOT CRDT.

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 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

Types

clock :: pos_integer
clouds :: %{optional(name) => cloud}
context :: %{optional(name) => clock}
delta :: %Phoenix.Tracker.State{clouds: term, context: term, delta: term, mode: :delta, pids: term, range: term, replica: term, replicas: term, values: term}
ets_id :: pos_integer
key :: term
meta :: Map.t
name :: term
pid_lookup :: {pid, topic, key}
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 :: {name, clock}
value :: {{topic, pid, key}, meta, tag}
values ::
  ets_id |
  :extracted |
  %{optional(tag) => {pid, topic, key, meta}}

Functions

clocks(state)

Specs

clocks(t) :: {name, context}

Returns the causal context for the set.

compact(state)

Specs

compact(t) :: t

Compacts a sets causal history.

Called as needed and after merges.

delta_size(state)

Specs

delta_size(delta) :: pos_integer

Returns the dize of the delta.

extract(state, remote_ref, remote_context)

Specs

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

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

Used when merging two sets.

get_by_pid(state, pid)

Specs

get_by_pid(t, pid) :: [value]

Returns all elements for the pid.

get_by_pid(state, pid, topic, key)

Specs

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

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

get_by_topic(state, topic)

Specs

get_by_topic(t, topic) :: [value]

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

has_delta?(state)

Specs

has_delta?(t) :: boolean

Checks if set has a non-empty delta.

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

Specs

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

Adds a new element to the set.

leave(state, pid)

Specs

leave(t, pid) :: t

Removes all elements from the set for the given pid.

leave(state, pid, topic, key)

Specs

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

Removes an element from the set.

merge(local, remote)

Specs

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)

Specs

new(name) :: t

Creates a new set for the replica.

Examples

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

Specs

online_list(t) :: [value]

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

remove_down_replicas(state, replica)

Specs

remove_down_replicas(t, name) :: t

Removes all elements for replicas that are permanently gone.

replica_down(state, replica)

Specs

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

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

replica_up(state, replica)

Specs

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

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

reset_delta(state)

Specs

reset_delta(t) :: t

Resets the set’s delta.