core

package
v0.0.0-...-61db174 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHostAlreadyExists = errors.New("host already exists")
	ErrHostNotFound      = errors.New("host not found")
)

Functions

This section is empty.

Types

type ConsistentHash

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

ConsistentHash is an implementation of consistent-hashing-algorithm

func NewConsistent

func NewConsistent(replicaNum int, hashFunc func(key string) uint64) *ConsistentHash

NewConsistent creates a consistent-hashing-algorithm

func (*ConsistentHash) DecLoad

func (ch *ConsistentHash) DecLoad(address string)

DecLoad 递减缓存服务器的负载

func (*ConsistentHash) GetHostByKey

func (ch *ConsistentHash) GetHostByKey(key string) (string, error)

GetHostByKey 根据Key查询Host

func (*ConsistentHash) GetHostByKeyLeast

func (ch *ConsistentHash) GetHostByKeyLeast(key string) (string, error)

GetHostByKeyLeast 有界负载的一致性哈希

func (*ConsistentHash) GetLoads

func (ch *ConsistentHash) GetLoads() map[string]int64

GetLoads 获取所有缓存服务器的负载数据

func (*ConsistentHash) IncLoad

func (ch *ConsistentHash) IncLoad(address string)

IncLoad 递增缓存服务器的负载

func (*ConsistentHash) MaxLoad

func (ch *ConsistentHash) MaxLoad() int64

MaxLoad 获取单节点的最大负载 (total_load / number_of_hosts) * (1 + load_bound_factor)

func (*ConsistentHash) RegisterHost

func (ch *ConsistentHash) RegisterHost(address string) error

RegisterHost 注册缓存服务器

func (*ConsistentHash) UnregisterHost

func (ch *ConsistentHash) UnregisterHost(address string) error

UnregisterHost 注销缓存服务器

type Host

type Host struct {
	// Address host:port
	Address string
	// LoadBound 缓存服务器的负载
	LoadBound int64
}

Jump to

Keyboard shortcuts

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