ring

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2015 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package ring implements a simple ring CRDT.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSorted       = errors.New("Ring not sorted")
	ErrTokenRepeated   = errors.New("Token appears twice in ring")
	ErrTokenOutOfRange = errors.New("Token is out of range")
	ErrDifferentSeeds  = errors.New("Received ring was seeded differently from ours!")
	ErrDifferentRange  = errors.New("Received range differs from ours!")
	ErrNewerVersion    = errors.New("Received new version for entry I own!")
	ErrInvalidEntry    = errors.New("Received invalid state update!")
	ErrEntryInMyRange  = errors.New("Received new entry in my range!")
	ErrNotFound        = errors.New("No entries for peer found")
)

Errors returned by Merge

Functions

This section is empty.

Types

type Ring

type Ring struct {
	Start, End address.Address // [min, max) tokens in this ring.  Due to wrapping, min == max (effectively)
	Peer       mesh.PeerName   // name of peer owning this ring instance
	Entries    entries         // list of entries sorted by token
	Seeds      []mesh.PeerName // peers with which the ring was seeded
}

Ring represents the ring itself

func New

func New(start, end address.Address, peer mesh.PeerName) *Ring

New creates an empty ring belonging to peer.

func (*Ring) ChoosePeersToAskForSpace added in v1.0.2

func (r *Ring) ChoosePeersToAskForSpace(start, end address.Address) []mesh.PeerName

ChoosePeersToAskForSpace returns all peers we can ask for space in the range [start, end), in weighted-random order. Assumes start<end.

func (*Ring) ClaimForPeers

func (r *Ring) ClaimForPeers(peers []mesh.PeerName)

ClaimForPeers claims the entire ring for the array of peers passed in. Only works for empty rings.

func (*Ring) Contains

func (r *Ring) Contains(addr address.Address) bool

Contains returns true if addr is in this ring

func (*Ring) Empty

func (r *Ring) Empty() bool

Empty returns true if the ring has no entries

func (*Ring) FprintWithNicknames

func (r *Ring) FprintWithNicknames(w io.Writer, m map[mesh.PeerName]string)

func (*Ring) GrantRangeToHost

func (r *Ring) GrantRangeToHost(start, end address.Address, peer mesh.PeerName)

GrantRangeToHost modifies the ring such that range [start, end) is assigned to peer. This may insert up to two new tokens. Preconditions: - start < end - [start, end) must be owned by the calling peer

func (*Ring) Merge

func (r *Ring) Merge(gossip Ring) error

Merge the given ring into this ring and return any new ranges added

func (*Ring) OwnedRanges

func (r *Ring) OwnedRanges() (result []address.Range)

OwnedRanges returns slice of Ranges, ordered by IP, indicating which ranges are owned by this peer. Will split ranges which span 0 in the ring.

func (*Ring) Owner

func (r *Ring) Owner(token address.Address) mesh.PeerName

Owner returns the peername which owns the range containing addr

func (*Ring) PeerNames

func (r *Ring) PeerNames() map[mesh.PeerName]struct{}

Get the set of PeerNames mentioned in the ring

func (*Ring) PickPeerForTransfer

func (r *Ring) PickPeerForTransfer(isValid func(mesh.PeerName) bool) mesh.PeerName

func (*Ring) Range added in v1.1.0

func (r *Ring) Range() address.Range

func (*Ring) ReportFree

func (r *Ring) ReportFree(freespace map[address.Address]address.Offset)

ReportFree is used by the allocator to tell the ring how many free ips are in a given range, so that ChoosePeersToAskForSpace can make more intelligent decisions.

func (*Ring) String

func (r *Ring) String() string

func (*Ring) Transfer

func (r *Ring) Transfer(from, to mesh.PeerName) ([]address.Range, error)

Transfer will mark all entries associated with 'from' peer as owned by 'to' peer and return ranges indicating the new space we picked up

Jump to

Keyboard shortcuts

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