Documentation
¶
Index ¶
- Variables
- type BackendInst
- type BackendSelector
- type ClientInfo
- type ConnEventReceiver
- type Group
- func (g *Group) AddBackend(backendID string, backend *backendWrapper)
- func (g *Group) Balance(ctx context.Context)
- func (g *Group) CloseTimedOutFailoverConnections(now time.Time)
- func (g *Group) ConnCount() int
- func (g *Group) EqualValues(values []string) bool
- func (g *Group) Intersect(values []string) bool
- func (g *Group) Match(clientInfo ClientInfo) bool
- func (g *Group) OnConnClosed(backendID string, conn RedirectableConn) error
- func (g *Group) OnRedirectFail(from, to string, conn RedirectableConn) error
- func (g *Group) OnRedirectSucceed(from, to string, conn RedirectableConn) error
- func (g *Group) RedirectConnections() error
- func (g *Group) RefreshCidr()
- func (g *Group) Route(excluded []BackendInst) (policy.BackendCtx, error)
- func (g *Group) SetConfig(cfg *config.Config)
- func (g *Group) UpdateFailover(now time.Time)
- type MatchType
- type RedirectableConn
- type Router
- type ScoreBasedRouter
- func (router *ScoreBasedRouter) Close()
- func (router *ScoreBasedRouter) ConnCount() int
- func (router *ScoreBasedRouter) GetBackendSelector(clientInfo ClientInfo) BackendSelector
- func (router *ScoreBasedRouter) HealthyBackendCount() int
- func (r *ScoreBasedRouter) Init(ctx context.Context, ob observer.BackendObserver, ...)
- func (router *ScoreBasedRouter) RedirectConnections() error
- func (router *ScoreBasedRouter) RefreshBackend()
- func (router *ScoreBasedRouter) ServerVersion() string
- type StaticBackend
- func (b *StaticBackend) Addr() string
- func (b *StaticBackend) ClusterName() string
- func (b *StaticBackend) Healthy() bool
- func (b *StaticBackend) ID() string
- func (b *StaticBackend) Keyspace() string
- func (b *StaticBackend) Local() bool
- func (b *StaticBackend) SetHealthy(healthy bool)
- func (b *StaticBackend) SetKeyspace(k string)
- type StaticRouter
- func (r *StaticRouter) Close()
- func (r *StaticRouter) ConnCount() int
- func (r *StaticRouter) GetBackendSelector(_ ClientInfo) BackendSelector
- func (r *StaticRouter) HealthyBackendCount() int
- func (r *StaticRouter) OnConnClosed(backendID string, conn RedirectableConn) error
- func (r *StaticRouter) OnRedirectFail(from, to string, conn RedirectableConn) error
- func (r *StaticRouter) OnRedirectSucceed(from, to string, conn RedirectableConn) error
- func (r *StaticRouter) RedirectConnections() error
- func (r *StaticRouter) RefreshBackend()
- func (r *StaticRouter) ServerVersion() string
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoBackend = errors.New("no available backend") ErrPortConflict = errors.New("port routing conflict") )
Functions ¶
This section is empty.
Types ¶
type BackendInst ¶
type BackendInst interface {
ID() string
Addr() string
Healthy() bool
Local() bool
Keyspace() string
ClusterName() string
}
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 ClientInfo ¶
type ConnEventReceiver ¶
type ConnEventReceiver interface {
OnRedirectSucceed(from, to string, conn RedirectableConn) error
OnRedirectFail(from, to string, conn RedirectableConn) error
OnConnClosed(backendID string, conn RedirectableConn) error
}
ConnEventReceiver receives connection events.
type Group ¶
Group is used for one backend group that can be matched by CIDR, username, database, or resource group list.
func (*Group) AddBackend ¶
func (*Group) CloseTimedOutFailoverConnections ¶
func (*Group) EqualValues ¶
func (*Group) Intersect ¶
Intersect returns if any cidrs are the same. In next-gen, backend cidrs may increase or decrease but they stay in the same group. E.g. enable public endpoint (3 cidrs) -> enable private endpoint (6 cidrs) -> disable public endpoint (3 cidrs).
func (*Group) Match ¶
func (g *Group) Match(clientInfo ClientInfo) bool
func (*Group) OnConnClosed ¶
func (g *Group) OnConnClosed(backendID string, conn RedirectableConn) error
OnConnClosed implements ConnEventReceiver.OnConnClosed interface.
func (*Group) OnRedirectFail ¶
func (g *Group) OnRedirectFail(from, to string, conn RedirectableConn) error
OnRedirectFail implements ConnEventReceiver.OnRedirectFail interface.
func (*Group) OnRedirectSucceed ¶
func (g *Group) OnRedirectSucceed(from, to string, conn RedirectableConn) error
OnRedirectSucceed implements ConnEventReceiver.OnRedirectSucceed interface.
func (*Group) RedirectConnections ¶
RedirectConnections implements Router.RedirectConnections interface. It redirects all connections compulsively. It's only used for testing.
func (*Group) Route ¶
func (g *Group) Route(excluded []BackendInst) (policy.BackendCtx, error)
func (*Group) UpdateFailover ¶
type MatchType ¶
type MatchType int
const ( // Match all connections, used when there is only one backend group. MatchAll MatchType = iota // Match connections based on the client CIDR. MatchClientCIDR // Match connections based on proxy CIDR. If proxy-protocol is disabled, route by the client CIDR. MatchProxyCIDR // Match connections based on the local SQL listener port. MatchPort )
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
// ForceClose closes the connection immediately and returns false if it's already closing.
ForceClose() bool
ConnectionID() uint64
ConnInfo() []zap.Field
}
RedirectableConn indicates a redirect-able connection.
type Router ¶
type Router interface {
GetBackendSelector(clientInfo ClientInfo) BackendSelector
HealthyBackendCount() int
RefreshBackend()
RedirectConnections() error
ConnCount() int
// ServerVersion returns the TiDB version.
ServerVersion() string
Close()
}
Router routes client connections to backends.
type ScoreBasedRouter ¶
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(clientInfo ClientInfo) 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, bpCreator func(lg *zap.Logger) policy.BalancePolicy, cfgGetter config.ConfigGetter, cfgCh <-chan *config.Config)
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) ClusterName ¶
func (b *StaticBackend) ClusterName() string
func (*StaticBackend) Healthy ¶
func (b *StaticBackend) Healthy() bool
func (*StaticBackend) ID ¶
func (b *StaticBackend) ID() string
func (*StaticBackend) Keyspace ¶
func (b *StaticBackend) Keyspace() string
func (*StaticBackend) Local ¶
func (b *StaticBackend) Local() bool
func (*StaticBackend) SetHealthy ¶
func (b *StaticBackend) SetHealthy(healthy bool)
func (*StaticBackend) SetKeyspace ¶
func (b *StaticBackend) SetKeyspace(k string)
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(_ ClientInfo) BackendSelector
func (*StaticRouter) HealthyBackendCount ¶ added in v1.3.0
func (r *StaticRouter) HealthyBackendCount() int
func (*StaticRouter) OnConnClosed ¶
func (r *StaticRouter) OnConnClosed(backendID 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