server

package
v0.0.0-...-3903214 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: Apache-2.0 Imports: 66 Imported by: 0

Documentation

Index

Constants

This section is empty.

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

	// ExecuteStmt executes a SQL statement.
	ExecuteStmt(context.Context, ast.StmtNode) (ResultSet, error)

	// Parse parses a SQL to statement node.
	Parse(ctx context.Context, sql string) ([]ast.StmtNode, error)

	// SetClientCapability sets client capability flags
	SetClientCapability(uint32)

	// Prepare prepares a statement.
	Prepare(sql string) (statement PreparedStatement, columns, params []*ColumnInfo, err error)

	// GetStatement gets PreparedStatement by statement ID.
	GetStatement(stmtID int) PreparedStatement

	// 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

	//For debug
	GetHistorySQL() string

	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
}

Server is the MySQL protocol server

func NewServer

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

NewServer creates a new Server.

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

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

GracefulDown waits all clients to close.

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

func (s *Server) Run() error

Run runs the 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) 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 Session

type Session interface {
	sctx.Context
	Status() uint16 // Flag of current status, such as autocommit.
	ExecuteStmt(context.Context, ast.StmtNode) (sqlexec.RecordSet, error)
	Execute(context.Context, string) (sqlexec.RecordSet, error)
	Parse(ctx context.Context, sql string) ([]ast.StmtNode, error)
	String() string // String is used to debug.
	CommitTxn(context.Context) error
	RollbackTxn(context.Context)
	SetConnectionID(uint64)
	SetCollation(coID int) error
	Close()
	// FieldList returns fields list of a table.
	FieldList(tableName string) (fields []*ast.ResultField, err error)
	AffectedRows() uint64

	GetHistorySQL() string
}

func CreateSession

func CreateSession(store kv.Storage) (Session, error)

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.

type TxnState

type TxnState struct {
	// States of a TxnState should be one of the followings:
	// Invalid: kv.Transaction == nil && txnFuture == nil
	// Pending: kv.Transaction == nil && txnFuture != nil
	// Valid:	kv.Transaction != nil && txnFuture == nil
	kv.Transaction
	// contains filtered or unexported fields
}

TxnState wraps kv.Transaction to provide a new kv.Transaction. 1. It holds all statement related modification in the buffer before flush to the txn, so if execute statement meets error, the txn won't be made dirty. 2. It's a lazy transaction, that means it's a txnFuture before StartTS() is really need.

func (*TxnState) BatchGet

func (st *TxnState) BatchGet(ctx context.Context, keys []kv.Key) (map[string][]byte, error)

BatchGet overrides the Transaction interface.

func (*TxnState) Commit

func (st *TxnState) Commit(ctx context.Context) error

Commit overrides the Transaction interface.

func (*TxnState) Delete

func (st *TxnState) Delete(k kv.Key) error

Delete overrides the Transaction interface.

func (*TxnState) Discard

func (st *TxnState) Discard()

Discard discards all staging kvs.

func (*TxnState) Flush

func (st *TxnState) Flush() (int, error)

Flush flushes all staging kvs into parent buffer.

func (*TxnState) Get

func (st *TxnState) Get(ctx context.Context, k kv.Key) ([]byte, error)

Get overrides the Transaction interface.

func (*TxnState) GetMemBuffer

func (st *TxnState) GetMemBuffer() kv.MemBuffer

GetMemBuffer overrides the Transaction interface.

func (*TxnState) GoString

func (st *TxnState) GoString() string

GoString implements the "%#v" format for fmt.Printf.

func (*TxnState) Iter

func (st *TxnState) Iter(k kv.Key, upperBound kv.Key) (kv.Iterator, error)

Iter overrides the Transaction interface.

func (*TxnState) IterReverse

func (st *TxnState) IterReverse(k kv.Key) (kv.Iterator, error)

IterReverse overrides the Transaction interface.

func (*TxnState) NewStagingBuffer

func (st *TxnState) NewStagingBuffer() kv.MemBuffer

NewStagingBuffer returns a new child write buffer.

func (*TxnState) Rollback

func (st *TxnState) Rollback() error

Rollback overrides the Transaction interface.

func (*TxnState) Set

func (st *TxnState) Set(k kv.Key, v []byte) error

