ring

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2016 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!")
)

Errors returned by Merge

Functions

This section is empty.

Types

type OnUpdate added in v1.6.0

type OnUpdate func(prev, curr []address.Range, local bool)

type RangeInfo added in v1.4.0

type RangeInfo struct {
	Peer mesh.PeerName
	address.Range
	Version uint32
}

For printing status

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
	// contains filtered or unexported fields
}

Ring represents the ring itself

func New

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

New creates an empty ring belonging to peer.

func (*Ring) AllRangeInfo added in v1.4.0

func (r *Ring) AllRangeInfo() (result []RangeInfo)

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. Each claimed range is CIDR-aligned.

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) (bool, error)

Merge the given ring into this ring and indicate whether this ring got updated as a result.

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) OwnedRangesOfPeer added in v1.6.0

func (r *Ring) OwnedRangesOfPeer(peer mesh.PeerName) (result []address.Range)

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.Count) (updated bool)

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. Returns true if any changes made.

func (*Ring) Restore added in v1.6.0

func (r *Ring) Restore(other *Ring)

func (*Ring) String

func (r *Ring) String() string

func (*Ring) Transfer

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

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