ring

package
v1.10.13 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashRing

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

HashRing is a token ring that can be used for Consistent Hashing.

Nodes place claims along a TokenRing in a distributed manner (rather than consecutively). This allows for less shuffling during claim changes in the ring. Construction of the ring is deterministic, which allows for multiple processes to have an (eventually) consistent view of the ring.

Users should select a high number of claims for nodes. This is due to the fact that the underlying hash functions aren't 100% uniform. Selecting a larger claim value helps compensate for this fact. As the set of nodes increase, the number of claims per node can decrease (in theory).

func NewHashRing

func NewHashRing() *HashRing

func NewRingFromMap

func NewRingFromMap(nodeClaims map[string]int) *HashRing

func (*HashRing) GetNode

func (r *HashRing) GetNode(key []byte) string

func (*HashRing) SetClaims

func (r *HashRing) SetClaims(node string, target int) error

SetClaims sets the number of claims for the specified node.

It only returns an error if an empty node or negative target is provided.

func (*HashRing) Size

func (r *HashRing) Size() int

Jump to

Keyboard shortcuts

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