hashring

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package hashring 在理想情况下,每个物理节点受影响的数据量 为其节点缓存数据最的1/4 (X/(N+X))N为原 有物理节点数,X为新加入物理节点数), 也就是集群中已经被缓存的数据有75%可以被继续命中, 和未使用虚拟节点的一致性Hash算法结果相同, 只是解决的负载均衡的问题。 @author: xwc1125 @date: 2021/5/27

Index

Constants

View Source
const (
	// DefaultVirtualSpots default virtual spots
	DefaultVirtualSpots = 400
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HashRing

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

HashRing store nodes and weights

func NewHashRing

func NewHashRing(spots int) *HashRing

NewHashRing create a hash ring with virtual spots

func (*HashRing) AddNode

func (h *HashRing) AddNode(nodeKey uint64, weight uint64)

AddNode add node to hash ring

func (*HashRing) AddNodes

func (h *HashRing) AddNodes(nodeWeight map[uint64]uint64)

AddNodes add nodes to hash ring

func (*HashRing) GetNode

func (h *HashRing) GetNode(s string) (uint64, error)

GetNode get node with key

func (*HashRing) GetWeight

func (h *HashRing) GetWeight() map[uint64]uint64

func (*HashRing) RemoveNode

func (h *HashRing) RemoveNode(nodeKey uint64)

RemoveNode remove node

func (*HashRing) UpdateNode

func (h *HashRing) UpdateNode(nodeKey uint64, weight uint64)

UpdateNode update node with weight

Jump to

Keyboard shortcuts

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