peer

package
v6.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CRStatesPeersThreadsafe

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

CRStatesPeersThreadsafe provides safe access for multiple goroutines to read a map of Traffic Monitor peers to their returned Crstates, with a single goroutine writer. This could be made lock-free, if the performance was necessary

func NewCRStatesPeersThreadsafe

func NewCRStatesPeersThreadsafe(quorumMin int) CRStatesPeersThreadsafe

NewCRStatesPeersThreadsafe creates a new CRStatesPeers object safe for multiple goroutine readers and a single writer.

func (*CRStatesPeersThreadsafe) GetCrstates

func (t *CRStatesPeersThreadsafe) GetCrstates() map[tc.TrafficMonitorName]tc.CRStates

GetCrstates returns the internal Traffic Monitor peer Crstates data. This MUST NOT be modified.

func (*CRStatesPeersThreadsafe) GetPeerAvailability

func (t *CRStatesPeersThreadsafe) GetPeerAvailability(peer tc.TrafficMonitorName) bool

GetPeerAvailability returns the state of the given peer

func (*CRStatesPeersThreadsafe) GetPeersOnline

func (t *CRStatesPeersThreadsafe) GetPeersOnline() map[tc.TrafficMonitorName]bool

GetPeersOnline return a map of peers which are marked ONLINE in the latest CRConfig from Traffic Ops. This is NOT guaranteed to actually _contain_ all OFFLINE monitors returned by other functions, such as `GetPeerAvailability` and `GetQueryTimes`, but bool defaults to false, so the value of any key is guaranteed to be correct.

func (*CRStatesPeersThreadsafe) GetQueryTimes

func (t *CRStatesPeersThreadsafe) GetQueryTimes() map[tc.TrafficMonitorName]time.Time

GetQueryTimes returns the last query time of all peers

func (*CRStatesPeersThreadsafe) HasAvailablePeers

func (t *CRStatesPeersThreadsafe) HasAvailablePeers() bool

HasAvailablePeers returns true if at least one peer is ONLINE and available (reachable via polling)

func (*CRStatesPeersThreadsafe) HasOptimisticQuorum

func (t *CRStatesPeersThreadsafe) HasOptimisticQuorum() (bool, int, int, int)

HasOptimisticQuorum returns true when the number of available peers is equal to or greater than the peer_optimistic_quorum_min setting.

func (*CRStatesPeersThreadsafe) OptimisticQuorumEnabled

func (t *CRStatesPeersThreadsafe) OptimisticQuorumEnabled() bool

OptimisticQuorumEnabled returns true when peer_optimistic_quorum_min is set to a value greater than zero and the number of peers is greater than 1. Optimistic quorum requires a minimum of three Traffic Monitors; every individual monitor requires at least two peers to prevent a split-brain scenario that would be caused by having a single peer. If a single peer was legal (i.e.: two Traffic Monitors), neither peer would know which peer is reachable, and consequently both would serve 503s. This would force all Traffic Routers to use only their last-known state until the peering is restored, despite the fact that one of the two Traffic Monitors could still be reachable. A future enhancement could employ a heuristic to enable two monitors to determine whether they are offline independently by combining peer connectivity state with a calculation around the number of caches that are reachable, which might also include a rate of change in cache health state.

func (*CRStatesPeersThreadsafe) Set

func (t *CRStatesPeersThreadsafe) Set(result Result)

Set sets the internal Traffic Monitor peer state and Crstates data. This MUST NOT be called by multiple goroutines.

func (*CRStatesPeersThreadsafe) SetPeers

func (t *CRStatesPeersThreadsafe) SetPeers(newPeers map[tc.TrafficMonitorName]struct{})

func (*CRStatesPeersThreadsafe) SetTimeout

func (t *CRStatesPeersThreadsafe) SetTimeout(timeout time.Duration)

type CRStatesThreadsafe

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

CRStatesThreadsafe provides safe access for multiple goroutines to read a single Crstates object, with a single goroutine writer. This could be made lock-free, if the performance was necessary TODO add separate locks for Caches and DeliveryService maps?

