jumphash

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Selector

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

Selector implements the memcache.ServerSelector interface. Selector utilizes a jump hash to distribute keys to servers.

While adding or removing servers only requires 1/N keys to move, servers are treated as a stack and can only be pushed/popped. Therefore, Selector works best for servers with consistent DNS names where the naturally sorted order is predictable.

func DefaultSelector

func DefaultSelector() *Selector

func NewSelector

func NewSelector(resolveUnixAddr UnixResolver, resolveTCPAddr TCPResolver) *Selector

func (*Selector) Addrs

func (s *Selector) Addrs() []net.Addr

func (*Selector) Each

func (s *Selector) Each(f func(net.Addr) error) error

Each iterates over each server and calls the given function. If f returns a non-nil error, iteration will stop and that error will be returned.

func (*Selector) FromString

func (s *Selector) FromString(key string) (net.Addr, error)

func (*Selector) FromUInt64

func (s *Selector) FromUInt64(key uint64) (net.Addr, error)

func (*Selector) PickServer

func (s *Selector) PickServer(key string) (net.Addr, error)

PickServer returns the server address that a given item should be shared onto.

func (*Selector) SetServers

func (s *Selector) SetServers(servers ...string) error

SetServers changes a MemcachedJumpHashSelector's set of servers at runtime and is safe for concurrent use by multiple goroutines.

Each server is given equal weight. A server is given more weight if it's listed multiple times.

SetServers returns an error if any of the server names fail to resolve. No attempt is made to connect to the server. If any error occurs, no changes are made to the internal server list.

To minimize the number of rehashes for keys when scaling the number of servers in subsequent calls to SetServers, servers are stored in natural sort order.

type TCPResolver

type TCPResolver func(network, address string) (*net.TCPAddr, error)

type UnixResolver

type UnixResolver func(network, address string) (*net.UnixAddr, error)

Jump to

Keyboard shortcuts

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