util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: Apache-2.0 Imports: 15 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecWithRollback

func ExecWithRollback(db *sql.DB, queries []QueryEntry) (res sql.Result, err error)

ExecWithRollback executes or rollback

func Hashfnv32a

func Hashfnv32a(b []byte) uint32

Hashfnv32a returns 32-bit FNV-1a hash for a byte slice

func IgnoreErrors

func IgnoreErrors(err error, ignoreErrs []terror.ErrCode) bool

IgnoreErrors returs true if ignoreErrs contains err

func InstallArchive

func InstallArchive(ctx context.Context, rawURL string, dest string) error

InstallArchive downloads the URL and extracts the archive to the dest diretory. Supports zip, and tarball.

func IsErrDupEntry

func IsErrDupEntry(err error) bool

IsErrDupEntry returns true if error code = 1062

func IsErrTableNotExists

func IsErrTableNotExists(err error) bool

IsErrTableNotExists checks whether err is TableNotExists error

func IsFileExist

func IsFileExist(name string) bool

IsFileExist returns true if the file exists.

func MustExec

func MustExec(db *sql.DB, query string, args ...interface{}) sql.Result

MustExec must execute sql or fatal

func OpenDB

func OpenDB(dsn string, maxIdleConns int) (*sql.DB, error)

OpenDB opens a db

func RandomlyChangeReplicaRead

func RandomlyChangeReplicaRead(job, replicaRead string, db *sql.DB)

RandomlyChangeReplicaRead changes `tidb_replica_read` randomly in a session.

func RunWithRetry

func RunWithRetry(ctx context.Context, retryCnt int, interval time.Duration, f func() error) error

RunWithRetry tries to run func in specified count

func Wget

func Wget(ctx context.Context, rawURL string, dest string) (string, error)

Wget downloads a string URL to the dest directory and returns the file path. SKips if the file already exists.

Types

type QueryEntry

type QueryEntry struct {
	Query              string
	Args               []interface{}
	ExpectAffectedRows int64
}

QueryEntry is a query

Jump to

Keyboard shortcuts

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