hashring

package
v0.0.0-...-644c959 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package balancer implements a gRPC Balancer backed by a consistent hashring for connection selection.

As new connections are established new virtual nodes (members) are added to the hashring. When a connection is not in a Ready state we remove the member from the hashring.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooFewMembers = errors.New("too few members in the hashring")
)

Functions

func NewConsistentHashring

func NewConsistentHashring(
	hasher Hasher,
	cfg ConsistentHashringConfig,
	members ...Member,
) *consistentHashring

NewConsistentHashring constructs a Hashring providing consistent hashing configured with the configurations provided.

If one or more members are provided these members are immediately added to the hashring.

Types

type ConsistentHashringConfig

type ConsistentHashringConfig struct {

	//  ReplicationFactor controls the distribution of virtual members on the hashring.
	//
	// A ReplicationFactor greater than 1 means that each member added to the hashring
	// will be added in multiple positions on the hashring.
	ReplicationFactor int
}

func DefaultConsistentHashringConfig

func DefaultConsistentHashringConfig() ConsistentHashringConfig

type Hasher

type Hasher func(b []byte) uint64

type Hashring

type Hashring interface {

	// AddMember adds the provided member to the hashring.
	AddMember(Member)

	// RemoveMember removes the provided member from the hashring.
	RemoveMember(Member)

	// FindNearestN finds the nearest n members on the hashring for the
	// provided key. If there are an insufficient number of members in the
	// hashring an ErrTooFewMembers error is returned.
	FindNearestN(key []byte, n int) ([]Member, error)
}

Hashring defines an interface for managing virtual members of a consistent hashring circle.

type Member

type Member interface {
	String() string
}

Member represents a virtual node or member of a hashring. The String implementation provides the key value for the virtual member.

type StringMember

type StringMember string

func (StringMember) String

func (s StringMember) String() string

type UInt64Item

type UInt64Item uint64

func (UInt64Item) Less

func (a UInt64Item) Less(b btree.Item) bool

Jump to

Keyboard shortcuts

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