balancer

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package balancer provides gRPC load balancing functionality for service discovery and routing in distributed systems.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ReaderBalancerRegistered indicates whether the reader balancer has been registered.
	ReaderBalancerRegistered atomic.Bool
	// MasterBalancerRegistered indicates whether the master balancer has been registered.
	MasterBalancerRegistered atomic.Bool
)

Functions

func New

func New(opts ...Option) selector.Selector

New random a selector.

func NewBuilder

func NewBuilder(opts ...Option) selector.Builder

NewBuilder returns a selector builder with wrr balancer

func NewFilter

func NewFilter() selector.NodeFilter

NewFilter creates a node filter that filters nodes based on color. It returns a selector.NodeFilter that selects nodes matching the color from context.

func RegisterMasterBalancer

func RegisterMasterBalancer(rt routetable.RouteTable)

RegisterMasterBalancer registers a balancer for master nodes. It uses the provided route table for routing decisions.

func RegisterReaderBalancer

func RegisterReaderBalancer(rt routetable.RouteTable)

RegisterReaderBalancer registers a balancer for reader nodes. It uses the provided route table for routing decisions.

Types

type Balancer

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

Balancer is a weighted round-robin load balancer that supports route tables.

func (*Balancer) Pick

Pick is pick a weighted node

type Builder

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

Builder is a selector builder for creating weighted round-robin balancers.

func (*Builder) Build

func (b *Builder) Build() selector.Balancer

Build creates a new balancer instance.

type Option

type Option func(o *options)

Option is a function that configures the selector options.

func WithBalancerType

func WithBalancerType(balancerType Type) Option

WithBalancerType sets the balancer type.

func WithRouteTable

func WithRouteTable(rt routetable.RouteTable) Option

WithRouteTable sets the route table for the balancer.

type Trailer

type Trailer metadata.MD

Trailer is a grpc trailer MD.

func (Trailer) Get

func (t Trailer) Get(k string) string

Get get a grpc trailer value.

type Type added in v0.0.7

type Type string

Type represents the type of load balancer.

const (
	// TypeMaster is the balancer type for master nodes.
	TypeMaster Type = "master"
	// TypeReader is the balancer type for reader nodes.
	TypeReader Type = "reader"
)

Jump to

Keyboard shortcuts

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