cluster

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterStatus

type ClusterStatus struct {
	IsClustered bool   `json:"is_clustered"`
	NodeID      string `json:"node_id"`
	State       string `json:"state,omitempty"`
	Leader      string `json:"leader,omitempty"`
	Term        uint64 `json:"term,omitempty"`
	PeerCount   int    `json:"peer_count,omitempty"`
}

ClusterStatus contains cluster status information

type DistributionStrategy added in v0.1.0

type DistributionStrategy int

DistributionStrategy determines how souls are assigned to nodes

const (
	// StrategyRoundRobin assigns souls sequentially
	StrategyRoundRobin DistributionStrategy = iota
	// StrategyRegionAware prefers nodes in the same region
	StrategyRegionAware
	// StrategyLoadBased assigns to least loaded nodes
	StrategyLoadBased
	// StrategyHashBased uses consistent hashing
	StrategyHashBased
)

func (DistributionStrategy) String added in v0.1.0

func (s DistributionStrategy) String() string

String returns the string representation of a strategy

type Distributor added in v0.1.0

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

Distributor handles soul assignment across cluster nodes The Scales of Ma'at - weighing and distributing the load

func NewDistributor added in v0.1.0

func NewDistributor(nodeID, region string, strategy DistributionStrategy, logger *slog.Logger) *Distributor

NewDistributor creates a new distributor

func (*Distributor) AssignSoul added in v0.1.0

func (d *Distributor) AssignSoul(soul *core.Soul) (string, error)

AssignSoul assigns a soul to a node

func (*Distributor) GetLoadDistribution added in v0.1.0

func (d *Distributor) GetLoadDistribution() map[string]*NodeLoad

GetLoadDistribution returns current load distribution

func (*Distributor) GetNodeForSoul added in v0.1.0

func (d *Distributor) GetNodeForSoul(soulID string) (string, bool)

GetNodeForSoul returns the node assigned to a soul

func (*Distributor) GetSoulsForNode added in v0.1.0

func (d *Distributor) GetSoulsForNode(nodeID string) []string

GetSoulsForNode returns all souls assigned to a node

func (*Distributor) ReassignSoul added in v0.1.0

func (d *Distributor) ReassignSoul(soulID string) error

ReassignSoul moves a soul to a different node

func (*Distributor) RegisterNode added in v0.1.0

func (d *Distributor) RegisterNode(nodeID, region string)

RegisterNode registers a node in the cluster

func (*Distributor) SetCallbacks added in v0.1.0

func (d *Distributor) SetCallbacks(
	onAssign func(soulID string, nodeID string) error,
	onUnassign func(soulID string) error,
	onRebalance func(moves []SoulMove),
)

SetCallbacks sets the distribution callbacks

func (*Distributor) Start added in v0.1.0

func (d *Distributor) Start()

Start starts the distributor

func (*Distributor) Stop added in v0.1.0

func (d *Distributor) Stop()

Stop stops the distributor

func (*Distributor) UnassignSoul added in v0.1.0

func (d *Distributor) UnassignSoul(soulID string)

UnassignSoul removes a soul assignment

func (*Distributor) UnregisterNode added in v0.1.0

func (d *Distributor) UnregisterNode(nodeID string)

UnregisterNode removes a node and triggers failover

func (*Distributor) UpdateNodeLoad added in v0.1.0

func (d *Distributor) UpdateNodeLoad(nodeID string, cpu, memory float64, soulCount int)

UpdateNodeLoad updates load information for a node

type Manager

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

Manager handles cluster coordination

func NewManager

func NewManager(cfg core.RaftConfig, db *storage.CobaltDB, logger *slog.Logger) (*Manager, error)

NewManager creates a new cluster manager

func (*Manager) GetStatus

func (m *Manager) GetStatus() *ClusterStatus

GetStatus returns cluster status information

func (*Manager) IsClustered

func (m *Manager) IsClustered() bool

IsClustered returns true if cluster mode is enabled

func (*Manager) IsLeader

func (m *Manager) IsLeader() bool

IsLeader returns true if this node is the Raft leader

func (*Manager) Leader

func (m *Manager) Leader() string

Leader returns the current leader's ID

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start initializes and starts the Raft node

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

Stop gracefully shuts down the Raft node

type NodeLoad added in v0.1.0

type NodeLoad struct {
	NodeID        string
	Region        string
	SoulCount     int
	CPUUsage      float64
	MemoryUsage   float64
	LastHeartbeat time.Time
	Healthy       bool
}

NodeLoad tracks load information for a node

type SoulMove added in v0.1.0

type SoulMove struct {
	SoulID   string
	FromNode string
	ToNode   string
	Reason   string
}

SoulMove represents a soul reassignment

Jump to

Keyboard shortcuts

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