Documentation ¶
Index ¶
- Constants
- func Hash(data []byte) uint64
- type Consistent
- type ConsistentHash
- func (h *ConsistentHash) Add(node string) error
- func (h *ConsistentHash) AddKey(key string) bool
- func (h *ConsistentHash) AddWithReplicas(node string, replicas int) error
- func (h *ConsistentHash) AddWithWeight(node string, weight int) error
- func (h *ConsistentHash) Get(v string) (string, *grpc.ClientConn, bool)
- func (h *ConsistentHash) Remove(node string) error
- type Func
Constants ¶
View Source
const (
// TopWeight is the maximum weight for a node in the consistent hashing ring.
TopWeight = 100
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Consistent ¶
type Consistent interface { Add(node string) error AddWithReplicas(node string, replicas int) error AddWithWeight(node string, weight int) error Get(v string) (string, *grpc.ClientConn, bool) Remove(node string) error AddKey(key string) bool }
Consistent is an interface for a consistent hash ring
type ConsistentHash ¶
type ConsistentHash struct { Nodes map[string]*grpc.ClientConn // Node addresses mapped to their gRPC client connections // contains filtered or unexported fields }
ConsistentHash implements a consistent hashing ring
func NewConsistentHash ¶
NewConsistentHash creates a new consistent hash ring
func (*ConsistentHash) Add ¶
func (h *ConsistentHash) Add(node string) error
Add adds a node to the hash ring with the default number of replicas
func (*ConsistentHash) AddKey ¶
func (h *ConsistentHash) AddKey(key string) bool
AddKey adds a key to the hash ring and assigns it to a node
func (*ConsistentHash) AddWithReplicas ¶
func (h *ConsistentHash) AddWithReplicas(node string, replicas int) error
AddWithReplicas adds a node to the hash ring with a specified number of replicas
func (*ConsistentHash) AddWithWeight ¶
func (h *ConsistentHash) AddWithWeight(node string, weight int) error
AddWithWeight adds a node to the hash ring with a number of replicas proportional to its weight
func (*ConsistentHash) Get ¶
func (h *ConsistentHash) Get(v string) (string, *grpc.ClientConn, bool)
Get returns the node responsible for the hash of the given key and its gRPC connection
func (*ConsistentHash) Remove ¶
func (h *ConsistentHash) Remove(node string) error
Remove removes a node from the hash ring
Click to show internal directories.
Click to hide internal directories.