Set overrides the Transaction interface.

func (*TxnState) Size

func (st *TxnState) Size() int

Size implements the MemBuffer interface.

func (*TxnState) String

func (st *TxnState) String() string

func (*TxnState) Valid

func (st *TxnState) Valid() bool

Valid implements the kv.Transaction interface.

type ZDBContext

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

func (*ZDBContext) AffectedRows

func (tc *ZDBContext) AffectedRows() uint64

func (*ZDBContext) Auth

func (tc *ZDBContext) Auth(user *auth.UserIdentity, auth []byte, salt []byte) bool

Auth implements QueryCtx Auth method.

func (*ZDBContext) Close

func (tc *ZDBContext) Close() error

Close implements QueryCtx Close method.

func (*ZDBContext) CommitTxn

func (tc *ZDBContext) CommitTxn(ctx context.Context) error

CommitTxn implements QueryCtx CommitTxn method.

func (*ZDBContext) CurrentDB

func (tc *ZDBContext) CurrentDB() string

CurrentDB implements QueryCtx CurrentDB method.

func (*ZDBContext) ExecuteStmt

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

ExecuteStmt implements QueryCtx interface.

func (*ZDBContext) FieldList

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

FieldList implements QueryCtx FieldList method.

func (*ZDBContext) GetHistorySQL

func (tc *ZDBContext) GetHistorySQL() string

func (*ZDBContext) GetSessionVars

func (tc *ZDBContext) GetSessionVars() *variable.SessionVars

func (*ZDBContext) GetStatement

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

GetStatement implements QueryCtx GetStatement method.

func (*ZDBContext) LastInsertID

func (tc *ZDBContext) LastInsertID() uint64

LastInsertID implements QueryCtx LastInsertID method.

func (*ZDBContext) LastMessage

func (tc *ZDBContext) LastMessage() string

LastMessage implements QueryCtx LastMessage method.

func (*ZDBContext) Parse

func (tc *ZDBContext) Parse(ctx context.Context, sql string) ([]ast.StmtNode, error)

Parse implements QueryCtx interface.

func (*ZDBContext) Prepare

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

Prepare implements QueryCtx Prepare method.

func (*ZDBContext) RollbackTxn

func (tc *ZDBContext) RollbackTxn()

RollbackTxn implements QueryCtx RollbackTxn method.

func (*ZDBContext) SetClientCapability

func (tc *ZDBContext) SetClientCapability(flags uint32)

SetClientCapability implements QueryCtx SetClientCapability method.

func (*ZDBContext) SetCommandValue

func (tc *ZDBContext) SetCommandValue(command byte)

SetCommandValue implements QueryCtx SetCommandValue method.

func (*ZDBContext) SetProcessInfo

func (tc *ZDBContext) SetProcessInfo(sql string, t time.Time, command byte, maxExecutionTime uint64)

SetProcessInfo implements QueryCtx SetProcessInfo method.

func (*ZDBContext) SetSessionManager

func (tc *ZDBContext) SetSessionManager(sm util.SessionManager)

SetSessionManager implements the QueryCtx interface.

func (*ZDBContext) SetValue

func (tc *ZDBContext) SetValue(key fmt.Stringer, value interface{})

SetValue implements QueryCtx SetValue method.

func (*ZDBContext) ShowProcess

func (tc *ZDBContext) ShowProcess() *util.ProcessInfo

ShowProcess implements QueryCtx ShowProcess method.

func (*ZDBContext) Status

func (tc *ZDBContext) Status() uint16

func (*ZDBContext) Value

func (tc *ZDBContext) Value(key fmt.Stringer) interface{}

Value implements QueryCtx Value method.

func (*ZDBContext) WarningCount

func (tc *ZDBContext) WarningCount() uint16

WarningCount implements QueryCtx WarningCount method.

type ZDBDriver

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

func NewZDBDriver

func NewZDBDriver(store kv.Storage) *ZDBDriver

func (*ZDBDriver) OpenCtx

func (qd *ZDBDriver) OpenCtx(connID uint64, capability uint32, collation uint8, dbname string, tlsState *tls.ConnectionState) (QueryCtx, error)

OpenCtx implements IDriver.

Jump to

Keyboard shortcuts

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