balancer

package
Version: v3.2.0-rc.1.0...-6143c13 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package balancer implements client balancer.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAddrAvilable = status.Error(codes.Unavailable, "there is no address available")

ErrNoAddrAvilable is returned by Get() when the balancer does not have any active connection to endpoints at the time. This error is returned only when opts.BlockingWait is true.

Functions

func RegisterBuilder

func RegisterBuilder(cfg Config)

RegisterBuilder creates and registers a builder. Since this function calls balancer.Register, it must be invoked at initialization time.

Types

type Balancer

type Balancer interface {
	// Balancer is called on specified client connection. Client initiates gRPC
	// connection with "grpc.Dial(addr, grpc.WithBalancerName)", and then those resolved
	// addresses are passed to "grpc/balancer.Balancer.HandleResolvedAddrs".
	// For each resolved address, balancer calls "balancer.ClientConn.NewSubConn".
	// "grpc/balancer.Balancer.HandleSubConnStateChange" is called when connectivity state
	// changes, thus requires failover logic in this method.
	balancer.Balancer

	// Picker calls "Pick" for every client request.
	picker.Picker
}

Balancer defines client balancer interface.

type Config

type Config struct {
	// Policy configures balancer policy.
	Policy picker.Policy

	// Name defines an additional name for balancer.
	// Useful for balancer testing to avoid register conflicts.
	// If empty, defaults to policy name.
	Name string

	// Logger configures balancer logging.
	// If nil, logs are discarded.
	Logger *zap.Logger
}

Config defines balancer configurations.

type DialFunc

type DialFunc func(ep string, dopts ...grpc.DialOption) (*grpc.ClientConn, error)

DialFunc defines gRPC dial function.

type GRPC17Health

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

GRPC17Health does the bare minimum to expose multiple eps to the grpc reconnection code path

func NewGRPC17Health

func NewGRPC17Health(
	eps []string,
	timeout time.Duration,
	dialFunc DialFunc,
) *GRPC17Health

NewGRPC17Health returns a new health balancer with gRPC v1.7.

func (*GRPC17Health) Close

func (b *GRPC17Health) Close() error

func (*GRPC17Health) ConnectNotify

func (b *GRPC17Health) ConnectNotify() <-chan struct{}

func (*GRPC17Health) Endpoint

func (b *GRPC17Health) Endpoint(hostPort string) string

func (*GRPC17Health) Get

func (b *GRPC17Health) Get(ctx context.Context, opts grpc.BalancerGetOptions) (grpc.Address, func(), error)

func (*GRPC17Health) HostPortError

func (b *GRPC17Health) HostPortError(hostPort string, err error)

func (*GRPC17Health) NeedUpdate

func (b *GRPC17Health) NeedUpdate() bool

NeedUpdate returns true if all connections are down or addresses do not include current pinned address.

func (*GRPC17Health) Next

func (b *GRPC17Health) Next()

func (*GRPC17Health) Notify

func (b *GRPC17Health) Notify() <-chan []grpc.Address

func (*GRPC17Health) Pinned

func (b *GRPC17Health) Pinned() string

func (*GRPC17Health) Ready

func (b *GRPC17Health) Ready() <-chan struct{}

func (*GRPC17Health) Start

func (b *GRPC17Health) Start(target string, config grpc.BalancerConfig) error

func (*GRPC17Health) StopC

func (b *GRPC17Health) StopC() chan struct{}

func (*GRPC17Health) Up

func (b *GRPC17Health) Up(addr grpc.Address) func(error)

func (*GRPC17Health) UpdateAddrs

func (b *GRPC17Health) UpdateAddrs(eps ...string)

func (*GRPC17Health) UpdateAddrsC

func (b *GRPC17Health) UpdateAddrsC() chan NotifyMsg

type NotifyMsg

type NotifyMsg int
const (
	NotifyReset NotifyMsg = iota
	NotifyNext
)

Directories

Path Synopsis
Package picker defines/implements client balancer picker policy.
Package picker defines/implements client balancer picker policy.
resolver
endpoint
Package endpoint resolves etcd entpoints using grpc targets of the form 'endpoint://<id>/<endpoint>'.
Package endpoint resolves etcd entpoints using grpc targets of the form 'endpoint://<id>/<endpoint>'.

Jump to

Keyboard shortcuts

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