Documentation ¶
Index ¶
- Variables
- type BackendEventReceiver
- type BackendFetcher
- type BackendInfo
- type BackendObserver
- type BackendSelector
- type BackendStatus
- type ConnEventReceiver
- type PDFetcher
- type RedirectableConn
- type Router
- type ScoreBasedRouter
- func (router *ScoreBasedRouter) Close()
- func (router *ScoreBasedRouter) ConnCount() int
- func (router *ScoreBasedRouter) GetBackendSelector() BackendSelector
- func (r *ScoreBasedRouter) Init(httpCli *http.Client, fetcher BackendFetcher, cfg *config.HealthCheck) error
- func (router *ScoreBasedRouter) OnBackendChanged(backends map[string]*backendHealth, err error)
- func (router *ScoreBasedRouter) OnConnClosed(addr string, conn RedirectableConn) error
- func (router *ScoreBasedRouter) OnRedirectFail(from, to string, conn RedirectableConn) error
- func (router *ScoreBasedRouter) OnRedirectSucceed(from, to string, conn RedirectableConn) error
- func (router *ScoreBasedRouter) RedirectConnections() error
- func (router *ScoreBasedRouter) RefreshBackend()
- func (router *ScoreBasedRouter) ServerVersion() string
- type StaticFetcher
- type StaticRouter
- func (r *StaticRouter) Close()
- func (r *StaticRouter) ConnCount() int
- func (r *StaticRouter) GetBackendSelector() BackendSelector
- func (r *StaticRouter) OnConnClosed(addr 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
- type TopologyFetcher
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoInstanceToSelect = errors.New("no instances to route")
)
Functions ¶
This section is empty.
Types ¶
type BackendEventReceiver ¶
type BackendEventReceiver interface { // OnBackendChanged is called when the backend list changes. OnBackendChanged(backends map[string]*backendHealth, err error) }
BackendEventReceiver receives the event of backend status change.
type BackendFetcher ¶
type BackendFetcher interface {
GetBackendList(context.Context) (map[string]*BackendInfo, error)
}
BackendFetcher is an interface to fetch the backend list.
type BackendInfo ¶
BackendInfo stores the status info of each backend.
type BackendObserver ¶
type BackendObserver struct {
// contains filtered or unexported fields
}
BackendObserver refreshes backend list and notifies BackendEventReceiver.
func NewBackendObserver ¶
func NewBackendObserver(logger *zap.Logger, eventReceiver BackendEventReceiver, httpCli *http.Client, config *config.HealthCheck, backendFetcher BackendFetcher) (*BackendObserver, error)
NewBackendObserver creates a BackendObserver.
func StartBackendObserver ¶
func StartBackendObserver(logger *zap.Logger, eventReceiver BackendEventReceiver, httpCli *http.Client, config *config.HealthCheck, backendFetcher BackendFetcher) (*BackendObserver, error)
StartBackendObserver creates a BackendObserver and starts watching.
func (*BackendObserver) Refresh ¶
func (bo *BackendObserver) Refresh()
Refresh indicates the observer to refresh immediately.
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() (string, error)
func (*BackendSelector) Reset ¶
func (bs *BackendSelector) Reset()
type BackendStatus ¶
type BackendStatus int
const ( StatusHealthy BackendStatus = iota StatusCannotConnect StatusMemoryHigh StatusRunSlow StatusSchemaOutdated )
func (*BackendStatus) String ¶
func (bs *BackendStatus) String() string
func (*BackendStatus) ToScore ¶
func (bs *BackendStatus) ToScore() int
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 PDFetcher ¶
type PDFetcher struct {
// contains filtered or unexported fields
}
PDFetcher fetches backend list from PD.
func NewPDFetcher ¶
func NewPDFetcher(tpFetcher TopologyFetcher, logger *zap.Logger, config *config.HealthCheck) *PDFetcher
func (*PDFetcher) GetBackendList ¶
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(addr string) bool NotifyBackendStatus(status BackendStatus) 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 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() BackendSelector
GetBackendSelector implements Router.GetBackendSelector interface.
func (*ScoreBasedRouter) Init ¶
func (r *ScoreBasedRouter) Init(httpCli *http.Client, fetcher BackendFetcher, cfg *config.HealthCheck) error
func (*ScoreBasedRouter) OnBackendChanged ¶
func (router *ScoreBasedRouter) OnBackendChanged(backends map[string]*backendHealth, err error)
OnBackendChanged implements BackendEventReceiver.OnBackendChanged interface.
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 StaticFetcher ¶
type StaticFetcher struct {
// contains filtered or unexported fields
}
StaticFetcher uses configured static addrs. This is only used for testing.
func NewStaticFetcher ¶
func NewStaticFetcher(staticAddrs []string) *StaticFetcher
func (*StaticFetcher) GetBackendList ¶
func (sf *StaticFetcher) GetBackendList(context.Context) (map[string]*BackendInfo, error)
type StaticRouter ¶
type StaticRouter struct {
// contains filtered or unexported fields
}
func NewStaticRouter ¶
func NewStaticRouter(addr []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) 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