util

package
v0.0.0-...-c6d3014 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger = log.L()
View Source
var ParserPool = sync.Pool{
	New: func() any {
		return parser.New()
	},
}

Functions

func AtomicWrite

func AtomicWrite(path string, content []byte) error

AtomicWrite writes content to path atomically by using mv.

func ConnectDB

func ConnectDB(
	host string,
	port int,
	user string,
	password string,
) (*sql.DB, error)

ConnectDB connects to a MySQL database.

func EscapeIdentifier

func EscapeIdentifier(s string) string

EscapeIdentifier escapes an MySQL identifier. TODO(lance6716): not all callers use it. And we can't process special characters?

func EscapePath

func EscapePath(input string) string

EscapePath encodes special characters in a string to make it safe for use as a file system path.

func ExtractTableNames

func ExtractTableNames(s ast.Node, currDB string) [][2]string

ExtractTableNames extracts all table names from a statement node.

func IsMemOrSysTable

func IsMemOrSysTable(dbTable [2]string) bool

func IsSQLErrorUnretryable

func IsSQLErrorUnretryable(err *mysql.MySQLError) bool

IsSQLErrorUnretryable checks the MySQL error to determine if it is unretryable. For errors we don't have confidence, we assume it is retryable so caller will execute the statement again in future.

func IsUnretryableError

func IsUnretryableError(err error) bool

IsUnretryableError checks if an error is wrapped by WrapUnretryableError. It supports pingcap/errors package.

func ReadCreateDatabase

func ReadCreateDatabase(
	ctx context.Context,
	db *sql.DB,
	dbName string,
) (string, error)

func ReadCreateTableViewSeq

func ReadCreateTableViewSeq(
	ctx context.Context,
	db *sql.DB,
	dbName, tableViewSeqName string,
) (string, error)

ReadCreateTableViewSeq reads the CREATE TABLE / VIEW / SEQUENCE statement from the database.

func ReadStrRowsByColumnName

func ReadStrRowsByColumnName(
	rows *sql.Rows,
	columnNames []string,
) (fields [][]string, allFound bool, err error)

ReadStrRowsByColumnName reads given columns from sql.Rows. If not all columns are found, allFound will be false, given sql.Rows will not be read. Caller need to close rows after it returns.

func WrapUnretryableError

func WrapUnretryableError(err error) error

WrapUnretryableError wraps an error to make it unretryable.

Types

type ClusterInfo

type ClusterInfo struct {
	TiDBCnt     int
	TiDBVersion string
	PDVersion   string
	TiKVVersion string
}

func ReadClusterInfo

func ReadClusterInfo(ctx context.Context, db *sql.DB) (*ClusterInfo, error)

ReadClusterInfo reads the cluster information from the TiDB cluster.

Jump to

Keyboard shortcuts

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