server

package
v1.1.0-beta.0...-5753106 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 141 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// RunInGoTest represents whether we are run code in test.
	RunInGoTest bool
	// RunInGoTestChan is used to control the RunInGoTest.
	RunInGoTestChan chan struct{}
)
View Source
var (
	// ConnectionInMemCounterForTest is a variable to count live connection object
	ConnectionInMemCounterForTest = atomic.Int64{}
)

Functions

func ClearOSUserForAuthSocket

func ClearOSUserForAuthSocket()

ClearOSUserForAuthSocket clears the mocked OS user for AUTH_SOCKET plugin

func MockOSUserForAuthSocket

func MockOSUserForAuthSocket(uname string)

MockOSUserForAuthSocket mocks the OS user for AUTH_SOCKET plugin

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 DetailStatus

type DetailStatus struct {
	InitStatsPercentage float64 `json:"init_stats_percentage"`
}

DetailStatus is to show the detail status of TiDB. for example the init stats percentage.

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 uint8, dbname string, tlsState *tls.ConnectionState, extensions *extension.SessionExtensions) (*TiDBContext, error)
}

IDriver opens IContext.

type MockConn

type MockConn interface {
	// HandleQuery executes a statement
	HandleQuery(ctx context.Context, sql string) error
	// Context gets the TiDBContext
	Context() *TiDBContext
	// Dispatch executes command according to the command type
	Dispatch(ctx context.Context, data []byte) error
	// Close releases resources
	Close()
	// ID returns the connection ID.
	ID() uint64
	// GetOutbound replaces the internal outbound endpoint with a empty buffer, and return it
	GetOutput() *bytes.Buffer
}

MockConn is a mock connection.

func CreateMockConn

func CreateMockConn(t *testing.T, server *Server) MockConn

CreateMockConn creates a mock connection together with a session.

type PreparedStatement

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

	// Execute executes the statement.
	Execute(context.Context, []expression.Expression) (resultset.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.CursorResultSet)

	// GetResultSet gets ResultSet associated this statement
	GetResultSet() resultset.CursorResultSet

	// Reset removes all bound parameters and opened resultSet/rowContainer.
	Reset() error

	// Close closes the statement.
	Close() error

	// GetCursorActive returns whether the statement has active cursor
	GetCursorActive() bool

	// SetCursorActive sets whether the statement has active cursor
	SetCursorActive(active bool)

	// StoreRowContainer stores a row container into the prepared statement. The `rowContainer` is used to be closed at
	// appropriate time. It's actually not used to read, because an iterator of it has been stored in the result set.
	StoreRowContainer(container *chunk.RowContainer)

	// GetRowContainer returns the row container of the statement
	GetRowContainer() *chunk.RowContainer
}

PreparedStatement is the interface to use a prepared statement.

type Server

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

Server is the MySQL protocol server

func CreateMockServer

func CreateMockServer(t *testing.T, store kv.Storage) *Server

CreateMockServer creates a mock server.

func NewServer

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

NewServer creates a new Server.

func NewTestServer

func NewTestServer(cfg *config.Config) *Server

NewTestServer creates a new Server for test.

func (*Server) BitwiseOrAssignCapability

func (s *Server) BitwiseOrAssignCapability(capability uint32)

BitwiseOrAssignCapability adds the capability to the server.

func (*Server) BitwiseXorCapability

func (s *Server) BitwiseXorCapability(capability uint32)

BitwiseXorCapability gets the capability of the server.

func (*Server) CheckOldRunningTxn

func (s *Server) CheckOldRunningTxn(job2ver map[int64]int64, job2ids map[int64]string)

CheckOldRunningTxn implements SessionManager interface.

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) DeleteInternalSession

func (s *Server) DeleteInternalSession(se any)

DeleteInternalSession implements SessionManager interface. @param addr The address of a session.session struct variable

func (*Server) DrainClients

func (s *Server) DrainClients(drainWait time.Duration, cancelWait time.Duration)

DrainClients drain all connections in drainWait. After drainWait duration, we kill all connections still not quit explicitly and wait for cancelWait.

func (*Server) GetConAttrs

func (s *Server) GetConAttrs(user *auth.UserIdentity) map[uint64]map[string]string

GetConAttrs returns the connection attributes

func (*Server) GetInternalSessionStartTSList

func (s *Server) GetInternalSessionStartTSList() []uint64

GetInternalSessionStartTSList implements SessionManager interface.

func (*Server) GetProcessInfo

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

GetProcessInfo implements the SessionManager interface.

func (*Server) GetScope

func (*Server) GetScope(_ string) variable.ScopeFlag

GetScope gets the Status variables scope.

func (*Server) GetStatusServerAddr

func (s *Server) GetStatusServerAddr() (on bool, addr string)

GetStatusServerAddr gets statusServer address for MppCoordinatorManager usage

func (*Server) GetTLSConfig

func (s *Server) GetTLSConfig() *tls.Config

GetTLSConfig implements the SessionManager interface.

func (*Server) InternalSessionExists

func (s *Server) InternalSessionExists(se any) bool

InternalSessionExists is used for test

func (*Server) Kill

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

Kill implements the SessionManager interface.

func (*Server) KillAllConnections

func (s *Server) KillAllConnections()

KillAllConnections implements the SessionManager interface. KillAllConnections kills all connections.

func (*Server) KillNonFlashbackClusterConn

func (s *Server) KillNonFlashbackClusterConn()

KillNonFlashbackClusterConn implements SessionManager interface.

func (*Server) KillSysProcesses

