bump google.golang.org/grpc v1.20.1
full diff: https://github.com/grpc/grpc-go/compare/v1.12.2...v1.20.1 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
		
							
								
								
									
										128
									
								
								vendor/google.golang.org/grpc/balancer/balancer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										128
									
								
								vendor/google.golang.org/grpc/balancer/balancer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -21,13 +21,15 @@
 | 
			
		||||
package balancer
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"net"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/net/context"
 | 
			
		||||
	"google.golang.org/grpc/connectivity"
 | 
			
		||||
	"google.golang.org/grpc/credentials"
 | 
			
		||||
	"google.golang.org/grpc/internal"
 | 
			
		||||
	"google.golang.org/grpc/metadata"
 | 
			
		||||
	"google.golang.org/grpc/resolver"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -46,8 +48,20 @@ func Register(b Builder) {
 | 
			
		||||
	m[strings.ToLower(b.Name())] = b
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// unregisterForTesting deletes the balancer with the given name from the
 | 
			
		||||
// balancer map.
 | 
			
		||||
//
 | 
			
		||||
// This function is not thread-safe.
 | 
			
		||||
func unregisterForTesting(name string) {
 | 
			
		||||
	delete(m, name)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	internal.BalancerUnregister = unregisterForTesting
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Get returns the resolver builder registered with the given name.
 | 
			
		||||
// Note that the compare is done in a case-insenstive fashion.
 | 
			
		||||
// Note that the compare is done in a case-insensitive fashion.
 | 
			
		||||
// If no builder is register with the name, nil will be returned.
 | 
			
		||||
func Get(name string) Builder {
 | 
			
		||||
	if b, ok := m[strings.ToLower(name)]; ok {
 | 
			
		||||
@@ -88,7 +102,15 @@ type SubConn interface {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewSubConnOptions contains options to create new SubConn.
 | 
			
		||||
type NewSubConnOptions struct{}
 | 
			
		||||
type NewSubConnOptions struct {
 | 
			
		||||
	// CredsBundle is the credentials bundle that will be used in the created
 | 
			
		||||
	// SubConn. If it's nil, the original creds from grpc DialOptions will be
 | 
			
		||||
	// used.
 | 
			
		||||
	CredsBundle credentials.Bundle
 | 
			
		||||
	// HealthCheckEnabled indicates whether health check service should be
 | 
			
		||||
	// enabled on this SubConn
 | 
			
		||||
	HealthCheckEnabled bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ClientConn represents a gRPC ClientConn.
 | 
			
		||||
//
 | 
			
		||||
@@ -105,7 +127,7 @@ type ClientConn interface {
 | 
			
		||||
	// The SubConn will be shutdown.
 | 
			
		||||
	RemoveSubConn(SubConn)
 | 
			
		||||
 | 
			
		||||
	// UpdateBalancerState is called by balancer to nofity gRPC that some internal
 | 
			
		||||
	// UpdateBalancerState is called by balancer to notify gRPC that some internal
 | 
			
		||||
	// state in balancer has changed.
 | 
			
		||||
	//
 | 
			
		||||
	// gRPC will update the connectivity state of the ClientConn, and will call pick
 | 
			
		||||
@@ -125,6 +147,8 @@ type BuildOptions struct {
 | 
			
		||||
	// use to dial to a remote load balancer server. The Balancer implementations
 | 
			
		||||
	// can ignore this if it does not need to talk to another party securely.
 | 
			
		||||
	DialCreds credentials.TransportCredentials
 | 
			
		||||
	// CredsBundle is the credentials bundle that the Balancer can use.
 | 
			
		||||
	CredsBundle credentials.Bundle
 | 
			
		||||
	// Dialer is the custom dialer the Balancer implementation can use to dial
 | 
			
		||||
	// to a remote load balancer server. The Balancer implementations
 | 
			
		||||
	// can ignore this if it doesn't need to talk to remote balancer.
 | 
			
		||||
@@ -143,16 +167,27 @@ type Builder interface {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// PickOptions contains addition information for the Pick operation.
 | 
			
		||||
type PickOptions struct{}
 | 
			
		||||
type PickOptions struct {
 | 
			
		||||
	// FullMethodName is the method name that NewClientStream() is called
 | 
			
		||||
	// with. The canonical format is /service/Method.
 | 
			
		||||
	FullMethodName string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DoneInfo contains additional information for done.
 | 
			
		||||
type DoneInfo struct {
 | 
			
		||||
	// Err is the rpc error the RPC finished with. It could be nil.
 | 
			
		||||
	Err error
 | 
			
		||||
	// Trailer contains the metadata from the RPC's trailer, if present.
 | 
			
		||||
	Trailer metadata.MD
 | 
			
		||||
	// BytesSent indicates if any bytes have been sent to the server.
 | 
			
		||||
	BytesSent bool
 | 
			
		||||
	// BytesReceived indicates if any byte has been received from the server.
 | 
			
		||||
	BytesReceived bool
 | 
			
		||||
	// ServerLoad is the load received from server. It's usually sent as part of
 | 
			
		||||
	// trailing metadata.
 | 
			
		||||
	//
 | 
			
		||||
	// The only supported type now is *orca_v1.LoadReport.
 | 
			
		||||
	ServerLoad interface{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
@@ -182,8 +217,10 @@ type Picker interface {
 | 
			
		||||
	//
 | 
			
		||||
	// If a SubConn is returned:
 | 
			
		||||
	// - If it is READY, gRPC will send the RPC on it;
 | 
			
		||||
	// - If it is not ready, or becomes not ready after it's returned, gRPC will block
 | 
			
		||||
	//   until UpdateBalancerState() is called and will call pick on the new picker.
 | 
			
		||||
	// - If it is not ready, or becomes not ready after it's returned, gRPC will
 | 
			
		||||
	//   block until UpdateBalancerState() is called and will call pick on the
 | 
			
		||||
	//   new picker. The done function returned from Pick(), if not nil, will be
 | 
			
		||||
	//   called with nil error, no bytes sent and no bytes received.
 | 
			
		||||
	//
 | 
			
		||||
	// If the returned error is not nil:
 | 
			
		||||
	// - If the error is ErrNoSubConnAvailable, gRPC will block until UpdateBalancerState()
 | 
			
		||||
@@ -194,9 +231,10 @@ type Picker interface {
 | 
			
		||||
	// - Else (error is other non-nil error):
 | 
			
		||||
	//   - The RPC will fail with unavailable error.
 | 
			
		||||
	//
 | 
			
		||||
	// The returned done() function will be called once the rpc has finished, with the
 | 
			
		||||
	// final status of that RPC.
 | 
			
		||||
	// done may be nil if balancer doesn't care about the RPC status.
 | 
			
		||||
	// The returned done() function will be called once the rpc has finished,
 | 
			
		||||
	// with the final status of that RPC.  If the SubConn returned is not a
 | 
			
		||||
	// valid SubConn type, done may not be called.  done may be nil if balancer
 | 
			
		||||
	// doesn't care about the RPC status.
 | 
			
		||||
	Pick(ctx context.Context, opts PickOptions) (conn SubConn, done func(DoneInfo), err error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -215,14 +253,84 @@ type Balancer interface {
 | 
			
		||||
	// that back to gRPC.
 | 
			
		||||
	// Balancer should also generate and update Pickers when its internal state has
 | 
			
		||||
	// been changed by the new state.
 | 
			
		||||
	//
 | 
			
		||||
	// Deprecated: if V2Balancer is implemented by the Balancer,
 | 
			
		||||
	// UpdateSubConnState will be called instead.
 | 
			
		||||
	HandleSubConnStateChange(sc SubConn, state connectivity.State)
 | 
			
		||||
	// HandleResolvedAddrs is called by gRPC to send updated resolved addresses to
 | 
			
		||||
	// balancers.
 | 
			
		||||
	// Balancer can create new SubConn or remove SubConn with the addresses.
 | 
			
		||||
	// An empty address slice and a non-nil error will be passed if the resolver returns
 | 
			
		||||
	// non-nil error to gRPC.
 | 
			
		||||
	//
 | 
			
		||||
	// Deprecated: if V2Balancer is implemented by the Balancer,
 | 
			
		||||
	// UpdateResolverState will be called instead.
 | 
			
		||||
	HandleResolvedAddrs([]resolver.Address, error)
 | 
			
		||||
	// Close closes the balancer. The balancer is not required to call
 | 
			
		||||
	// ClientConn.RemoveSubConn for its existing SubConns.
 | 
			
		||||
	Close()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SubConnState describes the state of a SubConn.
 | 
			
		||||
type SubConnState struct {
 | 
			
		||||
	ConnectivityState connectivity.State
 | 
			
		||||
	// TODO: add last connection error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// V2Balancer is defined for documentation purposes.  If a Balancer also
 | 
			
		||||
// implements V2Balancer, its UpdateResolverState method will be called instead
 | 
			
		||||
// of HandleResolvedAddrs and its UpdateSubConnState will be called instead of
 | 
			
		||||
// HandleSubConnStateChange.
 | 
			
		||||
type V2Balancer interface {
 | 
			
		||||
	// UpdateResolverState is called by gRPC when the state of the resolver
 | 
			
		||||
	// changes.
 | 
			
		||||
	UpdateResolverState(resolver.State)
 | 
			
		||||
	// UpdateSubConnState is called by gRPC when the state of a SubConn
 | 
			
		||||
	// changes.
 | 
			
		||||
	UpdateSubConnState(SubConn, SubConnState)
 | 
			
		||||
	// Close closes the balancer. The balancer is not required to call
 | 
			
		||||
	// ClientConn.RemoveSubConn for its existing SubConns.
 | 
			
		||||
	Close()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ConnectivityStateEvaluator takes the connectivity states of multiple SubConns
 | 
			
		||||
// and returns one aggregated connectivity state.
 | 
			
		||||
//
 | 
			
		||||
// It's not thread safe.
 | 
			
		||||
type ConnectivityStateEvaluator struct {
 | 
			
		||||
	numReady            uint64 // Number of addrConns in ready state.
 | 
			
		||||
	numConnecting       uint64 // Number of addrConns in connecting state.
 | 
			
		||||
	numTransientFailure uint64 // Number of addrConns in transientFailure.
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RecordTransition records state change happening in subConn and based on that
 | 
			
		||||
// it evaluates what aggregated state should be.
 | 
			
		||||
//
 | 
			
		||||
//  - If at least one SubConn in Ready, the aggregated state is Ready;
 | 
			
		||||
//  - Else if at least one SubConn in Connecting, the aggregated state is Connecting;
 | 
			
		||||
//  - Else the aggregated state is TransientFailure.
 | 
			
		||||
//
 | 
			
		||||
// Idle and Shutdown are not considered.
 | 
			
		||||
func (cse *ConnectivityStateEvaluator) RecordTransition(oldState, newState connectivity.State) connectivity.State {
 | 
			
		||||
	// Update counters.
 | 
			
		||||
	for idx, state := range []connectivity.State{oldState, newState} {
 | 
			
		||||
		updateVal := 2*uint64(idx) - 1 // -1 for oldState and +1 for new.
 | 
			
		||||
		switch state {
 | 
			
		||||
		case connectivity.Ready:
 | 
			
		||||
			cse.numReady += updateVal
 | 
			
		||||
		case connectivity.Connecting:
 | 
			
		||||
			cse.numConnecting += updateVal
 | 
			
		||||
		case connectivity.TransientFailure:
 | 
			
		||||
			cse.numTransientFailure += updateVal
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Evaluate.
 | 
			
		||||
	if cse.numReady > 0 {
 | 
			
		||||
		return connectivity.Ready
 | 
			
		||||
	}
 | 
			
		||||
	if cse.numConnecting > 0 {
 | 
			
		||||
		return connectivity.Connecting
 | 
			
		||||
	}
 | 
			
		||||
	return connectivity.TransientFailure
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user