router

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoBackend = errors.New("no available backend")
)

Functions

This section is empty.

Types

type BackendInst

type BackendInst interface {
	Addr() string
	Healthy() bool
	Local() bool
}

BackendInst defines a backend that a connection is redirecting to.

type BackendSelector

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

func (*BackendSelector) Finish

func (bs *BackendSelector) Finish(conn RedirectableConn, succeed bool)

func (*BackendSelector) Next

func (bs *BackendSelector) Next() (BackendInst, error)

type ConnEventReceiver

type ConnEventReceiver interface {
	OnRedirectSucceed(from, to string, conn RedirectableConn) error
	OnRedirectFail(from, to string, conn RedirectableConn) error
	OnConnClosed(addr string, conn RedirectableConn) error
}

ConnEventReceiver receives connection events.

type RedirectableConn

type RedirectableConn interface {
	SetEventReceiver(receiver ConnEventReceiver)
	SetValue(key, val any)
	Value(key any) any
	// Redirect returns false if the current conn is not redirectable.
	Redirect(backend BackendInst) bool
	ConnectionID() uint64
}

RedirectableConn indicates a redirect-able connection.

type Router

type Router interface {
	// ConnEventReceiver handles connection events to balance connections if possible.
	ConnEventReceiver

	GetBackendSelector() BackendSelector
	HealthyBackendCount() int
	RefreshBackend()
	RedirectConnections() error
	ConnCount() int
	// ServerVersion returns the TiDB version.
	ServerVersion() string
	Close()
}

Router routes client connections to backends.

type ScoreBasedRouter

type ScoreBasedRouter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ScoreBasedRouter is an implementation of Router interface. It routes a connection based on score.

func NewScoreBasedRouter

func NewScoreBasedRouter(logger *zap.Logger) *ScoreBasedRouter

NewScoreBasedRouter creates a ScoreBasedRouter.

func (*ScoreBasedRouter) Close

func (router *ScoreBasedRouter) Close()

Close implements Router.Close interface.

func (*ScoreBasedRouter) ConnCount

func (router *ScoreBasedRouter) ConnCount() int

func (*ScoreBasedRouter) GetBackendSelector

func (router *ScoreBasedRouter) GetBackendSelector() BackendSelector

GetBackendSelector implements Router.GetBackendSelector interface.

func (*ScoreBasedRouter) HealthyBackendCount added in v1.3.0

func (router *ScoreBasedRouter) HealthyBackendCount() int

func (*ScoreBasedRouter) Init

func (r *ScoreBasedRouter) Init(ctx context.Context, ob observer.BackendObserver, balancePolicy policy.BalancePolicy, cfg *config.Config, cfgCh <-chan *config.Config)

func (*ScoreBasedRouter) OnConnClosed

func (router *ScoreBasedRouter) OnConnClosed(addr string, conn RedirectableConn) error

OnConnClosed implements ConnEventReceiver.OnConnClosed interface.

func (*ScoreBasedRouter) OnRedirectFail

func (router *ScoreBasedRouter) OnRedirectFail(from, to string, conn RedirectableConn) error

OnRedirectFail implements ConnEventReceiver.OnRedirectFail interface.

func (*ScoreBasedRouter) OnRedirectSucceed

func (router *ScoreBasedRouter) OnRedirectSucceed(from, to string, conn RedirectableConn) error

OnRedirectSucceed implements ConnEventReceiver.OnRedirectSucceed interface.

func (*ScoreBasedRouter) RedirectConnections

func (router *ScoreBasedRouter) RedirectConnections() error

RedirectConnections implements Router.RedirectConnections interface. It redirects all connections compulsively. It's only used for testing.

func (*ScoreBasedRouter) RefreshBackend

func (router *ScoreBasedRouter) RefreshBackend()

RefreshBackend implements Router.GetBackendSelector interface.

func (*ScoreBasedRouter) ServerVersion

func (router *ScoreBasedRouter) ServerVersion() string

type StaticBackend

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

func NewStaticBackend

func NewStaticBackend(addr string) *StaticBackend

func (*StaticBackend) Addr

func (b *StaticBackend) Addr() string

func (*StaticBackend) Healthy

func (b *StaticBackend) Healthy() bool

func (*StaticBackend) Local

func (b *StaticBackend) Local() bool

func (*StaticBackend) SetHealthy

func (b *StaticBackend) SetHealthy(healthy bool)

type StaticRouter

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

func NewStaticRouter

func NewStaticRouter(addrs []string) *StaticRouter

func (*StaticRouter) Close

func (r *StaticRouter) Close()

func (*StaticRouter) ConnCount

func (r *StaticRouter) ConnCount() int

func (*StaticRouter) GetBackendSelector

func (r *StaticRouter) GetBackendSelector() BackendSelector

func (*StaticRouter) HealthyBackendCount added in v1.3.0

func (r *StaticRouter) HealthyBackendCount() int

func (*StaticRouter) OnConnClosed

func (r *StaticRouter) OnConnClosed(addr string, conn RedirectableConn) error

func (*StaticRouter) OnRedirectFail

func (r *StaticRouter) OnRedirectFail(from, to string, conn RedirectableConn) error

func (*StaticRouter) OnRedirectSucceed

func (r *StaticRouter) OnRedirectSucceed(from, to string, conn RedirectableConn) error

func (*StaticRouter) RedirectConnections

func (r *StaticRouter) RedirectConnections() error

func (*StaticRouter) RefreshBackend

func (r *StaticRouter) RefreshBackend()

func (*StaticRouter) ServerVersion

func (r *StaticRouter) ServerVersion() string

Jump to

Keyboard shortcuts

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