Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoNodes = errors.New("no nodes available in the hash ring")
ErrNoNodes is returned when attempting to get a node from an empty ring
var ErrNodeExists = errors.New("node already exists in the hash ring")
ErrNodeExists is returned when attempting to add a node that already exists
var ErrNodeNotFound = errors.New("node not found in the hash ring")
ErrNodeNotFound is returned when attempting to operate on a node that doesn't exist
Functions ¶
This section is empty.
Types ¶
type HashRing ¶
type HashRing struct {
// contains filtered or unexported fields
}
HashRing implements a consistent hash ring
func NewHashRing ¶
NewHashRing creates a new consistent hash ring
func (*HashRing) GetNodeCount ¶
GetNodeCount returns the number of nodes in the hash ring
func (*HashRing) RemoveNode ¶
RemoveNode removes a node from the hash ring
func (*HashRing) UpdateNodeStatus ¶
func (h *HashRing) UpdateNodeStatus(nodeID string, status NodeStatus) error
UpdateNodeStatus updates a node's status
type Node ¶
type Node struct { // ID is the unique identifier for this node ID string // Address is the network address of the node Address string // Status indicates the current operational status Status NodeStatus // LastHeartbeat is the Unix timestamp of the last heartbeat received LastHeartbeat int64 }
Node represents a physical node in the system
func (*Node) IsAvailable ¶
IsAvailable returns true if the node is available to handle requests
func (*Node) SetStatus ¶
func (n *Node) SetStatus(status NodeStatus)
SetStatus updates the node's status
func (*Node) UpdateHeartbeat ¶
UpdateHeartbeat updates the last heartbeat timestamp
type NodeStatus ¶
type NodeStatus string
Status represents the current state of a node
const ( // StatusActive indicates the node is operational and available NodeStatusActive NodeStatus = "active" // StatusInactive indicates the node is not operational NodeStatusInactive NodeStatus = "inactive" // StatusDraining indicates the node is preparing to be removed NodeStatusDraining NodeStatus = "draining" )
type Ring ¶
type Ring interface { // AddNode adds a new node to the hash ring AddNode(node *Node) error // RemoveNode removes a node from the hash ring RemoveNode(nodeID string) error // GetNode returns the node responsible for the given key GetNode(key string) (*Node, error) // GetNodes returns all nodes in the hash ring GetNodes() []*Node // GetNodeCount returns the number of nodes in the hash ring GetNodeCount() int // UpdateNodeStatus updates a node's status UpdateNodeStatus(nodeID string, status NodeStatus) error }
Ring defines the interface for a consistent hash ring