consistentHashing

package
v0.0.0-...-8e1c7b4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddOne

func AddOne(key string) string

Add key by one, the key is usually a very large number, mixing number & alphabetic letter. This method is used specifically for adding SHA1 result by 1

func SubOne

func SubOne(key string) string

Substract key by one, the key is usually a very large number, mixing number & alphabetic letter. This method is used specifically for substractign SHA1 result by 1

Types

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

The abstruct structure of consistent hash ring. It consists of a Red-Black-Tree serve as the ring.

func NewRing

func NewRing() (ring *Ring)

Create a new consistent hashing ring with default value setting.

@return: pointer to new created consistent hashing ring

func (*Ring) AddAsync

func (ring *Ring) AddAsync(addChan <-chan *node.Node, complete chan<- *node.Node)

Add a new Node to consistent hashing ring.

@param addChan: incoming channel of Node pointer @param complete: outgoing channel of Node pointer, indicating

which Node has been added

func (*Ring) AddSync

func (ring *Ring) AddSync(node *node.Node)

Add a new Node to consistent hashing ring. This function block the running routine until the Node is successfully added.

@param node: Node to be added

func (*Ring) Empty

func (ring *Ring) Empty() bool

Check if the ring is empty/no node alive

@return: true if ring is empty otherwise false

func (*Ring) Get

func (ring *Ring) Get(key string) (*node.Node, bool)

Get a Node given a specific key.

@param key: string of key @return: if key exists in tree, return the node and true, otherwise return

return nil and false

func (*Ring) Keys

func (ring *Ring) Keys() []string

Get all keys in the ring in ascending order

@return: all keys in ascending order

func (*Ring) LookUp

func (ring *Ring) LookUp(key string) (*node.Node, error)

Lookup for a Node in consistent hashing ring given a key. If the input key is the same as some Node's key, then the result is that exact Node.

@param key: string of key @return: return the node if such successor founded, otherwise an error is

given

func (*Ring) Predecessor

func (ring *Ring) Predecessor(key string) (*node.Node, error)

Get predecessor of a given key(this key is supposed to belong to a Node)

@param key: string of key @return: return the node if such predecessor founded, otherwise an error is

given

func (*Ring) RemoveAsync

func (ring *Ring) RemoveAsync(removeChan <-chan *node.Node, complete chan<- *node.Node)

Remove a Node from consistent hashing ring.

@param removeChan: incoming channel of Node pointer @param complete: outgoing channel of Node pointer, indicating

which Node has been removed

func (*Ring) RemoveSync

func (ring *Ring) RemoveSync(node *node.Node)

Remove a new Node to consistent hashing ring. This function block the running routine until the Node is successfully removed.

@param node: Node to be removed

func (*Ring) Successor

func (ring *Ring) Successor(key string) (*node.Node, error)

Get successor of a given key(this key is supposed to belong to a Node)

@param key: string of key @return: return the node if such successor founded, otherwise an error is

given

func (*Ring) Values

func (ring *Ring) Values() []*node.Node

Get all values in the ring corresponding to the keys in ascending order

@return: all values in the ring corresponding to the keys in ascending order

Jump to

Keyboard shortcuts

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