4.6 Module classy_membership

Cluster Membership CRDT.

This module provides a low-level API for maintaining and updating cluster membership information. Business code should not use it directly.

4.6.1 Types

pv_last()
-type pv_last() :: #pv_last{op :: op(), toi :: clock()}.
pk_last()
-type pk_last() :: #pk_last{c :: classy:cluster_id(),
                            l :: classy:site(), k :: key()}.
sync_data()
-type sync_data() :: #cast_sync{}.
ord()
-type ord() :: {clock(), magic(), classy:site()}.

Projection of ‘op()‘ fields used to establish total order of logs.

op()
-type op() :: #op_set{origin :: classy:site(),
                      k :: key(), c :: clock(), m :: magic(), val :: term(),
                      owt :: integer(), reserved :: term()}.
magic()
-type magic() :: term().

Not exported

Arbitrary term used to break ties between commands with the same logical timestamp.

key()
-type key() :: #mem{} | #host{}.

Not exported

clock()
-type clock() :: non_neg_integer().
start_args()
-type start_args() :: #{cluster := classy:cluster_id(),
                        site := classy:site()}.

4.6.2 Functions

get_data(Cluster, Local, Since, Acked)
-spec get_data(classy:cluster_id(), classy:site(),
               clock(), clock()) -> {ok, sync_data()} | {error, _}.

Get membership data

call_sync(Cluster, Site, SyncData)
-spec call_sync(classy:cluster_id(), classy:site(),
                sync_data()) -> ok.
cast_sync(Cluster, Site, SyncData)
-spec cast_sync(classy:cluster_id(), classy:site(),
                sync_data()) -> ok.
dump()
-spec dump() -> #{{classy:cluster_id(), classy:site()}
                      => map()}.

Format full state of the membership CRDT in human-readable form for tests and debugging.

flush(Cluster, Local)
-spec flush(classy:cluster_id(), classy:site()) -> ok.

Force sending of events and execution of hooks.

cleanup(Cluster, Local, ForgetAfter)
-spec cleanup(classy:cluster_id(), classy:site(),
              pos_integer()) -> ok.

Delete sites that have been kicked for longer than ForgetAfter seconds ago from the local state.

node_of_site(Cluster, Local)
-spec node_of_site(classy:cluster_id(),
                   classy:site()) -> #{classy:site() => node()}.

Return mapping of sites to nodes.

WARNING: it includes kicked members.

site_of_node(Cluster, Local)
-spec site_of_node(classy:cluster_id(),
                   classy:site()) -> #{node() => classy:site()}.

Return mapping of nodes to sites.

WARNING: it includes kicked members.

list_local_sites/1
-spec list_local_sites(running |
                       all) -> [{classy:cluster_id(), classy:site()}].

List local sites and clusters.

members(Cluster, Local)
-spec members(classy:cluster_id(),
              classy:site()) -> [classy:site()].

Return active members of the Cluster, as perceived by Local site.

WARNING: if Local is not a member of the returned list, then the local system may be permanently out of sync with the Cluster or {Cluster,Local} server may be inactive. In both cases the result value can’t be trusted.

set_member(Cluster, Local, Target, IsMember)
-spec set_member(classy:cluster_id(), classy:site(),
                 classy:site(), boolean()) -> ok | {error, _}.

Low-level call that sets Target’s membership state to true.

WARNING: this function does not check if target site exists and/or is part of cluster. When called with invalid Target, it will create a new entry that will eventually make its way to the entire cluster. This fictitious site will become a member until kicked, and even then some records about it may be kept around.

known_clusters(Site)
-spec
     known_clusters(classy:site()) -> #{classy:cluster_id()
                                            => [classy:site()]}.

Return collection of clusters where site is or was peer.


JavaScript license information