resolver

package
v1.2.19 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadResolverState = errors.New("bad resolver state")

ErrBadResolverState may be returned by UpdateState to indicate a problem with the provided name resolver data.

View Source
var (
	// ErrNoAddrAvailable indicates no Addr is available for pick().
	ErrNoAddrAvailable = errors.New("no Addr is available")
)

Functions

func GetDefaultScheme

func GetDefaultScheme() string

GetDefaultScheme gets the default scheme that will be used.

func NewRoundRobinPicker

func NewRoundRobinPicker(next int) *rrPicker

func Register

func Register(driver Builder)

Register makes a database driver available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.

func ResolveNow

func ResolveNow(ctx context.Context, target string, opts ...ResolveNowOption) error

func Resolvers

func Resolvers() []string

Resolvers returns a sorted list of the names of the registered resolvers.

func SetDefaultScheme

func SetDefaultScheme(scheme string)

SetDefaultScheme sets the default scheme that will be used. The default default scheme is "passthrough".

NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. The scheme set last overrides previously set values.

Types

type Address

type Address struct {
	// Addr is the server address on which a connection will be established.
	Addr string
}

Address represents a server the client connects to.

func PickFirst

func PickFirst(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error)

func ResolveAddr

func ResolveAddr(ctx context.Context, target string, opts ...ResolveAddrOption) ([]Address, error)

func ResolveOneAddr

func ResolveOneAddr(ctx context.Context, target string, opts ...ResolveOneAddrOption) (Address, error)

type Build

type Build struct {
	ClientConn ClientConn
}

Build includes additional information for the builder to create the resolver.

func (*Build) ApplyOptions

func (o *Build) ApplyOptions(options ...BuildOption) *Build

type BuildOption

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

A BuildOption sets options.

func BuildWithClientConn

func BuildWithClientConn(cc ClientConn) BuildOption

BuildWithClientConn append cc to Build

type BuildOptionFunc

type BuildOptionFunc func(*Build)

BuildOptionFunc wraps a function that modifies Build into an implementation of the BuildOption interface.

type Builder

type Builder interface {
	// Build creates a new resolver for the given target.
	//
	// gRPC dial calls Build synchronously, and fails if the returned error is
	// not nil.
	Build(ctx context.Context, target Target, opts ...BuildOption) (Resolver, error)

	// Scheme returns the scheme supported by this resolver.
	// Scheme is defined at https://github.com/grpc/grpc/blob/master/doc/naming.md.
	Scheme() string
}

Builder is the interface that must be implemented by a database driver.

Database drivers may implement DriverContext for access to contexts and to parse the name only once for a pool of connections, instead of once per connection.

func Get

func Get(scheme string) Builder

Get returns the resolver builder registered with the given scheme.

If no builder is register with the scheme, nil will be returned.

func GetBuilderOrDefault

func GetBuilderOrDefault(target string) (Builder, error)

type ClientConn

type ClientConn interface {
	// UpdateState updates the state of the ClientConn appropriately.
	UpdateState(State) error
	// ReportError notifies the ClientConn that the Resolver encountered an
	// error.  The ClientConn will notify the load balancer and begin calling
	// ResolveNow on the Resolver with exponential backoff.
	ReportError(error)
}

ClientConn contains the callbacks for resolver to notify any updates to the gRPC ClientConn.

This interface is to be implemented by gRPC. Users should not need a brand new implementation of this interface. For the situations like testing, the new implementation should embed this interface. This allows gRPC to add new methods to this interface.

type EmptyBuildOption

type EmptyBuildOption struct{}

EmptyBuildOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type EmptyPickOption

type EmptyPickOption struct{}

EmptyPickOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type EmptyResolveAddrOption

type EmptyResolveAddrOption struct{}

EmptyResolveAddrOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type EmptyResolveNowOption

type EmptyResolveNowOption struct{}

EmptyResolveNowOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type EmptyResolveOneAddrOption

type EmptyResolveOneAddrOption struct{}

EmptyResolveOneAddrOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type Pick

type Pick struct{}

Pick includes additional information for Pick.

func (*Pick) ApplyOptions

func (o *Pick) ApplyOptions(options ...PickOption) *Pick

type PickOption

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

A PickOption sets options.

type PickOptionFunc

type PickOptionFunc func(*Pick)

PickOptionFunc wraps a function that modifies Pick into an implementation of the PickOption interface.

type Picker

type Picker interface {
	Pick(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error)
}

Picker is used to pick an Address.

func NewErrPicker

func NewErrPicker(err error) Picker

NewErrPicker returns a Picker that always returns err on Pick().

type PickerFunc

type PickerFunc func(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error)

The PickerFunc type is an adapter to allow the use of ordinary functions as Picker handlers. If f is a function with the appropriate signature, PickerFunc(f) is a Handler that calls f.

