balancer

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name = "consistenthashing"             // Name of the balancer.
	Key  = contextKey("consistenthashkey") // Key for the consistent hash.
)

Package-level constants for the balancer name and consistent hash key.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balancer added in v1.2.8

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

func (*Balancer) Close added in v1.2.8

func (b *Balancer) Close()

func (*Balancer) ExitIdle added in v1.4.3

func (b *Balancer) ExitIdle()

ExitIdle instructs the LB policy to reconnect to backends / exit the IDLE state, if appropriate and possible. Note that SubConns that enter the IDLE state will not reconnect until SubConn.Connect is called.

func (*Balancer) ResolverError added in v1.2.8

func (b *Balancer) ResolverError(err error)

func (*Balancer) UpdateClientConnState added in v1.2.8

func (b *Balancer) UpdateClientConnState(s balancer.ClientConnState) error

func (*Balancer) UpdateSubConnState added in v1.2.8

func (b *Balancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState)

type Builder added in v1.2.8

type Builder interface {
	balancer.Builder      // Interface for building balancers.
	balancer.ConfigParser // Interface for parsing balancer configurations.
}

Builder defines the interface for the consistent hashing balancer builder.

func NewBuilder added in v1.2.8

func NewBuilder(fn consistent.Hasher) Builder

NewBuilder initializes a new builder with the given hashing function.

type ClientConnWrapper added in v1.3.5

type ClientConnWrapper interface {
	// NewSubConn creates a new SubConn with the specified addresses and options.
	NewSubConn([]resolver.Address, balancer.NewSubConnOptions) (balancer.SubConn, error)
	// RemoveSubConn removes the specified SubConn.
	RemoveSubConn(balancer.SubConn)
	// UpdateAddresses updates the addresses for the specified SubConn.
	UpdateAddresses(balancer.SubConn, []resolver.Address)
	// UpdateState updates the overall connectivity state of the balancer.
	UpdateState(balancer.State)
	// ResolveNow triggers an immediate resolution of the target.
	ResolveNow(resolver.ResolveNowOptions)
	// Target returns the target URI of the connection.
	Target() string
	// MetricsRecorder returns the metrics recorder for the connection.
	MetricsRecorder() estats.MetricsRecorder
}

ClientConnWrapper is an interface that wraps the gRPC ClientConn interface.

type Config added in v1.2.8

type Config struct {
	serviceconfig.LoadBalancingConfig `json:"-"` // Embedding the base load balancing config.
	PartitionCount                    int        `json:"partitionCount,omitempty"`    // Number of partitions in the consistent hash ring.
	ReplicationFactor                 int        `json:"replicationFactor,omitempty"` // Number of replicas for each member.
	Load                              float64    `json:"load,omitempty"`              // Load factor for balancing traffic.
	PickerWidth                       int        `json:"pickerWidth,omitempty"`       // Number of closest members to consider in the picker.
}

Config represents the configuration for the consistent hashing balancer.

func (*Config) ServiceConfigJSON added in v1.2.8

func (c *Config) ServiceConfigJSON() (string, error)

ServiceConfigJSON generates the JSON representation of the load balancer configuration.

type ConsistentMember added in v1.2.8

type ConsistentMember struct {
	balancer.SubConn // Embedded SubConn for the gRPC connection.
	// contains filtered or unexported fields
}

ConsistentMember represents a member in the consistent hashing ring.

func (ConsistentMember) String added in v1.2.8

func (s ConsistentMember) String() string

String returns the name of the ConsistentMember.

Jump to

Keyboard shortcuts

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