hashring

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2016 License: MIT Imports: 8 Imported by: 0

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 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
	// 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) AddRemoveServers

func (r *HashRing) AddRemoveServers(add []string, remove []string) bool

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) AddServer

func (r *HashRing) AddServer(address string) bool

AddServer adds a server and its replicas onto the HashRing.

func (*HashRing) Checksum

func (r *HashRing) 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) 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) RegisterListener

func (r *HashRing) RegisterListener(l events.EventListener)

RegisterListener adds a listener that will listen for hashring events.

func (*HashRing) RemoveServer

func (r *HashRing) RemoveServer(address string) bool

RemoveServer removes a server and its 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