balancer

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConsistentHash           = "consistent_hash"
	DefaultConsistentHashKey = "consistent-hash"
)
View Source
const (
	DefaultReplicas = 10
	Salt            = "n*@if09g3n"
)
View Source
const LeastConnection = "least_connection"
View Source
const Random = "random"
View Source
const RoundRobin = "round_robin"
View Source
const (
	WeightKey = "weight"
)

Variables

View Source
var (
	// ErrNoSubConnAvailable indicates no SubConn is available for pick().
	ErrNoSubConnAvailable = errors.New("no SubConn is available")
	ErrNoContextAvailable = errors.New("no context is available")
)

Functions

func DefaultHash

func DefaultHash(data []byte) uint32

func GetWeight

func GetWeight(addr Address) int

func Register

func Register(b PickerBuilder)

Types

type Address

type Address struct {
	Name string
	Addr string
	// Attributes contains arbitrary data about this address intended for
	// consumption by the SubConn.
	Attributes *attributes.Attributes
}

type DoneInfo

type DoneInfo struct {
	// Err is the rpc error the RPC finished with. It could be nil.
	Err error
}

type HashFunc

type HashFunc func(data []byte) uint32

type Ketama

type Ketama struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewKetama

func NewKetama(replicas int, fn HashFunc) *Ketama

func (*Ketama) Add

func (h *Ketama) Add(nodes ...string)

func (*Ketama) Get

func (h *Ketama) Get(key string) (string, bool)

func (*Ketama) IsEmpty

func (h *Ketama) IsEmpty() bool

func (*Ketama) Remove

func (h *Ketama) Remove(nodes ...string)

type PickInfo

type PickInfo struct {
	Name string
	Ctx  context.Context
}

type PickResult

type PickResult struct {
	Node any
	Done func(DoneInfo)
}

type Picker

type Picker interface {
	Pick(info PickInfo) (PickResult, error)
}

func NewErrPicker

func NewErrPicker(err error) Picker

NewErrPicker returns a Picker that always returns err on Pick().

type PickerBuildInfo

type PickerBuildInfo struct {
	ReadySCs map[any]SubConnInfo
}

type PickerBuilder

type PickerBuilder interface {
	// Build returns a picker that will be used by client to pick a SubConn.metadata.go
	Build(info PickerBuildInfo) Picker
	Name() string
}

PickerBuilder creates Picker.

func Builder

func Builder(name string) PickerBuilder

type SubConnInfo

type SubConnInfo struct {
	Address Address
}

Jump to

Keyboard shortcuts

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