cluster

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Membership

type Membership struct {
	// contains filtered or unexported fields
}

Membership is the set of live nodes in the cluster, as the local Node sees it at one moment.

A nil Membership has no live nodes, so the local node is responsible for no workloads.

func (*Membership) LocalNodeIsResponsibleFor

func (m *Membership) LocalNodeIsResponsibleFor(workload *uuidpb.UUID) bool

LocalNodeIsResponsibleFor returns true if the local node is responsible for the given rendezvous workload.

Each live node is scored by hashing the workload with the node's ID, and the node with the highest score is responsible. Ties are broken by the lower ID, so every node with the same membership reaches the same answer, regardless of the order in which it holds the live nodes.

The local node is responsible for nothing while it can not hear its own heartbeats.

func (*Membership) Peers

func (m *Membership) Peers() *uuidcollection.Set

Peers returns the IDs of the live nodes other than the local node.

The returned set must not be modified.

type Node

type Node struct {
	// ID is the ID of this node.
	ID *uuidpb.UUID

	// Signals is the bus used to send and receive heartbeat signals.
	Signals *signal.Bus

	// Interval is the time between the heartbeats sent by each node.
	Interval time.Duration

	// Timeout is the amount of time a node can go without sending a heartbeat
	// before it is considered offline.
	Timeout time.Duration

	// Logger is the target for log messages produced by the node.
	Logger *slog.Logger
	// contains filtered or unexported fields
}

Node represents this engine's node in the cluster. It sends heartbeat signals on behalf of this node, and receives them from every node in the cluster to build a view of the live nodes in the cluster.

Heartbeat delivery is lossy. A node is only removed from the view after the heartbeat timeout, which spans several heartbeats, so dropped heartbeats are tolerated.

func (*Node) Membership

func (n *Node) Membership() cosyne.ObservableR[*Membership]

Membership returns an observable of this node's view of the live nodes in the cluster.

The membership is nil until this node first hears a heartbeat, and has no live nodes once this node has stopped.

func (*Node) Run

func (n *Node) Run(ctx context.Context) error

Run sends and receives heartbeats, and publishes the membership as it changes, until ctx is canceled.

It must be called at most once.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL