Documentation ¶
Index ¶
Constants ¶
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 ¶
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 ¶
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 ¶
func (p *ConsistentHashPicker) Pick(info balancer.PickInfo) (balancer.PickResult, error)
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 ¶
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.