partisan_membership (partisan v6.0.0)

View Source

Lock-free snapshot of the cluster's membership, with a non-blocking change-notification feed.

The peer service manager (the membership oracle) writes the current member set here on every change, and readers — broadcast groups and application code — consume it with lock-free ETS reads. This replaces fanning membership updates out over partisan_peer_service_events (a gen_event bus), whose synchronous sync_notify blocked the oracle and did not scale to many readers.

The backing table is a public, read_concurrency set created and owned by partisan_sup, so it survives manager restarts.

Writers observe a simple ordering discipline: the member set is written before the version is bumped, so a reader that sees a new version/0 is guaranteed to read the corresponding — or newer — members. A cheap reader polls version/0 and re-reads members/0 only when it changes.

Observing membership

set/1 and notify/1 are the writer side, called by the peer service managers; application code does not call them.

Summary

Functions

Returns the current member set as node specs, with a lock-free read.

Returns the current member node names as an ordset, with a lock-free read.

Delivers an asynchronous {partisan_membership, Members} message to every subscribed process.

Publishes the current member set and bumps the version.

Subscribes the calling process to membership-change notifications.

Subscribes Pid to membership-change notifications.

Removes the calling process's membership-change subscription.

Removes Pid's membership-change subscription.

Returns the current membership version.

Functions

members()

-spec members() -> [partisan:node_spec()].

Returns the current member set as node specs, with a lock-free read.

node_names()

-spec node_names() -> ordsets:ordset(node()).

Returns the current member node names as an ordset, with a lock-free read.

notify(Members)

-spec notify([partisan:node_spec()]) -> ok.

Delivers an asynchronous {partisan_membership, Members} message to every subscribed process.

Called by the peer service managers after set/1 on a membership change. It is fire-and-forget: it never blocks the caller (the oracle), and each subscriber handles the change in its own process. Subscribers are local pids, so a dead one is pruned here as it is found. Not for application code.

set(Members)

-spec set([partisan:node_spec()]) -> ok.

Publishes the current member set and bumps the version.

Called by the peer service manager whenever membership changes. The member set is written before the version, so a reader that observes the new version/0 reads members at least as new. Not for application code.

subscribe()

-spec subscribe() -> ok.

Subscribes the calling process to membership-change notifications.

The subscriber receives a {partisan_membership, Members} message on every change, where Members is the new member set as node specs.

subscribe(Pid)

-spec subscribe(pid()) -> ok.

Subscribes Pid to membership-change notifications.

unsubscribe()

-spec unsubscribe() -> ok.

Removes the calling process's membership-change subscription.

unsubscribe(Pid)

-spec unsubscribe(pid()) -> ok.

Removes Pid's membership-change subscription.

version()

-spec version() -> non_neg_integer().

Returns the current membership version.

The version increases monotonically; a change is the signal for a polling reader to re-read members/0. Lock-free read.