hashring

package
v0.11.7 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashRing

type HashRing struct {
	VRing           *rbtree.Rbtree
	NRing           *rbtree.Rbtree
	Nodes           *sync.Map // map(NodeID => *Node)
	NodeStatus      *sync.Map // map(NodeID => status)
	NodeCount       uint32
	NodeOkCount     uint32
	NumberOfVirtual uint32
	sync.Mutex
}

func New

func New(numOfVNode uint32) *HashRing

func (*HashRing) AddNode

func (r *HashRing) AddNode(node *Node)

func (*HashRing) GetNode

func (r *HashRing) GetNode(key string) (uint32, string)

GetNode calculates an index from the given key, and returns a node selected using this index

func (*HashRing) GetNodeByIndex

func (r *HashRing) GetNodeByIndex(keyIndex uint32) (uint32, string)

func (*HashRing) GetNodeExcludedNodeIDs

func (r *HashRing) GetNodeExcludedNodeIDs(key string, NodeIDs []string, setOffline bool) (uint32, string)

GetNodeExcludedNodeIDs calculates an index from the given key, and returns a node selected using this index. The nodes with IDs specified by NodeIDs will be excluded. If setOffline is true, the excluded nodes will become offline.

func (*HashRing) GetNodeUpDownNodes

func (r *HashRing) GetNodeUpDownNodes(NodeID string) (string, string)

GetNodeUpDownNodes get upstream of downstream of node

func (*HashRing) IsOnline

func (r *HashRing) IsOnline(ID string) bool

func (*HashRing) Node

func (r *HashRing) Node(ID string) *Node

func (*HashRing) PrintNodes

func (r *HashRing) PrintNodes()

PrintNodes print all non-virtual nodes

func (*HashRing) RandomGetNodes

func (r *HashRing) RandomGetNodes(num int) []*Node

RandomGetNodes return random nodes from the hashring

func (*HashRing) RemoveNode

func (r *HashRing) RemoveNode(nodeID string) bool

func (*HashRing) SetOffline

func (r *HashRing) SetOffline(ID string)

func (*HashRing) SetOnline

func (r *HashRing) SetOnline(ID string)

func (*HashRing) TraversalNRing

func (r *HashRing) TraversalNRing()

TraversalNRing traverse non-virtual rbtree

func (*HashRing) TraversalVRing

func (r *HashRing) TraversalVRing()

TraversalVRing traverse virtual rbtree

func (*HashRing) UpdateNodeDiskUsage added in v0.9.0

func (r *HashRing) UpdateNodeDiskUsage(ID string, diskSize, freeDisk uint64)

type Node

type Node struct {
	ID        string
	Host      string
	Rest      string
	Data      *sync.Map
	DiskUsage float64
}

func (*Node) Less

func (n *Node) Less(than rbtree.Item) bool

Less of rbtree

func (*Node) SetDiskUsage added in v0.9.0

func (n *Node) SetDiskUsage(diskSize, freeDisk uint64)

type VNode

type VNode struct {
	Index  uint32 // index, crc32 of hashkey
	NodeID string
}

VNode virtual node

func (*VNode) Less

func (vn *VNode) Less(than rbtree.Item) bool

Less of rbtree

type VWeightedNode added in v0.5.0

type VWeightedNode struct {
	Index  uint32 // index, crc32 of hashkey
	NodeID string
}

VWeightedNode virtual node

func (*VWeightedNode) Less added in v0.5.0

func (vwn *VWeightedNode) Less(than rbtree.Item) bool

Less of rbtree

type WeightedHashRing added in v0.5.0

type WeightedHashRing struct {
	VRing           *rbtree.Rbtree
	NRing           *rbtree.Rbtree
	Nodes           *sync.Map // map(NodeID => *WeightedNode)
	NodeStatus      *sync.Map // map(NodeID => status)
	NodeCount       uint32
	NodeOkCount     uint32
	NumberOfVirtual uint32
	sync.Mutex
}

func NewWeightedHashRing added in v0.5.0

func NewWeightedHashRing() *WeightedHashRing

func (*WeightedHashRing) AddNode added in v0.5.0

func (r *WeightedHashRing) AddNode(node *WeightedNode)

func (*WeightedHashRing) GetNode added in v0.5.0

func (r *WeightedHashRing) GetNode(key string) (uint32, string)

GetNode calculates an index from the given key, and returns a node selected using this index

func (*WeightedHashRing) GetNodeByIndex added in v0.5.0

func (r *WeightedHashRing) GetNodeByIndex(keyIndex uint32) (uint32, string)

func (*WeightedHashRing) GetNodeExcludedNodeIDs added in v0.5.0

func (r *WeightedHashRing) GetNodeExcludedNodeIDs(key string, NodeIDs []string, setOffline bool) (uint32, string)

GetNodeExcludedNodeIDs calculates an index from the given key, and returns a node selected using this index. The nodes with IDs specified by NodeIDs will be excluded. If setOffline is true, the excluded nodes will become offline.

func (*WeightedHashRing) GetNodeUpDownNodes added in v0.5.0

func (r *WeightedHashRing) GetNodeUpDownNodes(NodeID string) (string, string)

GetNodeUpDownNodes get upstream of downstream of node

func (*WeightedHashRing) IsOnline added in v0.5.0

func (r *WeightedHashRing) IsOnline(ID string) bool

func (*WeightedHashRing) Node added in v0.5.0

func (r *WeightedHashRing) Node(ID string) *WeightedNode

func (*WeightedHashRing) PrintNodes added in v0.5.0

func (r *WeightedHashRing) PrintNodes()

PrintNodes print all non-virtual nodes

func (*WeightedHashRing) RandomGetNodes added in v0.5.0

func (r *WeightedHashRing) RandomGetNodes(num int) []*WeightedNode

RandomGetNodes return random nodes from the hashring

func (*WeightedHashRing) RemoveNode added in v0.5.0

func (r *WeightedHashRing) RemoveNode(nodeID string) bool

func (*WeightedHashRing) SetOffline added in v0.5.0

func (r *WeightedHashRing) SetOffline(ID string)

func (*WeightedHashRing) SetOnline added in v0.5.0

func (r *WeightedHashRing) SetOnline(ID string)

func (*WeightedHashRing) TraversalNRing added in v0.5.0

func (r *WeightedHashRing) TraversalNRing()

TraversalNRing traverse non-virtual rbtree

func (*WeightedHashRing) TraversalVRing added in v0.5.0

func (r *WeightedHashRing) TraversalVRing()

TraversalVRing traverse virtual rbtree

func (*WeightedHashRing) UpdateCopies added in v0.10.0

func (r *WeightedHashRing) UpdateCopies(nodeID string, updatedCopies uint32)

type WeightedNode added in v0.5.0

type WeightedNode struct {
	ID     string
	Host   string
	Rest   string
	Copies uint32 // Number of copies in the hashring
	Data   *sync.Map
}

func (*WeightedNode) Less added in v0.5.0

func (n *WeightedNode) Less(than rbtree.Item) bool

Less of rbtree

Jump to

Keyboard shortcuts

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