util

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxRetries indicates the max retry count.
	DefaultMaxRetries = 30
	// RetryInterval indicates retry interval.
	RetryInterval uint64 = 500
)

Variables

This section is empty.

Functions

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

type OscProcessInfo struct {
	ID uint64
	// 连接ID
	ConnID uint64

	Schema     string
	Table      string
	Command    string
	Sqlsha1    string
	Percent    int
	RemainTime string
	Info       string

	Killed bool

	IsGhost bool
	Pause   bool

	PanicAbort chan ProcessOperation

	// gh-ost serve-socket-file
	SocketFile string

	RW *sync.RWMutex
}

OscProcessInfo is a struct used for show osc processlist statement.

type ProcessInfo

type ProcessInfo struct {
	ID      uint64
	User    string
	Host    string
	DB      string
	Command string
	Time    time.Time
	State   uint16
	Info    string
	Mem     int64

	// 操作目标信息
	DestUser string
	DestHost string
	DestPort int
	// 当前操作状态
	OperState string
	// 操作进度. 审核/执行/备份时自动计算
	Percent float64
}

ProcessInfo is a struct used for show processlist statement.

type ProcessOperation added in v1.2.3

type ProcessOperation int

ProcessOperation Process operation

const (
	ProcessOperationNone ProcessOperation = iota
	ProcessOperationKill
	ProcessOperationPause
	ProcessOperationResume
)

Process operation.

type SessionManager

type SessionManager interface {
	// ShowProcessList returns map[connectionID]ProcessInfo
	ShowProcessList() map[uint64]ProcessInfo
	Kill(connectionID uint64, query bool)

	// 添加osc进程
	AddOscProcess(p *OscProcessInfo)
	// 返回osc进程列表
	ShowOscProcessList() map[string]*OscProcessInfo
	ShowOscProcessListWithWrite() map[string]*OscProcessInfo
	OscLock()
	OscUnLock()
	// Kill当前会话的Osc进程
	KillOscProcess(connectionID uint64)
}

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

Directories

Path Synopsis
Package mock is just for test only.
Package mock is just for test only.

Jump to

Keyboard shortcuts

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