lbcache

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Overview

Package lbcache combine balancer with resolver and cache the resolve result

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump added in v0.1.0

func Dump() interface{}

Types

type Balancer

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

Balancer same with loadbalance.Loadbalancer but without resolver.Result that has been cached

func (*Balancer) GetPicker

func (bl *Balancer) GetPicker() loadbalance.Picker

GetPicker equal to loadbalance.Balancer without pass discovery.Result, because we cache the result

func (*Balancer) GetResult added in v0.3.0

func (bl *Balancer) GetResult() (res discovery.Result, ok bool)

GetResult returns the discovery result that the Balancer holds.

func (*Balancer) Refresh added in v0.5.0

func (bl *Balancer) Refresh()

func (*Balancer) Tick added in v0.5.0

func (bl *Balancer) Tick()

Tick implements the interface utils.TickerTask.

type BalancerFactory

type BalancerFactory struct {
	Hookable
	// contains filtered or unexported fields
}

BalancerFactory get or create a balancer with given target if it has the same key(reslover.Target(target)), we will cache and reuse the Balance

func NewBalancerFactory

func NewBalancerFactory(resolver discovery.Resolver, balancer loadbalance.Loadbalancer, opts Options) *BalancerFactory

NewBalancerFactory get or create a balancer factory for balancer instance cache key with resolver name, balancer name and options

func (*BalancerFactory) Get

Get create a new balancer if not exists

type Hookable

type Hookable interface {
	// register loadbalance rebalance hook for Rebalance events
	RegisterRebalanceHook(func(ch *discovery.Change)) (index int)
	DeregisterRebalanceHook(index int)
	// register loadbalance delete hook for Delete events
	RegisterDeleteHook(func(ch *discovery.Change)) (index int)
	DeregisterDeleteHook(index int)
}

Hookable add hook for rebalancer events

type Options

type Options struct {
	// refresh discovery result timely
	RefreshInterval time.Duration

	// Balancer expire check interval
	// we need remove idle Balancers for resource saving
	ExpireInterval time.Duration

	// DiagnosisService is used register info for diagnosis
	DiagnosisService diagnosis.Service

	// Cacheable is used to indicate that if the factory could be shared between multi clients
	Cacheable bool
}

Options for create builder

Jump to

Keyboard shortcuts

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