peerlist

package
v1.32.4 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package peerlist is deprecated in favor of `go.uber.org/yarpc/peer/peerlist/v2` which can additionally convey peer list identifiers to the peerlist.Implementation without a wrapper type, allowing a peer list updater to communicate shard information for example.

Package peerlist provides a utility for managing peer availability with a separate implementation of peer selection from just among available peers. The peer list implements the peer.ChooserList interface and accepts a peer.ListImplementation to provide the implementation-specific concern of, for example, a *roundrobin.List.

The example is an implementation of peer.ChooserList using a random peer selection strategy, returned by newRandomListImplementation(), implementing peer.ListImplementation.

type List struct {
	*peerlist.List
}

func New(transport peer.Transport) *List {
	return &List{
		List: peerlist.New(
			"random",
			transport,
			newRandomListImplementation(),
		),
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

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

List is an abstract peer list, backed by a peer.ListImplementation to determine which peer to choose among available peers. The abstract list manages available versus unavailable peers, intercepting these notifications from the transport's concrete implementation of peer.Peer with the peer.Subscriber API. The peer list will not choose an unavailable peer, prefering to block until one becomes available.

The list is a suitable basis for concrete implementations like round-robin.

func New

func New(name string, transport peer.Transport, availableChooser peer.ListImplementation, opts ...ListOption) *List

New creates a new peer list with an identifier chooser for available peers.

func (*List) Available

func (pl *List) Available(p peer.Identifier) bool

Available returns whether the identifier peer is available for traffic.

func (*List) Choose

func (pl *List) Choose(ctx context.Context, req *transport.Request) (peer.Peer, func(error), error)

Choose selects the next available peer in the peer list

func (*List) Introspect

func (pl *List) Introspect() introspection.ChooserStatus

Introspect returns a ChooserStatus with a summary of the Peers.

func (*List) IsRunning

func (pl *List) IsRunning() bool

IsRunning returns whether the peer list is running.

func (*List) NotifyStatusChanged

func (pl *List) NotifyStatusChanged(pid peer.Identifier)

NotifyStatusChanged receives status change notifications for peers in the list.

func (*List) NumAvailable

func (pl *List) NumAvailable() int

NumAvailable returns how many peers are available.

func (*List) NumUnavailable

func (pl *List) NumUnavailable() int

NumUnavailable returns how many peers are unavailable.

func (*List) NumUninitialized

func (pl *List) NumUninitialized() int

NumUninitialized returns how many peers are unavailable.

func (*List) Peers

func (pl *List) Peers() []peer.Peer

Peers returns a snapshot of all retained (available and unavailable) peers.

func (*List) Start

func (pl *List) Start() error

Start notifies the List that requests will start coming

func (*List) Stop

func (pl *List) Stop() error

Stop notifies the List that requests will stop coming

func (*List) Uninitialized

func (pl *List) Uninitialized(p peer.Identifier) bool

Uninitialized returns whether a peer is waiting for the peer list to start.

func (*List) Update

func (pl *List) Update(updates peer.ListUpdates) error

Update applies the additions and removals of peer Identifiers to the list it returns a multi-error result of every failure that happened without circuit breaking due to failures.

type ListOption

type ListOption interface {
	// contains filtered or unexported methods
}

ListOption customizes the behavior of a list.

func Capacity

func Capacity(capacity int) ListOption

Capacity specifies the default capacity of the underlying data structures for this list

Defaults to 10.

func NoShuffle added in v1.28.0

func NoShuffle() ListOption

NoShuffle disables the default behavior of shuffling peerlist order.

func Seed added in v1.28.0

func Seed(seed int64) ListOption

Seed specifies the random seed to use for shuffling peers

Defaults to approximately the process start time in nanoseconds.

Directories

Path Synopsis
Package peerlist provides a utility for managing peer availability with a separate implementation of peer selection from just among available peers.
Package peerlist provides a utility for managing peer availability with a separate implementation of peer selection from just among available peers.

Jump to

Keyboard shortcuts

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