func NewCRStatesThreadsafe

func NewCRStatesThreadsafe() CRStatesThreadsafe

NewCRStatesThreadsafe creates a new CRStatesThreadsafe object safe for multiple goroutine readers and a single writer.

func (*CRStatesThreadsafe) AddCache

func (t *CRStatesThreadsafe) AddCache(cacheName tc.CacheName, available tc.IsAvailable)

AddCache adds the internal availability data for a particular cache.

func (*CRStatesThreadsafe) DeleteCache

func (t *CRStatesThreadsafe) DeleteCache(name tc.CacheName)

DeleteCache deletes the given cache from the internal data.

func (*CRStatesThreadsafe) DeleteDeliveryService

func (t *CRStatesThreadsafe) DeleteDeliveryService(name tc.DeliveryServiceName)

DeleteDeliveryService deletes the given delivery service from the internal data. This MUST NOT be called by multiple goroutines.

func (*CRStatesThreadsafe) Get

func (t *CRStatesThreadsafe) Get() tc.CRStates

Get returns the internal Crstates object for reading.

func (*CRStatesThreadsafe) GetCache

func (t *CRStatesThreadsafe) GetCache(name tc.CacheName) (available tc.IsAvailable, ok bool)

GetCache returns the availability data of the given cache. This does not mutate, and is thus safe for multiple goroutines to call.

func (*CRStatesThreadsafe) GetCaches

func (t *CRStatesThreadsafe) GetCaches() map[tc.CacheName]tc.IsAvailable

GetCaches returns the availability data of all caches. This does not mutate, and is thus safe for multiple goroutines to call.

func (*CRStatesThreadsafe) GetDeliveryService

func (t *CRStatesThreadsafe) GetDeliveryService(name tc.DeliveryServiceName) (ds tc.CRStatesDeliveryService, ok bool)

GetDeliveryService returns the availability data of the given delivery service. This does not mutate, and is thus safe for multiple goroutines to call.

func (*CRStatesThreadsafe) GetDeliveryServices

func (t *CRStatesThreadsafe) GetDeliveryServices() map[tc.DeliveryServiceName]tc.CRStatesDeliveryService

GetDeliveryServices returns the internal Crstates delivery services map for reading.

func (*CRStatesThreadsafe) SetCache

func (t *CRStatesThreadsafe) SetCache(cacheName tc.CacheName, available tc.IsAvailable)

SetCache sets the internal availability data for a particular cache. It does NOT set data if the cache doesn't already exist. By adding newly received caches with `AddCache`, this allows easily avoiding a race condition when an in-flight poller tries to set a cache which has been removed.

func (*CRStatesThreadsafe) SetDeliveryService

func (t *CRStatesThreadsafe) SetDeliveryService(name tc.DeliveryServiceName, ds tc.CRStatesDeliveryService)

SetDeliveryService sets the availability data for the given delivery service.

type Handler

type Handler struct {
	ResultChannel chan Result
}

Handler handles peer Traffic Monitor data, taking a raw reader, parsing the data, and passing a result object to the ResultChannel. This fulfills the common `Handler` interface.

func NewHandler

func NewHandler() Handler

NewHandler returns a new peer Handler.

func (Handler) Handle

func (handler Handler) Handle(id string, r io.Reader, format string, reqTime time.Duration, reqEnd time.Time, err error, pollID uint64, usingIPv4 bool, pollCtx interface{}, pollFinished chan<- uint64)

Handle handles a response from a polled Traffic Monitor peer, parsing the data and forwarding it to the ResultChannel.

type Result

type Result struct {
	ID           tc.TrafficMonitorName
	Available    bool
	Errors       []error
	PeerStates   tc.CRStates
	PollID       uint64
	PollFinished chan<- uint64
	Time         time.Time
}

Result contains the data parsed from polling a peer Traffic Monitor.

Jump to

Keyboard shortcuts

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