server

package
v0.0.0-...-97e998e Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: GPL-3.0 Imports: 117 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRPCServer

func NewRPCServer(config *config.Config, dom *domain.Domain, sm util.SessionManager) *grpc.Server

NewRPCServer creates a new rpc server.

Types

type Ballast

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

Ballast try to reduce the GC frequency by using Ballast Object

func (*Ballast) GenHTTPHandler

func (b *Ballast) GenHTTPHandler() func(w http.ResponseWriter, r *http.Request)

GenHTTPHandler generate a HTTP handler to get/set the size of this ballast object

func (*Ballast) GetSize

func (b *Ballast) GetSize() int

GetSize get the size of ballast object

func (*Ballast) SetSize

func (b *Ballast) SetSize(newSz int) error

SetSize set the size of ballast object

type ColumnInfo

type ColumnInfo struct {
	Schema             string
	Table              string
	OrgTable           string
	Name               string
	OrgName            string
	ColumnLength       uint32
	Charset            uint16
	Flag               uint16
	Decimal            uint8
	Type               uint8
	DefaultValueLength uint64
	DefaultValue       []byte
}

ColumnInfo contains information of a column

func (*ColumnInfo) Dump

func (column *ColumnInfo) Dump(buffer []byte, d *resultEncoder) []byte

Dump dumps ColumnInfo to bytes.

type CorsHandler

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

CorsHandler adds Cors Header if `cors` config is set.

func (CorsHandler) ServeHTTP

