selector

package
v0.0.0-...-f59cc51 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAvailable = errors.New("no_available_node")

ErrNoAvailable is no available node.

Functions

This section is empty.

Types

type Balancer

type Balancer interface {
	Pick(ctx context.Context, nodes []WeightedNode) (selected WeightedNode, done DoneFunc, err error)
}

Balancer is balancer interface

type Default

type Default struct {
	NodeBuilder WeightedNodeBuilder
	Balancer    Balancer
	Filters     []Filter
	// contains filtered or unexported fields
}

Default is composite selector.

func (*Default) Apply

func (d *Default) Apply(nodes []Node)

Apply update nodes info.

func (*Default) Select

func (d *Default) Select(ctx context.Context, opts ...SelectOption) (selected Node, done DoneFunc, err error)

Select select one node.

type DoneFunc

type DoneFunc func(ctx context.Context, di DoneInfo)

DoneFunc is callback function when RPC invoke done.

type DoneInfo

type DoneInfo struct {
	// Response Error
	Err error
	// Response Metadata
	ReplyMeta ReplyMeta

	// 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
}

DoneInfo is callback info when RPC invoke done.

type Filter

type Filter func(context.Context, []Node) []Node

Filter is node filter function.

type Node

type Node interface {
	// Address is the unique address under the same service
	Address() string

	// ServiceName is service name
	ServiceName() string

	// InitialWeight is the initial value of scheduling weight
	// if not set return nil
	InitialWeight() *int64

	// Version is service node version
	Version() string

	// Metadata is the kv pair metadata associated with the service instance.
	// version,namespace,region,protocol etc..
	Metadata() map[string]interface{}

	GetAttr() *attributes.Attributes
}

Node is node interface.

type Rebalancer

type Rebalancer interface {
	// apply all nodes when any changes happen
	Apply(nodes []Node)
}

Rebalancer is nodes rebalancer.

type ReplyMeta

type ReplyMeta interface {
	Get(key string) string
}

ReplyMeta is Reply Metadata.

type SelectOption

type SelectOption func(*SelectOptions)

SelectOption is Selector option.

func WithFilter

func WithFilter(fn ...Filter) SelectOption

WithFilter with filter options

type SelectOptions

type SelectOptions struct {
	Filters []Filter
}

SelectOptions is Select Options.

type Selector

type Selector interface {
	Rebalancer

	// Select nodes
	// if err == nil, selected and done must not be empty.
	Select(ctx context.Context, opts ...SelectOption) (selected Node, done DoneFunc, err error)
}

Selector is node pick balancer.

type WeightedNode

type WeightedNode interface {
	Node

	// Weight is the runtime calculated weight
	Weight() float64

	// Pick the node
	Pick() DoneFunc

	// PickElapsed is time elapsed since the latest pick
	PickElapsed() time.Duration
}

WeightedNode calculates scheduling weight in real time

type WeightedNodeBuilder

type WeightedNodeBuilder interface {
	Build(Node) WeightedNode
}

WeightedNodeBuilder is WeightedNode Builder

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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