internal

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PeerStatusUp   = PeerStatus(1)
	PeerStatusDown = PeerStatus(2)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrivalIntervals

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

ArrivalIntervals tracks the intervals in a circular buffer.

func NewArrivalIntervals

func NewArrivalIntervals(sampleSize int) *ArrivalIntervals

func (*ArrivalIntervals) Add

func (ai *ArrivalIntervals) Add(interval uint64)

func (*ArrivalIntervals) Mean

func (ai *ArrivalIntervals) Mean() float64

type ArrivalWindow

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

func NewArrivalWindow

func NewArrivalWindow(gossipInterval uint64, sampleSize int) *ArrivalWindow

func (*ArrivalWindow) Add

func (w *ArrivalWindow) Add(timestampNano uint64)

func (*ArrivalWindow) Phi

func (w *ArrivalWindow) Phi(timestampNano uint64) float64

type Delta

type Delta struct {
	Addr    string
	Key     string
	Value   string
	Version uint64
}

func (Delta) MarshalLogObject

func (e Delta) MarshalLogObject(enc zapcore.ObjectEncoder) error

type Digest

type Digest struct {
	Addr    string
	Version uint64
}

func (Digest) MarshalLogObject

func (p Digest) MarshalLogObject(enc zapcore.ObjectEncoder) error

type FailureDetector

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

FailureDetector is a failure detector that detects down nodes based on incoming heartbeats.

This implements the paper "The Phi Accrual Failure Detector".

func NewFailureDetector

func NewFailureDetector(gossipInterval uint64, sampleSize int, convictThreshold float64) *FailureDetector

func (*FailureDetector) PeerStatus

func (fd *FailureDetector) PeerStatus(endpoint string) PeerStatus

func (*FailureDetector) PeerStatusAtTimestamp

func (fd *FailureDetector) PeerStatusAtTimestamp(endpoint string, timestampNano uint64) PeerStatus

func (*FailureDetector) RemovePeer

func (fd *FailureDetector) RemovePeer(endpoint string)

func (*FailureDetector) Report

func (fd *FailureDetector) Report(endpoint string)

func (*FailureDetector) ReportWithTimestamp

func (fd *FailureDetector) ReportWithTimestamp(endpoint string, timestampNano uint64)

type Gossiper

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

func NewGossiper

func NewGossiper(peerMap *PeerMap, transport Transport, failureDetector *FailureDetector, maxMessageSize int, logger *zap.Logger) *Gossiper

func (*Gossiper) Addrs

func (g *Gossiper) Addrs(includeLocal bool) []string

func (*Gossiper) BindAddr

func (g *Gossiper) BindAddr() string

func (*Gossiper) CheckLiveness

func (g *Gossiper) CheckLiveness()

func (*Gossiper) Close

func (g *Gossiper) Close() error

func (*Gossiper) Lookup

func (g *Gossiper) Lookup(addr string, key string) (string, bool)

func (*Gossiper) OnMessage

func (g *Gossiper) OnMessage(b []byte, fromAddr string) error

func (*Gossiper) RandomDownPeer

func (g *Gossiper) RandomDownPeer() (string, bool)

func (*Gossiper) RandomUpPeer

func (g *Gossiper) RandomUpPeer() (string, bool)

func (*Gossiper) Seed

func (g *Gossiper) Seed(seeds []string)

func (*Gossiper) SendDigestRequest

func (g *Gossiper) SendDigestRequest(addr string) error

func (*Gossiper) UpdateLocal

func (g *Gossiper) UpdateLocal(key string, value string)

type Packet

type Packet struct {
	// Buf has the raw contents of the packet.
	Buf []byte

	// From has the address of the peer. This is an actual net.Addr so we
	// can expose some concrete details about incoming packets.
	From net.Addr
}

Packet is used to provide some metadata about incoming packets from peers over a packet connection, as well as the packet payload.

type Peer

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

Peer represents the state of a peer.

func NewPeer

func NewPeer(addr string) *Peer

NewPeer returns a new peer with the given address, with a version of 0 to indicate it has no known state.

func (*Peer) Addr

func (p *Peer) Addr() string

func (*Peer) Deltas

func (p *Peer) Deltas(version uint64) []Delta

Deltas returns all entries whos versions exceed the given version, ordered by version.

Note the deltas are ordered by version since the full all deltas may not be sent and we can't have gaps in versions.