func (s *Server) KillSysProcesses()

KillSysProcesses kill sys processes such as auto analyze.

func (*Server) ListenAddr

func (s *Server) ListenAddr() net.Addr

ListenAddr returns the server's listener's network address.

func (*Server) Listener

func (s *Server) Listener() net.Listener

Listener returns the server's listener.

func (*Server) NewTikvHandlerTool

func (s *Server) NewTikvHandlerTool() *handler.TikvHandlerTool

NewTikvHandlerTool checks and prepares for tikv handler. It would panic when any error happens.

func (*Server) Run

func (s *Server) Run(dom *domain.Domain) error

Run runs the server.

func (*Server) ServerID

func (s *Server) ServerID() uint64

ServerID implements SessionManager interface.

func (*Server) SetCNChecker

func (s *Server) SetCNChecker(tlsConfig *tls.Config) *tls.Config

SetCNChecker set the CN checker for server.

func (*Server) SetDomain

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

SetDomain use to set the server domain.

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`. Internal sessions are not taken into consideration.

func (*Server) Socket

func (s *Server) Socket() net.Listener

Socket returns the server's socket file.

func (*Server) Stats

func (s *Server) Stats(_ *variable.SessionVars) (map[string]any, error)

Stats returns the server statistics.

func (*Server) StatusListenerAddr

func (s *Server) StatusListenerAddr() net.Addr

StatusListenerAddr returns the server's status listener's network address.

func (*Server) StoreInternalSession

func (s *Server) StoreInternalSession(se any)

StoreInternalSession implements SessionManager interface. @param addr The address of a session.session struct variable

func (*Server) UpdateProcessCPUTime

func (s *Server) UpdateProcessCPUTime(connID uint64, sqlID uint64, cpuTime time.Duration)

UpdateProcessCPUTime updates specific process's tidb CPU time when the process is still running It implements ProcessCPUTimeUpdater interface

func (*Server) UpdateTLSConfig

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

UpdateTLSConfig implements the SessionManager interface.

type Status

type Status struct {
	Connections int          `json:"connections"`
	Version     string       `json:"version"`
	GitHash     string       `json:"git_hash"`
	Status      DetailStatus `json:"status"`
}

Status of TiDB.

type TiDBContext

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

TiDBContext implements QueryCtx.

func (*TiDBContext) Close

func (tc *TiDBContext) Close() error

Close implements QueryCtx Close method.

func (*TiDBContext) DecodeSessionStates

func (tc *TiDBContext) DecodeSessionStates(ctx context.Context, _ sessionctx.Context, sessionStates *sessionstates.SessionStates) error

DecodeSessionStates implements SessionStatesHandler.DecodeSessionStates interface.

func (*TiDBContext) EncodeSessionStates

func (tc *TiDBContext) EncodeSessionStates(_ context.Context, _ sessionctx.Context, sessionStates *sessionstates.SessionStates) error

EncodeSessionStates implements SessionStatesHandler.EncodeSessionStates interface.

func (*TiDBContext) ExecuteStmt

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

ExecuteStmt implements QueryCtx interface.

func (*TiDBContext) FieldList

func (tc *TiDBContext) FieldList(table string) (columns []*column.Info, err error)

FieldList implements QueryCtx FieldList method.

func (*TiDBContext) GetStatement

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

GetStatement implements QueryCtx GetStatement method.

func (*TiDBContext) GetStmtStats

func (tc *TiDBContext) GetStmtStats() *stmtstats.StatementStats

GetStmtStats implements the sessionctx.Context interface.

func (*TiDBContext) GetWarnings

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

GetWarnings implements QueryCtx GetWarnings method.

func (*TiDBContext) Prepare

func (tc *TiDBContext) Prepare(sql string) (statement PreparedStatement, columns, params []*column.Info, 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 uint8, _ string,
	tlsState *tls.ConnectionState, extensions *extension.SessionExtensions) (*TiDBContext, error)

OpenCtx implements IDriver.

type TiDBStatement

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

TiDBStatement implements PreparedStatement.

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 []expression.Expression) (rs resultset.ResultSet, err error)

Execute implements PreparedStatement Execute method.

func (*TiDBStatement) GetCursorActive

func (ts *TiDBStatement) GetCursorActive() bool

GetCursorActive implements PreparedStatement GetCursorActive method.

func (*TiDBStatement) GetParamsType

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

GetParamsType implements PreparedStatement GetParamsType method.

func (*TiDBStatement) GetResultSet

func (ts *TiDBStatement) GetResultSet() resultset.CursorResultSet

GetResultSet gets ResultSet associated this statement

func (*TiDBStatement) GetRowContainer

func (ts *TiDBStatement) GetRowContainer() *chunk.RowContainer

GetRowContainer returns the row container of the 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() error

Reset implements PreparedStatement Reset method.

func (*TiDBStatement) SetCursorActive

func (ts *TiDBStatement) SetCursorActive(fetchEnd bool)

SetCursorActive implements PreparedStatement SetCursorActive method.

func (*TiDBStatement) SetParamsType

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

SetParamsType implements PreparedStatement SetParamsType method.

func (*TiDBStatement) StoreResultSet

func (ts *TiDBStatement) StoreResultSet(rs resultset.CursorResultSet)

StoreResultSet stores ResultSet for stmt fetching

func (*TiDBStatement) StoreRowContainer

func (ts *TiDBStatement) StoreRowContainer(c *chunk.RowContainer)

StoreRowContainer stores a row container into the prepared statement

Jump to

Keyboard shortcuts

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