Documentation ¶
Index ¶
- Variables
- func NewPeerContext(ctx context.Context, p *Peer) context.Context
- func SetGlobalSelector(builder Builder)
- type Balancer
- type BalancerBuilder
- type Builder
- type Default
- type DefaultBuilder
- type DefaultNode
- type DoneFunc
- type DoneInfo
- type Node
- type NodeFilter
- type Peer
- type Rebalancer
- type ReplyMD
- type SelectOption
- type SelectOptions
- type Selector
- type WeightedNode
- type WeightedNodeBuilder
Constants ¶
This section is empty.
Variables ¶
var ErrNoAvailable = errors.ServiceUnavailable("no_available_node", "")
ErrNoAvailable is no available node.
Functions ¶
func NewPeerContext ¶ added in v2.4.0
NewPeerContext creates a new context with peer information attached.
func SetGlobalSelector ¶ added in v2.5.0
func SetGlobalSelector(builder Builder)
SetGlobalSelector set global selector builder.
Types ¶
type Balancer ¶
type Balancer interface {
Pick(ctx context.Context, nodes []WeightedNode) (selected WeightedNode, done DoneFunc, err error)
}
Balancer is balancer interface
type BalancerBuilder ¶ added in v2.1.1
type BalancerBuilder interface {
Build() Balancer
}
BalancerBuilder build balancer
type Builder ¶ added in v2.1.1
type Builder interface {
Build() Selector
}
Builder build selector
func GlobalSelector ¶ added in v2.5.0
func GlobalSelector() Builder
GlobalSelector returns global selector builder.
type Default ¶
type Default struct { NodeBuilder WeightedNodeBuilder Balancer Balancer // contains filtered or unexported fields }
Default is composite selector.
type DefaultBuilder ¶ added in v2.1.1
type DefaultBuilder struct { Node WeightedNodeBuilder Balancer BalancerBuilder }
DefaultBuilder is de
func (*DefaultBuilder) Build ¶ added in v2.1.1
func (db *DefaultBuilder) Build() Selector
Build create builder
type DefaultNode ¶ added in v2.1.2
type DefaultNode struct {
// contains filtered or unexported fields
}
DefaultNode is selector node
func (*DefaultNode) Address ¶ added in v2.1.2
func (n *DefaultNode) Address() string
Address is node address
func (*DefaultNode) InitialWeight ¶ added in v2.1.2
func (n *DefaultNode) InitialWeight() *int64
InitialWeight is node initialWeight
func (*DefaultNode) Metadata ¶ added in v2.1.2
func (n *DefaultNode) Metadata() map[string]string
Metadata is node metadata
func (*DefaultNode) Scheme ¶ added in v2.2.2
func (n *DefaultNode) Scheme() string
Scheme is node scheme
func (*DefaultNode) ServiceName ¶ added in v2.1.2
func (n *DefaultNode) ServiceName() string
ServiceName is node serviceName
func (*DefaultNode) Version ¶ added in v2.1.2
func (n *DefaultNode) Version() string
Version is node version
type DoneInfo ¶
type DoneInfo struct { // Response Error Err error // Response Metadata ReplyMD ReplyMD // 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 Node ¶
type Node interface { // Scheme is service node scheme Scheme() string // 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]string }
Node is node interface.
type NodeFilter ¶ added in v2.1.2
NodeFilter is select filter.
type Peer ¶ added in v2.4.0
type Peer struct { // node is the peer node. Node Node }
Peer contains the information of the peer for an RPC, such as the address and authentication information.
type Rebalancer ¶
type Rebalancer interface { // Apply is apply all nodes when any changes happen Apply(nodes []Node) }
Rebalancer is nodes rebalancer.
type SelectOption ¶
type SelectOption func(*SelectOptions)
SelectOption is Selector option.
func WithNodeFilter ¶ added in v2.1.2
func WithNodeFilter(fn ...NodeFilter) SelectOption
WithNodeFilter with filter options
type SelectOptions ¶
type SelectOptions struct {
NodeFilters []NodeFilter
}
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 // Raw returns the original node Raw() 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