func (*Peer) Digest

func (p *Peer) Digest() Digest

func (*Peer) Equal

func (p *Peer) Equal(o *Peer) bool

func (*Peer) Expiry

func (p *Peer) Expiry() time.Time

func (*Peer) Lookup

func (p *Peer) Lookup(key string) (PeerEntry, bool)

func (*Peer) SetStatusDown

func (p *Peer) SetStatusDown(expiry time.Time)

SetStatusDown sets the status to down and sets the expiry of when the peer should be removed if it hasen't come up.

func (*Peer) SetStatusUp

func (p *Peer) SetStatusUp()

func (*Peer) Status

func (p *Peer) Status() PeerStatus

func (*Peer) UpdateLocal

func (p *Peer) UpdateLocal(key string, value string)

UpdateLocal updates the peer when it is owned by the local node. This increments the peers version so it is propagated around the cluster. If the value is unchanged, the version isn't updated (to avoid propagating redundant data).

func (*Peer) UpdateRemote

func (p *Peer) UpdateRemote(key string, value string, version uint64)

UpdateRemote updates the peer from an update from a remote node. If the local version of that entry is greater than the new version, the update is discarded.

func (*Peer) Version

func (p *Peer) Version() uint64

type PeerEntry

type PeerEntry struct {
	Version uint64
	Value   string
}

type PeerMap

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

PeerMap contains this nodes view of all known peers in the cluster.

Note this is thread safe.

func NewPeerMap

func NewPeerMap(
	localAddr string,
	onJoin func(addr string),
	onLeave func(addr string),
	onUpdate func(addr string, key string, value string),
	logger *zap.Logger,
) *PeerMap

func (*PeerMap) Addrs

func (m *PeerMap) Addrs(includeLocal bool) []string

Addrs returns the addresses of the up peers known by this node. If includeLocal is true the local node is included, otherwise it isn't.

func (*PeerMap) ApplyDelta

func (m *PeerMap) ApplyDelta(delta Delta)

func (*PeerMap) ApplyDigest

func (m *PeerMap) ApplyDigest(digest Digest)

func (*PeerMap) Deltas

func (m *PeerMap) Deltas(addr string, version uint64) []Delta

func (*PeerMap) Digest

func (m *PeerMap) Digest(addr string) Digest

func (*PeerMap) DownPeers

func (m *PeerMap) DownPeers() []string

func (*PeerMap) Lookup

func (m *PeerMap) Lookup(addr string, key string) (PeerEntry, bool)

func (*PeerMap) PeersEqual

func (m *PeerMap) PeersEqual(o *PeerMap) bool

func (*PeerMap) RemoveExpiredPeers

func (m *PeerMap) RemoveExpiredPeers() []string

func (*PeerMap) SetStatusDown

func (m *PeerMap) SetStatusDown(addr string, expiry time.Time)

func (*PeerMap) SetStatusUp

func (m *PeerMap) SetStatusUp(addr string)

func (*PeerMap) UpdateLocal

func (m *PeerMap) UpdateLocal(key string, value string)

UpdateLocal updates an entery in this nodes local peer.

func (*PeerMap) Version

func (m *PeerMap) Version(addr string) uint64

type PeerStatus

type PeerStatus int

type Transport

type Transport interface {
	// WriteTo is a packet-oriented interface that fires off the given
	// payload to the given address in a connectionless fashion.
	WriteTo(b []byte, addr string) error

	// BindAddr returns the address the transport listener is bound to. Note
	// this may be different from the configured bind addr if the system chooses
	// the addr (such as using a port of 0).
	BindAddr() string

	// Shutdown is called when gossip is shutting down; this gives the
	// transport a chance to clean up any listeners.
	Shutdown() error
}

Transport is an interface for a best-effort packet oriented transport.

func NewUDPTransport

func NewUDPTransport(bindAddr string, onPacket func(p *Packet), logger *zap.Logger) (Transport, error)

NewUDPTransport returns a new UDP transport listening on the given addr.

type UDPTransport

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

UDPTransport is a Transport implementation using UDP.

func (*UDPTransport) BindAddr

func (t *UDPTransport) BindAddr() string

func (*UDPTransport) Shutdown

func (t *UDPTransport) Shutdown() error

func (*UDPTransport) WriteTo

func (t *UDPTransport) WriteTo(b []byte, addr string) error

Jump to

Keyboard shortcuts

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