util

package
v0.0.0-...-3633c1a Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxRetries indicates the max retry count.
	DefaultMaxRetries = 30
	// RetryInterval indicates retry interval.
	RetryInterval uint64 = 500
	// GCTimeFormat is the format that gc_worker used to store times.
	GCTimeFormat = "20060102-15:04:05 -0700"
)

Variables

This section is empty.

Functions

func CompatibleParseGCTime

func CompatibleParseGCTime(value string) (time.Time, error)

CompatibleParseGCTime parses a string with `GCTimeFormat` and returns a time.Time. If `value` can't be parsed as that format, truncate to last space and try again. This function is only useful when loading times that saved by gc_worker. We have changed the format that gc_worker saves time (removed the last field), but when loading times it should be compatible with the old format.

func DelKeyWithPrefix

func DelKeyWithPrefix(rm kv.RetrieverMutator, prefix kv.Key) error

DelKeyWithPrefix deletes keys with prefix.

func GetStack

func GetStack() []byte

GetStack gets the stacktrace.

func RandomBuf

func RandomBuf(size int) []byte

RandomBuf generates a random string using ASCII characters but avoid separator character. See https://github.com/mysql/mysql-server/blob/5.7/mysys_ssl/crypt_genhash_impl.cc#L435

func RowKeyPrefixFilter

func RowKeyPrefixFilter(rowKeyPrefix kv.Key) kv.FnKeyCmp

RowKeyPrefixFilter returns a function which checks whether currentKey has decoded rowKeyPrefix as prefix.

func RunWithRetry

func RunWithRetry(retryCnt int, backoff uint64, f func() (bool, error)) (err error)

RunWithRetry will run the f with backoff and retry. retryCnt: Max retry count backoff: When run f failed, it will sleep backoff * triedCount time.Millisecond. Function f should have two return value. The first one is an bool which indicate if the err if retryable. The second is if the f meet any error.

func ScanMetaWithPrefix

func ScanMetaWithPrefix(retriever kv.Retriever, prefix kv.Key, filter func(kv.Key, []byte) bool) error

ScanMetaWithPrefix scans metadata with the prefix.

func SyntaxError

func SyntaxError(err error) error

SyntaxError converts parser error to TiDB's syntax error.

func SyntaxWarn

func SyntaxWarn(err error) error

SyntaxWarn converts parser warn to TiDB's syntax warn.

func WithRecovery

func WithRecovery(exec func(), recoverFn func(r interface{}))

WithRecovery wraps goroutine startup call with force recovery. it will dump current goroutine stack into log if catch any recover result.

exec:      execute logic function.
recoverFn: handler will be called after recover and before dump stack, passing `nil` means noop.

Types

type ProcessInfo

type ProcessInfo struct {
	ID                        uint64
	User                      string
	Host                      string
	DB                        interface{}
	Command                   byte
	Plan                      interface{}
	Time                      time.Time
	State                     uint16
	Info                      interface{}
	CurTxnStartTS             uint64
	StmtCtx                   *stmtctx.StatementContext
	StatsInfo                 func(interface{}) map[string]uint64
	ExceedExpensiveTimeThresh bool
	// MaxExecutionTime is the timeout for select statement, in milliseconds.
	// If the query takes too long, kill it.
	MaxExecutionTime uint64
}

ProcessInfo is a struct used for show processlist statement.

func (*ProcessInfo) ToRow

func (pi *ProcessInfo) ToRow() []interface{}

ToRow returns []interface{} for the row data of "SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST".

func (*ProcessInfo) ToRowForShow

func (pi *ProcessInfo) ToRowForShow(full bool) []interface{}

ToRowForShow returns []interface{} for the row data of "SHOW [FULL] PROCESSLIST".

type SessionManager

type SessionManager interface {
	ShowProcessList() map[uint64]*ProcessInfo
	GetProcessInfo(id uint64) (*ProcessInfo, bool)
	Kill(connectionID uint64, query bool)
}

SessionManager is an interface for session manage. Show processlist and kill statement rely on this interface.

Jump to

Keyboard shortcuts

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