Documentation
¶
Index ¶
- type NodeLoad
- type Ring
- func (r *Ring) AddNode(nodeID string) bool
- func (r *Ring) DecrementLoad(nodeID string)
- func (r *Ring) GetLoad(nodeID string) int64
- func (r *Ring) GetNode(key string) (string, bool)
- func (r *Ring) GetNodes(key string, n int) []string
- func (r *Ring) HasNode(nodeID string) bool
- func (r *Ring) IncrementLoad(nodeID string)
- func (r *Ring) IsEmpty() bool
- func (r *Ring) Members() []string
- func (r *Ring) RemoveNode(nodeID string) bool
- func (r *Ring) SetOnNodeAdded(fn func(nodeID string))
- func (r *Ring) SetOnNodeRemoved(fn func(nodeID string))
- func (r *Ring) Size() int
- type VNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring implements consistent hashing with bounded loads. It distributes keys across nodes using virtual nodes on a hash ring, and enforces a maximum load factor to prevent any single node from being overloaded (Google's "Consistent Hashing with Bounded Loads").
func NewRing ¶
NewRing creates a new consistent hash ring. vnodeCount is the number of virtual nodes per physical node. maxLoadFactor is ε for bounded loads (e.g., 0.25 means max 125% of avg).
func (*Ring) AddNode ¶
AddNode adds a physical node to the ring with its virtual nodes. Returns false if the node already exists.
func (*Ring) DecrementLoad ¶
DecrementLoad atomically decrements the load for a node. Call this when a request finishes being processed by the node.
func (*Ring) GetNode ¶
GetNode returns the node responsible for the given key. It implements bounded loads: if the target node is overloaded, it moves clockwise to the next eligible node.
func (*Ring) GetNodes ¶
GetNodes returns up to n distinct nodes responsible for the given key, walking clockwise from the key's position on the ring. Used for replication: first node = primary, rest = secondaries.
func (*Ring) IncrementLoad ¶
IncrementLoad atomically increments the load for a node. Call this when a request starts being processed by the node.
func (*Ring) RemoveNode ¶
RemoveNode removes a physical node and all its virtual nodes from the ring. Returns false if the node doesn't exist.
func (*Ring) SetOnNodeAdded ¶
SetOnNodeAdded sets a callback invoked when a node is added to the ring.
func (*Ring) SetOnNodeRemoved ¶
SetOnNodeRemoved sets a callback invoked when a node is removed from the ring.