func (h CorsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type DatabaseMode

type DatabaseMode int
const (
	DatabaseModeNone DatabaseMode = iota
	DatabaseModeMySQL
	DatabaseModePostgreSQL
)

type FrameItem

type FrameItem struct {
	DBName      string   `json:"db_name"`
	TableName   string   `json:"table_name"`
	TableID     int64    `json:"table_id"`
	IsRecord    bool     `json:"is_record"`
	RecordID    int64    `json:"record_id,omitempty"`
	IndexName   string   `json:"index_name,omitempty"`
	IndexID     int64    `json:"index_id,omitempty"`
	IndexValues []string `json:"index_values,omitempty"`
}

FrameItem includes a index's or record's meta data with table's info.

type IDriver

type IDriver interface {
	// OpenCtx opens an IContext with connection id, client capability, collation, dbname and optionally the tls state.
	OpenCtx(connID uint64, capability uint32, collation uint16, dbname string, tlsState *tls.ConnectionState) (*TiDBContext, error)
}

IDriver opens IContext.

type IndexRegions

type IndexRegions struct {
	Name    string       `json:"name"`
	ID      int64        `json:"id"`
	Regions []RegionMeta `json:"regions"`
}

IndexRegions is the region info for one index.

type PlanReplayerHandler

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

PlanReplayerHandler is the handler for dumping plan replayer file.

func (PlanReplayerHandler) ServeHTTP

func (prh PlanReplayerHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type PreparedStatement

type PreparedStatement interface {
	// ID returns statement ID
	ID() int

	// Execute executes the statement.
	Execute(context.Context, []types.Datum) (ResultSet, error)

	// AppendParam appends parameter to the statement.
	AppendParam(paramID int, data []byte) error

	// NumParams returns number of parameters.
	NumParams() int

	// BoundParams returns bound parameters.
	BoundParams() [][]byte

	// SetParamsType sets type for parameters.
	SetParamsType([]byte)

	// GetParamsType returns the type for parameters.
	GetParamsType() []byte

	// StoreResultSet stores ResultSet for subsequent stmt fetching
	StoreResultSet(rs ResultSet)

	// GetResultSet gets ResultSet associated this statement
	GetResultSet() ResultSet

	// Reset removes all bound parameters.
	Reset()

	// Close closes the statement.
	Close() error

	// SetColumnInfo 设置statement中返回行数据信息
	// PgSQL Modified
	SetColumnInfo(columns []*ColumnInfo)

	// GetColumnInfo 获取statement中返回行数据信息
	// PgSQL Modified
	GetColumnInfo() []*ColumnInfo

	// SetArgs 在bind阶段绑定参数具体值
	// PgSQL Modified
	SetArgs(args []types.Datum)

	// GetArgs 获取Args的具体值
	// PgSQL Modified
	GetArgs() []types.Datum

	// GetResultFormat 获取结果返回的格式 0 为 Text, 1 为 Binary
	// PgSQL Modified
	GetResultFormat() []int16

	// SetResultFormat 设置结果返回的格式 0 为 Text, 1 为 Binary
	// PgSQL Modified
	SetResultFormat(rf []int16)

	// GetOIDs returns the postgres OIDs
	// PgSQL Modified
	GetOIDs() []uint32

	// SetOIDs set the postgres OIDs
	// PgSQL Modified
	SetOIDs(pgOIDs []uint32)
}

PreparedStatement is the interface to use a prepared statement.

type RangeDetail

type RangeDetail struct {
	StartKey    []byte `json:"start_key"`
	EndKey      []byte `json:"end_key"`
	StartKeyHex string `json:"start_key_hex"`
	EndKeyHex   string `json:"end_key_hex"`
}

RangeDetail contains detail information about a particular range

type RegionDetail

type RegionDetail struct {
	RangeDetail `json:",inline"`
	RegionID    uint64              `json:"region_id"`
	Frames      []*helper.FrameItem `json:"frames"`
}

RegionDetail is the response data for get region by ID it includes indices and records detail in current region.

type RegionMeta

type RegionMeta struct {
	ID          uint64              `json:"region_id"`
	Leader      *metapb.Peer        `json:"leader"`
	Peers       []*metapb.Peer      `json:"peers"`
	RegionEpoch *metapb.RegionEpoch `json:"region_epoch"`
}

RegionMeta contains a region's peer detail

type ResultSet

type ResultSet interface {
	Columns() []*ColumnInfo
	NewChunk() *chunk.Chunk
	Next(context.Context, *chunk.Chunk) error
	StoreFetchedRows(rows []chunk.Row)
	GetFetchedRows() []chunk.Row
	Close() error
	IsPrepareStmt() bool
}

ResultSet is the result set of an query.

type Server

type Server struct {
	DatabaseMode
	// contains filtered or unexported fields
}

Server is the MySQL protocol server

func NewServer

func NewServer(cfg *config.Config, driver IDriver) (*Server, error)

NewServer creates a new Server.

func (*Server) AddOscProcess

func (s *Server) AddOscProcess(p *util.OscProcessInfo)

AddOscProcess implements util.SessionManager.

func (*Server) Close

func (s *Server) Close()

Close closes the server.

func (*Server) ConnectionCount

func (s *Server) ConnectionCount() int

ConnectionCount gets current connection count.

func (*Server) GetProcessInfo

func (s *Server) GetProcessInfo(id uint64) (*util.ProcessInfo, bool)

GetProcessInfo implements the SessionManager interface.

func (*Server) GetScope

func (s *Server) GetScope(status string) variable.ScopeFlag

GetScope gets the status variables scope.

func (*Server) GracefulDown

func (s *Server) GracefulDown(ctx context.Context, done chan struct{})

GracefulDown waits all clients to close.

func (*Server) InitGlobalConnID

func (s *Server) InitGlobalConnID(serverIDGetter func() uint64)

InitGlobalConnID initialize global connection id.

func (*Server) InitOscProcessList

func (s *Server) InitOscProcessList()

func (*Server) Kill

func (s *Server) Kill(connectionID uint64, query bool)

Kill implements the SessionManager interface.

func (*Server) KillAllConnections

func (s *Server) KillAllConnections()

KillAllConnections kills all connections when server is not gracefully shutdown.

func (*Server) KillOscProcess

func (s *Server) KillOscProcess(connectionID uint64)

KillOscProcess implements util.SessionManager.

func (*Server) OscLock

func (s *Server) OscLock()

OscLock implements util.SessionManager.

func (*Server) OscUnLock

func (s *Server) OscUnLock()

OscUnLock implements util.SessionManager.

func (*Server) Run

func (s *Server) Run() error

Run runs the server.

func (*Server) ServerID

func (s *Server) ServerID() uint64

ServerID implements SessionManager interface.

func (*Server) SetDomain

func (s *Server) SetDomain(dom *domain.Domain)

SetDomain use to set the server domain.

func (*Server) ShowOscProcessList

func (s *Server) ShowOscProcessList() map[string]*util.OscProcessInfo

func (*Server) ShowOscProcessListWithWrite

func (s *Server) ShowOscProcessListWithWrite() map[string]*util.OscProcessInfo

ShowOscProcessListWithWrite implements util.SessionManager.

func (*Server) ShowProcessList

func (s *Server) ShowProcessList() map[uint64]*util.ProcessInfo

ShowProcessList implements the SessionManager interface.

func (*Server) ShowTxnList

func (s *Server) ShowTxnList() []*txninfo.TxnInfo

ShowTxnList shows all txn info for displaying in `TIDB_TRX`

func (*Server) Stats

func (s *Server) Stats(vars *variable.SessionVars) (map[string]interface{}, error)

Stats returns the server statistics.

func (*Server) TryGracefulDown

func (s *Server) TryGracefulDown()

TryGracefulDown will try to gracefully close all connection first with timeout. if timeout, will close all connection directly.

func (*Server) UpdateTLSConfig

func (s *Server) UpdateTLSConfig(cfg *tls.Config)

UpdateTLSConfig implements the SessionManager interface.

type StatsHandler

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

StatsHandler is the handler for dumping statistics.

func (StatsHandler) ServeHTTP

func (sh StatsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type StatsHistoryHandler

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

StatsHistoryHandler is the handler for dumping statistics.

func (StatsHistoryHandler) ServeHTTP

func (sh StatsHistoryHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type TableRanges

type TableRanges struct {
	TableName string                 `json:"name"`
	TableID   int64                  `json:"id"`
	Range     RangeDetail            `json:"table"`
	Record    RangeDetail            `json:"record"`
	Index     RangeDetail            `json:"index"`
	Indices   map[string]RangeDetail `json:"indices,omitempty"`
}

TableRanges is the response data for list table's ranges. It contains ranges list for record and indices as well as the whole table.

type TableRegions

type TableRegions struct {
	TableName     string         `json:"name"`
	TableID       int64          `json:"id"`
	RecordRegions []RegionMeta   `json:"record_regions"`
	Indices       []IndexRegions `json:"indices"`
}

TableRegions is the response data for list table's regions. It contains regions list for record and indices.

type TiDBContext

type TiDBContext struct {
	session.Session
	// contains filtered or unexported fields
}

TiDBContext implements QueryCtx.

func (*TiDBContext) Close

func (tc *TiDBContext) Close() error

Close implements QueryCtx Close method.

func (*TiDBContext) CurrentDB

func (tc *TiDBContext) CurrentDB() string

CurrentDB implements QueryCtx CurrentDB method.

func (*TiDBContext) Execute

func (tc *TiDBContext) Execute(ctx context.Context, sql string) (rs []ResultSet, err error)

func (*TiDBContext) ExecuteStmt

func (tc *TiDBContext) ExecuteStmt(ctx context.Context, stmt ast.StmtNode) (ResultSet, error)

ExecuteStmt implements QueryCtx interface.

func (*TiDBContext) FieldList

func (tc *TiDBContext) FieldList(table string) (columns []*ColumnInfo, err error)

FieldList implements QueryCtx FieldList method.

func (*TiDBContext) GetStatement

func (tc *TiDBContext) GetStatement(stmtID int) PreparedStatement

GetStatement implements QueryCtx GetStatement method.

func (*TiDBContext) GetWarnings

func (tc *TiDBContext) GetWarnings() []stmtctx.SQLWarn

GetWarnings implements QueryCtx GetWarnings method.

func (*TiDBContext) MysqlPrepare

func (tc *TiDBContext) MysqlPrepare(sql string) (statement PreparedStatement, columns, params []*ColumnInfo, err error)

Prepare implements QueryCtx Prepare method.

func (*TiDBContext) NeedPassword

func (tc *TiDBContext) NeedPassword(user *auth.UserIdentity) bool

NeedPassword implements QueryCtx NeedPassword method

func (*TiDBContext) Prepare

func (tc *TiDBContext) Prepare(sql string, name string) (statement PreparedStatement, columns, params []*ColumnInfo, err error)

Prepare implements QueryCtx Prepare method.

func (*TiDBContext) WarningCount

func (tc *TiDBContext) WarningCount() uint16

WarningCount implements QueryCtx WarningCount method.

type TiDBDriver

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

TiDBDriver implements IDriver.

func NewTiDBDriver

func NewTiDBDriver(store kv.Storage) *TiDBDriver

NewTiDBDriver creates a new TiDBDriver.

func (*TiDBDriver) OpenCtx

func (qd *TiDBDriver) OpenCtx(connID uint64, capability uint32, collation uint16, dbname string, tlsState *tls.ConnectionState) (*TiDBContext, error)

OpenCtx implements IDriver.

type TiDBStatement

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

func (*TiDBStatement) AppendParam

func (ts *TiDBStatement) AppendParam(paramID int, data []byte) error

AppendParam implements PreparedStatement AppendParam method.

func (*TiDBStatement) BoundParams

func (ts *TiDBStatement) BoundParams() [][]byte

BoundParams implements PreparedStatement BoundParams method.

func (*TiDBStatement) Close

func (ts *TiDBStatement) Close() error

Close implements PreparedStatement Close method.

func (*TiDBStatement) Execute

func (ts *TiDBStatement) Execute(ctx context.Context, args []types.Datum) (rs ResultSet, err error)

Execute implements PreparedStatement Execute method.

func (*TiDBStatement) GetArgs

func (ts *TiDBStatement) GetArgs() []types.Datum

GetArgs 获取绑定后的参数值

func (*TiDBStatement) GetColumnInfo

func (ts *TiDBStatement) GetColumnInfo() []*ColumnInfo

GetColumnInfo 获取 TiDBStatement 中返回行数据信息

func (*TiDBStatement) GetOIDs

func (ts *TiDBStatement) GetOIDs() []uint32

GetOIDs return OIDs for the current statement

func (*TiDBStatement) GetParamsType

func (ts *TiDBStatement) GetParamsType() []byte

GetParamsType implements PreparedStatement GetParamsType method.

func (*TiDBStatement) GetResultFormat

func (ts *TiDBStatement) GetResultFormat() []int16

GetResultFormat 获取结果返回的格式 0 为 Text, 1 为 Binary

func (*TiDBStatement) GetResultSet

func (ts *TiDBStatement) GetResultSet() ResultSet

GetResultSet gets ResultSet associated this statement

func (*TiDBStatement) ID

func (ts *TiDBStatement) ID() int

ID implements PreparedStatement ID method.

func (*TiDBStatement) NumParams

func (ts *TiDBStatement) NumParams() int

NumParams implements PreparedStatement NumParams method.

func (*TiDBStatement) Reset

func (ts *TiDBStatement) Reset()

Reset implements PreparedStatement Reset method.

func (*TiDBStatement) SetArgs

func (ts *TiDBStatement) SetArgs(args []types.Datum)

SetArgs 进行参数绑定值

func (*TiDBStatement) SetColumnInfo

func (ts *TiDBStatement) SetColumnInfo(columns []*ColumnInfo)

SetColumnInfo 设置 TiDBStatement 中返回行数据信息 如果有返回数据的语句,则存储返回数据的结构,如果没有则为空

func (*TiDBStatement) SetOIDs

func (ts *TiDBStatement) SetOIDs(pgOIDs []uint32)

SetOIDs set OIDs for the current statement

func (*TiDBStatement) SetParamsType

func (ts *TiDBStatement) SetParamsType(paramsType []byte)

SetParamsType implements PreparedStatement SetParamsType method.

func (*TiDBStatement) SetResultFormat

func (ts *TiDBStatement) SetResultFormat(rf []int16)

SetResultFormat 设置结果返回的格式 0 为 Text, 1 为 Binary

func (*TiDBStatement) StoreResultSet

func (ts *TiDBStatement) StoreResultSet(rs ResultSet)

StoreResultSet stores ResultSet for stmt fetching

type Token

type Token struct {
}

Token is used as a permission to keep on running.

type TokenLimiter

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

TokenLimiter is used to limit the number of concurrent tasks.

func NewTokenLimiter

func NewTokenLimiter(count uint) *TokenLimiter

NewTokenLimiter creates a TokenLimiter with count tokens.

func (*TokenLimiter) Get

func (tl *TokenLimiter) Get() *Token

Get obtains a token.

func (*TokenLimiter) Put

func (tl *TokenLimiter) Put(tk *Token)

Put releases the token.

Jump to

Keyboard shortcuts

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