Documentation ¶
Overview ¶
Package hashring provides a hashring implementation that uses a red-black Tree.
Index ¶
- type Configuration
- type HashRing
- func (r *HashRing) AddRemoveServers(add []string, remove []string) bool
- func (r *HashRing) AddServer(address string) bool
- func (r *HashRing) Checksum() uint32
- func (r *HashRing) HasServer(server string) bool
- func (r *HashRing) Lookup(key string) (string, bool)
- func (r *HashRing) LookupN(key string, n int) []string
- func (r *HashRing) RegisterListener(l events.EventListener)
- func (r *HashRing) RemoveServer(address string) bool
- func (r *HashRing) ServerCount() int
- func (r *HashRing) Servers() []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Configuration ¶
type Configuration struct { // ReplicaPoints is the number of positions a node will be assigned on the // ring. A bigger number will provide better key distribution, but require // more computation when building or traversing the ring (typically on // lookups or membership changes). ReplicaPoints int }
Configuration is a configuration struct that can be passed to the Ringpop constructor to customize hash ring options.
type HashRing ¶
HashRing stores strings on a consistent hash ring. HashRing internally uses a Red-Black Tree to achieve O(log N) lookup and insertion time.
func (*HashRing) AddRemoveServers ¶
AddRemoveServers adds and removes servers and all replicas associated to those servers to and from the HashRing. Returns whether the HashRing has changed.
func (*HashRing) Checksum ¶
Checksum returns the checksum of all stored servers in the HashRing Use this value to find out if the HashRing is mutated.
func (*HashRing) Lookup ¶
Lookup returns the owner of the given key and whether the HashRing contains the key at all.
func (*HashRing) LookupN ¶
LookupN returns the N servers that own the given key. Duplicates in the form of virtual nodes are skipped to maintain a list of unique servers. If there are less servers than N, we simply return all existing servers.
func (*HashRing) RegisterListener ¶
func (r *HashRing) RegisterListener(l events.EventListener)
RegisterListener adds a listener that will listen for hashring events.
func (*HashRing) RemoveServer ¶
RemoveServer removes a server and its replicas from the HashRing.
func (*HashRing) ServerCount ¶
ServerCount returns the number of servers contained in the HashRing.