ConsistentHash_trpcgo

package
v0.0.0-...-156932d Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoServerAvailable = errors.New("no server available")
	ErrInvalidKey        = errors.New("invalid key")
	ErrInvalidNodeList   = errors.New("node list contains nil node")
)

Functions

This section is empty.

Types

type ConsistentHash

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

ConsistentHash defines the consistent hash.

func NewConsistentHash

func NewConsistentHash() *ConsistentHash

NewConsistentHash creates a new ConsistentHash.

func (*ConsistentHash) Select

func (ch *ConsistentHash) Select(serviceName string, list []*Node, key string, opt ...Option) (*Node, error)

Select implements loadbalance.LoadBalancer.

type Hash

type Hash func(data []byte) uint32

Hash is the hash function type.

type Node

type Node struct {
	ServiceName   string        // 服务名
	ContainerName string        // 容器名
	Address       string        // 目标地址 ip:port
	Network       string        // 网络层协议 tcp/udp
	Protocol      string        // 业务协议 trpc/http
	SetName       string        // 节点Set名
	Weight        int           // 权重
	CostTime      time.Duration // 当次请求耗时
	EnvKey        string        // 透传的环境信息
	Metadata      map[string]interface{}
}

Node is the information of a node.

func (*Node) String

func (n *Node) String() string

String returns an abbreviation information of node.

type Option

type Option func(*Options)

Option modifies the Options.

func WithContext

func WithContext(ctx context.Context) Option

WithContext returns an Option which set request ctx.

func WithInterval

func WithInterval(interval time.Duration) Option

WithInterval returns an Option which set load balance refresh interval.

func WithLoadBalanceType

func WithLoadBalanceType(name string) Option

WithLoadBalanceType returns an Option which set load balance type.

func WithNamespace

func WithNamespace(namespace string) Option

WithNamespace returns an Option which set namespace.

func WithReplicas

func WithReplicas(r int) Option

WithReplicas returns an Option which set the virtual node coefficient.

type Options

type Options struct {
	Ctx             context.Context // request context
	Interval        time.Duration   // refresh interval
	Namespace       string          // namespace
	LoadBalanceType string          // load balance type
	Replicas        int             // virtual node coefficient of consistent hash
}

Options is the call options.

type UInt32Slice

type UInt32Slice []uint32

UInt32Slice defines uint32 slice.

func (UInt32Slice) Len

func (s UInt32Slice) Len() int

Len returns the length of the slice.

func (UInt32Slice) Less

func (s UInt32Slice) Less(i, j int) bool

Less returns whether the value at i is less than j.

func (UInt32Slice) Swap

func (s UInt32Slice) Swap(i, j int)

Swap swaps values between i and j.

Jump to

Keyboard shortcuts

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