hashring

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2022 License: MIT Imports: 11 Imported by: 12

Documentation

Overview

Package hashring provides a hashring implementation that uses a red-black Tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checksummer added in v0.8.0

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 New

func New(hashfunc func([]byte) uint32, replicaPoints int) *HashRing

New instantiates and returns a new HashRing.

func (*HashRing) AddMembers added in v0.8.0

func (r *HashRing) AddMembers(members ...membership.Member) bool

AddMembers adds multiple membership Member's and thus their replicas to the HashRing.

func (*HashRing) Checksum

func (r *HashRing) Checksum() (checksum uint32)

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 added in v0.8.0

func (r *HashRing) Checksums() (checksums map[string]uint32)

Checksums returns a map of checksums named by the algorithm used to compute the checksum.

func (*HashRing) HasServer

func (r *HashRing) HasServer(server string) bool

HasServer returns whether the HashRing contains the given server.

func (*HashRing) Lookup

func (r *HashRing) Lookup(key string) (string, bool)

Lookup returns the owner of the given key and whether the HashRing contains the key at all.

func (*HashRing) LookupN

func (r *HashRing) LookupN(key string, n int) []string

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 added in v0.8.0

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 added in v0.8.0

func (r *HashRing) RemoveMembers(members ...membership.Member) bool

RemoveMembers removes multiple membership Member's and thus their replicas from the HashRing.

func (*HashRing) ServerCount

func (r *HashRing) ServerCount() int

ServerCount returns the number of servers contained in the HashRing.

func (*HashRing) Servers

func (r *HashRing) Servers() []string

Servers returns all servers contained in the HashRing.

Jump to

Keyboard shortcuts

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