Documentation ¶
Overview ¶
Package ring implements a simple ring CRDT.
Index ¶
- Variables
- type OnUpdate
- type RangeInfo
- type Ring
- func (r *Ring) AllRangeInfo() (result []RangeInfo)
- func (r *Ring) ChoosePeersToAskForSpace(start, end address.Address) []mesh.PeerName
- func (r *Ring) ClaimForPeers(peers []mesh.PeerName)
- func (r *Ring) Contains(addr address.Address) bool
- func (r *Ring) Empty() bool
- func (r *Ring) FprintWithNicknames(w io.Writer, m map[mesh.PeerName]string)
- func (r *Ring) GrantRangeToHost(start, end address.Address, peer mesh.PeerName)
- func (r *Ring) Merge(gossip Ring, hasAllocations func(r []address.Range) bool) (bool, error)
- func (r *Ring) OwnedRanges() (result []address.Range)
- func (r *Ring) OwnedRangesOfPeer(peer mesh.PeerName) (result []address.Range)
- func (r *Ring) Owner(token address.Address) mesh.PeerName
- func (r *Ring) PeerNames() map[mesh.PeerName]struct{}
- func (r *Ring) PickPeerForTransfer(isValid func(mesh.PeerName) bool) mesh.PeerName
- func (r *Ring) Range() address.Range
- func (r *Ring) ReportFree(freespace map[address.Address]address.Count) (updated bool)
- func (r *Ring) Restore(other *Ring)
- func (r *Ring) String() string
- func (r *Ring) Transfer(from, to mesh.PeerName) []address.Range
Constants ¶
This section is empty.
Variables ¶
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 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 (*Ring) AllRangeInfo ¶ added in v1.4.0
func (*Ring) ChoosePeersToAskForSpace ¶ added in v1.0.2
ChoosePeersToAskForSpace returns all peers we can ask for space in the range [start, end), in weighted-random order. Assumes start<end.
func (*Ring) ClaimForPeers ¶
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) FprintWithNicknames ¶
func (*Ring) GrantRangeToHost ¶
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 ¶
Merge the given ring into this ring and indicate whether this ring got updated as a result.
func (*Ring) OwnedRanges ¶
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 (*Ring) PickPeerForTransfer ¶
func (*Ring) ReportFree ¶
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.