Documentation
¶
Overview ¶
Package cluster contains primitives for node identity, membership tracking and consistent hashing used by distributed backends.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidAddress = errors.New("invalid node address")
ErrInvalidAddress is returned when the node address is invalid.
Functions ¶
This section is empty.
Types ¶
type Membership ¶
type Membership struct {
// contains filtered or unexported fields
}
Membership tracks current cluster nodes (static MVP, future: gossip/swim).
func NewMembership ¶
func NewMembership(ring *Ring) *Membership
NewMembership creates a new membership container bound to a ring.
func (*Membership) Mark ¶
func (m *Membership) Mark(id NodeID, state NodeState) bool
Mark updates node state + incarnation and refreshes LastSeen. Returns true if node exists.
func (*Membership) Remove ¶
func (m *Membership) Remove(id NodeID) bool
Remove deletes a node from membership and rebuilds the ring. Returns true if removed.
func (*Membership) Ring ¶
func (m *Membership) Ring() *Ring
Ring returns the underlying ring reference.
func (*Membership) Upsert ¶
func (m *Membership) Upsert(n *Node)
Upsert adds or updates a node and rebuilds ring.
func (*Membership) Version ¶ added in v0.2.1
func (m *Membership) Version() uint64
Version returns current membership version.
type MembershipVersion ¶ added in v0.2.1
type MembershipVersion struct {
// contains filtered or unexported fields
}
MembershipVersion tracks a monotonically increasing version for membership changes. Used to expose a cheap cluster epoch for clients/metrics.
func (*MembershipVersion) Get ¶ added in v0.2.1
func (mv *MembershipVersion) Get() uint64
Get returns current version.
func (*MembershipVersion) Next ¶ added in v0.2.1
func (mv *MembershipVersion) Next() uint64
Next increments and returns the next version.
type Node ¶
type Node struct { ID NodeID Address string // host:port for intra-cluster RPC State NodeState Incarnation uint64 LastSeen time.Time }
Node holds identity & state.
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring implements a consistent hashing ring with virtual nodes.
func NewRing ¶
func NewRing(opts ...RingOption) *Ring
NewRing creates a ring with defaults overridden by options. NewRing constructs a new Ring applying provided options.
func (*Ring) Build ¶
Build rebuilds ring from nodes set (copy-on-write). Build rebuilds the ring using the supplied node list.
func (*Ring) Lookup ¶
Lookup returns primary + (replication-1) replicas. Lookup returns the primary owner and (replication-1) replicas for a key.
func (*Ring) VNodeHashes ¶
VNodeHashes returns a copy of vnode hash values as hex strings (debug only).
func (*Ring) VirtualNodesPerNode ¶
VirtualNodesPerNode returns configured virtual nodes per physical node.
type RingOption ¶
type RingOption func(*Ring)
RingOption configures ring.
func WithReplication ¶
func WithReplication(n int) RingOption
WithReplication sets the replication factor (number of owners per key).
func WithVirtualNodes ¶
func WithVirtualNodes(n int) RingOption
WithVirtualNodes sets the number of virtual nodes per physical node.