balancer

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Policy defines the name or identifier for the consistent hashing load balancing policy.
	Policy = "consistenthashpolicy"

	// Key is the context key used to retrieve the hash key for consistent hashing.
	Key = "consistenthashkey"

	// ConnectionLifetime specifies the duration for which a connection is maintained
	// before being considered for termination or renewal.
	ConnectionLifetime = time.Second * 5
)

Variables

View Source
var (
	// ErrSubConnMissing indicates that a SubConn (sub-connection) was expected but not found.
	ErrSubConnMissing = fmt.Errorf("sub-connection is missing or not found")
	// ErrSubConnResetFailure indicates an error occurred while trying to reset the SubConn.
	ErrSubConnResetFailure = fmt.Errorf("failed to reset the sub-connection")
)

Functions

func NewConsistentHashBalancerBuilder

func NewConsistentHashBalancerBuilder() balancer.Builder

NewConsistentHashBalancerBuilder returns a consistentHashBalancerBuilder.

Types

type ConsistentHashPicker

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

ConsistentHashPicker is a custom gRPC picker that uses consistent hashing to determine which backend server should handle the request.

func NewConsistentHashPicker

func NewConsistentHashPicker(subConns map[string]balancer.SubConn) *ConsistentHashPicker

NewConsistentHashPicker initializes and returns a new ConsistentHashPicker. It creates a hash ring from the provided set of backend server addresses.

func (*ConsistentHashPicker) Pick

Pick selects an appropriate backend server (SubConn) for the incoming request. If a custom key is provided in the context, it will be used for consistent hashing; otherwise, the full method name of the request will be used.

type PickResult

type PickResult struct {
	Ctx context.Context
	SC  balancer.SubConn
}

PickResult represents the result of a pick operation. It contains the context and the selected SubConn for the request.

type Queue

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

Queue is a basic FIFO queue based on a doubly linked list.

func NewQueue

func NewQueue() *Queue

NewQueue returns a new queue.

func (*Queue) DeQueue

func (q *Queue) DeQueue() (interface{}, bool)

DeQueue removes and returns the first item in the queue.

func (*Queue) EnQueue

func (q *Queue) EnQueue(value interface{})

EnQueue adds an item to the end of the queue.

func (*Queue) IsEmpty

func (q *Queue) IsEmpty() bool

IsEmpty returns true if the queue is empty.

func (*Queue) Len

func (q *Queue) Len() int

Len returns the number of items in the queue.

Jump to

Keyboard shortcuts

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