util

package
v0.0.0-...-8639602 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2022 License: BSL-1.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 默认虚拟节点
	DefaultVirualSpots = 100
)

Variables

This section is empty.

Functions

func CaptureErrGo

func CaptureErrGo(function func(), callBack PanicErr)

捕获err go 协程,callBack 只有panic的时候才会有

func Sum64

func Sum64(key string) uint64

Sum64 gets the string and returns its uint64 hash value.

Types

type HashRing

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

HashRing 结构体

func NewHashRing

func NewHashRing(spots int) *HashRing

创建一个hashring 建议值 虚拟节点数 = 已知总节点数 * 100 如果知道总节点数为6 个,那么虚拟节点数值 = 6 *100 差值最小,分布最均匀,差值在千分之5以内

func (*HashRing) AddNode

func (h *HashRing) AddNode(nodeKey string, weight int)

AddNode 添加一个节点 , weight 权重

func (*HashRing) AddNodes

func (h *HashRing) AddNodes(nodeWeight map[string]int)

AddNodes 添加一个节点到换上

func (*HashRing) GetNode

func (h *HashRing) GetNode(key string) string

GetNode 根据一个key 获取一个节点主机

func (*HashRing) RemoveNode

func (h *HashRing) RemoveNode(nodeKey string)

RemoveNode 移除一个节点

func (*HashRing) UpdateNode

func (h *HashRing) UpdateNode(nodeKey string, weight int)

UpdateNode 更新一个节点的权重

type PanicErr

type PanicErr func(err any)

Jump to

Keyboard shortcuts

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