server

package
v0.0.0-...-89d789c Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: Apache-2.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WRITE_TIMEOUT = "write_timeout"

	DEF_WRITE_TIMEOUT = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

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) []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 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) (QueryCtx, error)
}

IDriver opens IContext.

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
}

PreparedStatement is the interface to use a prepared statement.

type QueryCtx

type QueryCtx interface {
	// Status returns server status code.
	Status() uint16

	// LastInsertID returns last inserted ID.
	LastInsertID() uint64

	// LastMessage returns last info message generated by some commands
	LastMessage() string

	// AffectedRows returns affected rows of last executed command.
	AffectedRows() uint64

	// Value returns the value associated with this context for key.
	Value(key fmt.Stringer) interface{}

	// SetValue saves a value associated with this context for key.
	SetValue(key fmt.Stringer, value interface{})

	SetProcessInfo(sql string, t time.Time, command byte, maxExecutionTime uint64)

	// CommitTxn commits the transaction operations.
	CommitTxn(ctx context.Context) error

	// RollbackTxn undoes the transaction operations.
	RollbackTxn()

	// WarningCount returns warning count of last executed command.
	WarningCount() uint16

	// CurrentDB returns current DB.
	CurrentDB() string

	// Execute executes a SQL statement.
	Execute(ctx context.Context, sql string) (*mysql.Result, error)

	// ExecuteInternal executes a internal SQL statement.
	ExecuteInternal(ctx context.Context, sql string) ([]ResultSet, error)

	// SetClientCapability sets client capability flags
	SetClientCapability(uint32)

	// Prepare prepares a statement.
	Prepare(ctx context.Context, sql string) (stmtId int, columns, params []*ColumnInfo, err error)

	StmtExecuteForward(ctx context.Context, stmtId int, data []byte) (*mysql.Result, error)

	StmtClose(ctx context.Context, stmtId int) error

	// FieldList returns columns of a table.
	FieldList(tableName string) (columns []*ColumnInfo, err error)

	// Close closes the QueryCtx.
	Close() error

	// Auth verifies user's authentication.
	Auth(user *auth.UserIdentity, auth []byte, salt []byte) bool

	// ShowProcess shows the information about the session.
	ShowProcess() *util.ProcessInfo

	// GetSessionVars return SessionVars.
	GetSessionVars() *variable.SessionVars

	SetCommandValue(command byte)

	SetSessionManager(util.SessionManager)
}

QueryCtx is the interface to execute command.

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
}

ResultSet is the result set of an query.

type Server

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

func NewServer

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

NewServer creates a new Server.

func (*Server) Close

func (s *Server) Close()

Close closes the server. TODO(eastfisher): implement this function, close unix socket, status server, and gRPC server.

func (*Server) ConnectionCount

func (s *Server) ConnectionCount() int

ConnectionCount gets current connection count.

func (*Server) GracefulDown

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

GracefulDown waits all clients to close.

func (*Server) KillAllConnections

func (s *Server) KillAllConnections()

KillAllConnections kills all connections when server is not gracefully shutdown.

func (*Server) KillOneConnections

func (s *Server) KillOneConnections(connectionID uint32)

KillOneConnections kills one connections when server is not gracefully shutdown.

func (*Server) Run

func (s *Server) Run() error

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.

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