ServiceMembership

class ServiceMembership(val service: String, val node: String, addressOf: () -> String, leases: LeaseStore, options: ClusterOptions = ClusterOptions(), context: CoroutineContext = Dispatchers.Default)

One node's membership in its service on one lease store: a single record, heartbeated every ClusterOptions.heartbeatInterval, listing the lease groups the node takes part in, and a single read of the service's live members every ClusterOptions.reconcileInterval (or ClusterOptions.routeRefreshInterval, the shorter), which every PartitionOwnership of the node reuses for its reconcile and its routes instead of reading its own. The store operations of membership so stay constant in the number of lease groups: a heartbeat and a read per node and interval, where each group used to heartbeat, and read its members twice, on its own.

An ownership joins with its group and leaves it; the record lists the groups joined and not stuck. A change of that list is heartbeated at once, so the other nodes see a group left (a graceful stop, a failed start, a stuck reconcile) as soon as they saw it before, when each group had its own record: HRW still counts, per group, the members that list it. The membership starts with its first group and leaves the service, at once, with its last.

Constructors

Link copied to clipboard
constructor(service: String, node: String, addressOf: () -> String, leases: LeaseStore, options: ClusterOptions = ClusterOptions(), context: CoroutineContext = Dispatchers.Default)

Properties

Link copied to clipboard

The service's live members as last read, each with the groups it serves.

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
suspend fun join(group: String, read: () -> Unit)

Takes part in group: heartbeats the record with it and reads the members at once, then calls read after each read of the members until leave. The first group starts the heartbeats and the reads.

Link copied to clipboard
suspend fun leave(group: String)

Stops taking part in group: heartbeats the record without it at once, or, for the last group, leaves the service and stops the heartbeats and the reads. The group leaves the record's list before the store is called, so no heartbeat lists it again, even one that waits on the store meanwhile; a leave of a group left already, one whose call was cancelled say, still brings the record and the heartbeats in line.

Link copied to clipboard
fun membersOf(group: String): List<Member>

The live members of group as last read: those whose record lists it.

Link copied to clipboard
suspend fun refresh()

Reads the service's members, and calls each group's join callback.

Link copied to clipboard
suspend fun stuck(group: String, stuck: Boolean)

Marks group stuck or not: a node whose reconcile of a group is stuck leaves that group's members, so the others take its partitions, and lists it again once the reconcile ends. Heartbeated at once.