consistent

package
v1.22.0-rc8 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMemberAlreadyExists = errors.New("member node already exists")
	ErrMemberNotFound      = errors.New("member node not found")
	ErrNotEnoughMembers    = errors.New("not enough member nodes to satisfy request")
)

Functions

This section is empty.

Types

type HasherFunc

type HasherFunc func([]byte) uint64

HasherFunc is the interface for any function that can act as a hasher.

type Hashring

type Hashring struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Hashring provides a ring consistent hash implementation using a configurable number of virtual nodes. It is internally synchronized and thread-safe.

func MustNewHashring added in v1.16.0

func MustNewHashring(hasher HasherFunc, replicationFactor uint16) *Hashring

MustNewHashring creates a new Hashring with the specified hasher function and replicationFactor.

replicationFactor must be >= 1 or this method will panic.

func NewHashring

func NewHashring(hasher HasherFunc, replicationFactor uint16) (*Hashring, error)

NewHashring creates a new Hashring with the specified hasher function and replicationFactor.

replicationFactor must be > 0 and should be a number like 20 for higher quality key distribution. At a replicationFactor of 100, the standard distribution of key->member mapping will be about 10% of the mean. At a replicationFactor of 1000 it will be about 3.2%. The replicationFactor should be chosen carefully because a higher replicationFactor will require more memory and worse member selection performance.

func (*Hashring) Add

func (h *Hashring) Add(member Member) error

Add adds an object that implements the Member interface as a node in the consistent hashring.

If a member with the same key is already in the hashring, ErrMemberAlreadyExists is returned.

func (*Hashring) FindN

func (h *Hashring) FindN(key []byte, num uint8) ([]Member, error)

FindN finds the first N members in the hashring after the specified key.

If there are not enough members in the hashring to satisfy the request, ErrNotEnoughMembers is returned.

func (*Hashring) Members

func (h *Hashring) Members() []Member

Members returns the current list of members of the Hashring.

func (*Hashring) Remove

func (h *Hashring) Remove(member Member) error

Remove removes an object with the same key as the specified member object.

If no member with the same key is in the hashring, ErrMemberNotFound is returned.

type Member

type Member interface {
	Key() string
}

Member is the interface for any object that can be stored and retrieved as a Hashring member (e.g. node/backend).

Jump to

Keyboard shortcuts

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