cluster

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package cluster manages the node's membership in the Hive cluster, including peer tracking, consistent hashing, data routing, and rebalancing.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("hive: not found")

ErrNotFound is returned when a requested key or field does not exist or has expired.

Functions

This section is empty.

Types

type Cluster

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

Cluster owns the cluster state for this node.

func NewCluster

func NewCluster(cfg Config) (*Cluster, error)

NewCluster creates and starts a cluster Cluster. In clustered mode it binds a TCP server and contacts Seeds to join.

func (*Cluster) Exec

func (m *Cluster) Exec(op transport.Op, key string, args ...[]byte) ([][]byte, error)

Exec is the exported entry point for store files to run a cluster op. It delegates to dispatch, keeping routing logic internal to this package.

func (*Cluster) KeyCount added in v1.1.0

func (m *Cluster) KeyCount() int

KeyCount returns the number of live keys held locally by this node.

func (*Cluster) Peers

func (m *Cluster) Peers() []PeerInfo

Peers returns a snapshot of all known peers.

func (*Cluster) Shutdown

func (m *Cluster) Shutdown() error

Shutdown gracefully stops the node. Safe to call more than once.

func (*Cluster) Used added in v1.1.0

func (m *Cluster) Used() int64

Used returns this node's current estimated local byte usage.

type Config

type Config struct {
	NodeID               string
	BindAddr             string
	BindPort             int
	Seeds                []string
	RoutingTimeout       time.Duration
	ConnPoolSize         int
	ReplicationFactor    int
	MemLimit             uint64
	GossipInterval       time.Duration
	GossipFanout         int
	GossipTimeout        time.Duration
	RebalanceDebounce    time.Duration
	RebalanceBatchSize   int
	ReplicationQueueSize int
	ReplicationBatchSize int
	CleanupInterval      time.Duration
	Clustered            bool
	TLSConfig            *tls.Config
}

Config holds all configuration for the cluster manager.

type NodeStatus

type NodeStatus uint8

NodeStatus represents a peer's liveness state in the cluster.

const (
	NodeAlive NodeStatus = 0
	NodeDead  NodeStatus = 1
)

type OpScope

type OpScope uint8

OpScope describes how a cluster op is routed and replicated.

const (
	ScopeWrite OpScope = iota // route to primary owner, replicate to replicas
	ScopeRead                 // route to primary owner, no replication
	ScopeLocal                // always execute on the receiving node
)

type PeerInfo

type PeerInfo struct {
	NodeID            string
	Addr              string
	Status            NodeStatus
	Incarnation       uint64
	ReplicationFactor int
	MemLimit          uint64
	MemUsed           uint64
}

PeerInfo is the canonical peer representation used both as internal mutable state and as the read-only snapshot returned by Peers().

Jump to

Keyboard shortcuts

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