Documentation ¶
Overview ¶
Package hashring provides a hashring implementation that uses a red-black Tree.
Index ¶
- type Checksummer
- type Configuration
- type HashRing
- func (r *HashRing) AddMembers(members ...membership.Member) bool
- func (r *HashRing) Checksum() (checksum uint32)
- func (r *HashRing) Checksums() (checksums map[string]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) ProcessMembershipChanges(changes []membership.MemberChange)
- func (r *HashRing) RemoveMembers(members ...membership.Member) 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 Checksummer ¶
type Checksummer interface { // Checksum calculates the checksum for the hashring that is passed in. // Compute will be called while having at least a read-lock on the hashring so // it is safe to read from the ring, but not safe to change the ring. There // might be multiple Checksum Computes initiated at the same time, but every // Checksum will only be called once per hashring at once Checksum(ring *HashRing) (checksum uint32) }
Checksummer computes a checksum for an instance of a HashRing. The checksum can be used to compare two rings for equality.
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 ¶
type HashRing struct { sync.RWMutex events.SyncEventEmitter // contains filtered or unexported fields }
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) AddMembers ¶
func (r *HashRing) AddMembers(members ...membership.Member) bool
AddMembers adds multiple membership Member's and thus their replicas to the HashRing.
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) Checksums ¶
Checksums returns a map of checksums named by the algorithm used to compute the checksum.
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) ProcessMembershipChanges ¶
func (r *HashRing) ProcessMembershipChanges(changes []membership.MemberChange)
ProcessMembershipChanges takes a slice of membership.MemberChange's and applies them to the hashring by adding and removing members accordingly to the changes passed in.
func (*HashRing) RemoveMembers ¶
func (r *HashRing) RemoveMembers(members ...membership.Member) bool
RemoveMembers removes multiple membership Member's and thus their replicas from the HashRing.
func (*HashRing) ServerCount ¶
ServerCount returns the number of servers contained in the HashRing.