func (PickerFunc) Pick

func (f PickerFunc) Pick(ctx context.Context, addrs []Address, opts ...PickOption) (Address, error)

Pick calls f(ctx, addrs, opts...).

type ResolveAddrOption

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

A ResolveAddrOption sets options.

type ResolveAddrOptionFunc

type ResolveAddrOptionFunc func(*resolveAddr)

ResolveAddrOptionFunc wraps a function that modifies resolveAddr into an implementation of the ResolveAddrOption interface.

type ResolveNowOption

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

A ResolveNowOption sets options.

type ResolveNowOptionFunc

type ResolveNowOptionFunc func(*resolveNow)

ResolveNowOptionFunc wraps a function that modifies resolveNow into an implementation of the ResolveNowOption interface.

type ResolveOneAddrOption

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

A ResolveOneAddrOption sets options.

func ResolveOneAddrOptionWithPickerOption

func ResolveOneAddrOptionWithPickerOption(opts ...PickOption) ResolveOneAddrOption

ResolveOneAddrOptionWithPickerOption append PickOption to picker

type ResolveOneAddrOptionFunc

type ResolveOneAddrOptionFunc func(*resolveOneAddr)

ResolveOneAddrOptionFunc wraps a function that modifies resolveOneAddr into an implementation of the ResolveOneAddrOption interface.

type Resolver

type Resolver interface {
	// ResolveOneAddr will be called to try to resolve the target name directly.
	// resolver can not ignore this if it's not necessary.
	// ResolveOneAddr may trigger and wait for ResolveNow if no addr in resolver cache
	ResolveOneAddr(ctx context.Context, opts ...ResolveOneAddrOption) (Address, error)
	// ResolveAddr will be called to try to resolve the target name directly.
	// resolver can not ignore this if it's not necessary.
	// ResolveAddr may trigger and wait for ResolveNow if no addr in resolver cache
	ResolveAddr(ctx context.Context, opts ...ResolveAddrOption) ([]Address, error)
	// ResolveNow will be called to try to resolve the target name
	// again. It's just a hint, resolver can ignore this if it's not necessary.
	//
	// It could be called multiple times concurrently.
	// It may trigger ClientConn to UpdateState or ReportError if failed.
	// It may update cache used by ResolveOneAddr or ResolveAddr.
	ResolveNow(ctx context.Context, opts ...ResolveNowOption)
	// Close closes the resolver.
	Close()
}

Resolver watches for the updates on the specified target. Updates include address updates and service config updates.

func NewResolver

func NewResolver(ctx context.Context, target string, opts ...BuildOption) (Resolver, error)

type State

type State struct {
	// Addresses is the latest set of resolved addresses for the target.
	Addresses []Address
}

State contains the current Resolver state relevant to the ClientConn.

type Target

type Target struct {
	Scheme    string
	Authority string
	Endpoint  string
}

Target represents a target for gRPC, as specified in: https://github.com/grpc/grpc/blob/master/doc/naming.md. It is parsed from the target string that gets passed into Dial or DialContext by the user. And grpc passes it to the resolver and the balancer.

If the target follows the naming spec, and the parsed scheme is registered with grpc, we will parse the target string according to the spec. e.g. "dns://some_authority/foo.bar" will be parsed into &Target{Scheme: "dns", Authority: "some_authority", Endpoint: "foo.bar"}

If the target does not contain a scheme, we will apply the default scheme, and set the Target to be the full target string. e.g. "foo.bar" will be parsed into &Target{Scheme: resolver.GetDefaultScheme(), Endpoint: "foo.bar"}.

If the parsed scheme is not registered (i.e. no corresponding resolver available to resolve the endpoint), we set the Scheme to be the default scheme, and set the Endpoint to be the full target string. e.g. target string "unknown_scheme://authority/endpoint" will be parsed into &Target{Scheme: resolver.GetDefaultScheme(), Endpoint: "unknown_scheme://authority/endpoint"}.

func ParseTarget

func ParseTarget(target string, skipUnixColonParsing bool) (ret Target)

ParseTarget splits target into a Target struct containing scheme, authority and endpoint. skipUnixColonParsing indicates that the parse should not parse "unix:path" cases. This should be true in cases where a custom dialer is present, to prevent a behavior change.

If target is not a valid scheme://authority/endpoint as specified in https://github.com/grpc/grpc/blob/master/doc/naming.md, it returns {Endpoint: target}. Code borrowed from https://github.com/grpc/grpc-go/blob/master/internal/grpcutil/target.go

Directories

Path Synopsis
Package unix implements a resolver for unix targets.
Package unix implements a resolver for unix targets.

Jump to

Keyboard shortcuts

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