hashring

package
v0.0.0-...-4aff305 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2018 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const BloomEventType = "bloom"

BloomEventType is a event type where the underlying bloom filter is broadcast to other nodes, to help improve the hashring.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

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

Actor represents a way to communicate to a node in the cluster. The actor also has some knowledge of a potential key living inside the underlying store.

func NewActor

func NewActor(strategy NodeStrategy) *Actor

NewActor creates a Actor with the correct Transport for communicating to the various end point.

func (*Actor) Add

func (n *Actor) Add(data string) error

Add adds a known piece of data to the actor to improve the potential of finding the data with in the store. Consider this as a Hint to improve various consensus algorithms.

func (*Actor) Contains

func (n *Actor) Contains(data string) bool

Contains checks to see if there is any potential data in the underlying store.

func (*Actor) Hash

func (n *Actor) Hash() uint32

Hash returns the unique hash of the actor node

func (*Actor) Host

func (n *Actor) Host() string

Host returns the host of the actor node

func (*Actor) Time

func (n *Actor) Time() clock.Time

Time returns the time of a last modification of the actor

func (*Actor) Update

func (n *Actor) Update(payload []byte) error

Update performs a union of the shared knowledge Hint. The update payload will more or less come from other nodes in the cluster and a union is an attempt to gather a much information as possible over time about what each store holds.

type Actors

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

Actors is a collection of the Actor Node allowing accessing the actor via the host or via a hash.

func NewActors

func NewActors() *Actors

NewActors creates a Actors with the correct dependencies

func (*Actors) Get

func (n *Actors) Get(hash uint32) (*Actor, bool)

Get returns a the Actor according to the hash of the node Returns the ok if the node is found.

func (*Actors) Hashes

func (n *Actors) Hashes() []uint32

Hashes returns a slice of hashes in the nodeset

func (*Actors) Remove

func (n *Actors) Remove(hash uint32)

Remove a Actor via it's addr

func (*Actors) Set

func (n *Actors) Set(v *Actor)

Set adds a Actor to the nodes according to the address hash If a hash already exists, then it will over write the existing hash value

func (*Actors) String

func (n *Actors) String() string

String returns a table view of the internal actor nodes

func (*Actors) Update

func (n *Actors) Update(hash uint32, payload []byte) error

Update the payload of a hash node Return error if the writing to the bloom fails

type Cluster

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

Cluster represents a set of nodes with in the cluster

func NewCluster

func NewCluster(peer cluster.Peer,
	transport api.TransportStrategy,
	replicationFactor int,
	localAPIAddr string,
	logger log.Logger,
) *Cluster

NewCluster creates a Cluster with the correct dependencies

func (*Cluster) DeregisterEventHandler

func (n *Cluster) DeregisterEventHandler(fn members.EventHandler) error

DeregisterEventHandler removes feed back from the underlying peers

func (*Cluster) Read

func (n *Cluster) Read(key selectors.Key, quorum selectors.Quorum) (nodes []nodes.Node)

Read returns a set of nodes in a specific time. Nodes which are used from the Read are not guaranteed to succeed for longer than their purpose. It is not recommended to store the nodes locally as they may not be the same nodes over time.

func (*Cluster) RegisterEventHandler

func (n *Cluster) RegisterEventHandler(fn members.EventHandler) error

RegisterEventHandler gives feed back from the underlying peers

func (*Cluster) Run

func (n *Cluster) Run() error

Run the Cluster snapshot selection process, this is required to get a valid picture of the cluster at large.

func (*Cluster) Stop

func (n *Cluster) Stop()

Stop the Cluster snapshot selection process

func (*Cluster) Write

func (n *Cluster) Write(key selectors.Key, quorum selectors.Quorum) ([]nodes.Node, func([]uint32) error)

type ClusterEventHandler

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

ClusterEventHandler holds a reference to the cluster so that we can effectively deal with the events comming in from the cluster.

func (ClusterEventHandler) HandleEvent

func (h ClusterEventHandler) HandleEvent(e members.Event) error

HandleEvent handles the member events comming from the cluster.

type HashRing

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

HashRing stores strings on a consistent hash ring. HashRing internally uses Red-Black Tree to achieve O(log N) lookup and insertion time.

func NewHashRing

func NewHashRing(replicationFactor int) *HashRing

NewHashRing creates a new HashRing with a replication factor

func (*HashRing) Add

func (r *HashRing) Add(host string) bool

Add a host and replicates it around the hashring according to the replication factor. Returns true if an insertion happens for all replicated points

func (*HashRing) Contains

func (r *HashRing) Contains(key string) bool

Contains checks to see if a key is already in the ring. Returns true if a key is found with in the ring.

func (*HashRing) Hosts

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

Hosts returns the hosts in a slice.

func (*HashRing) Len

func (r *HashRing) Len() int

Len returns the number of unique hosts

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

func (r *HashRing) Remove(host string) bool

Remove a host from the hashring including all the subsequent replicated hosts. Returns true if a deletion happens to all the replicated points

type NodeStrategy

type NodeStrategy func() nodes.Node

type Snapshot

type Snapshot interface {

	// Write returns a set of nodes for a specific time. Nodes which are
	// used from the Read Snapshot are not guaranteed to succeed for longer than
	// their purpose.
	// It is not recommended to store the nodes locally as they may not be the same
	// nodes over time.
	// The function commits the values to the blooms once they've been written
	Write(selectors.Key, selectors.Quorum) ([]nodes.Node, func([]uint32) error)

	// Read returns a set of nodes for a specific time. Nodes which are
	// used from the Read Snapshot are not guaranteed to succeed for longer than
	// their purpose.
	// It is not recommended to store the nodes locally as they may not be the same
	// nodes over time.
	Read(selectors.Key, selectors.Quorum) []nodes.Node
}

Snapshot defines a way to snapshot a series of nodes at a specific time.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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