utils

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 34 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ReleaseVersion = "None"
	BuildTS        = "None"
	GitHash        = "None"
	GitBranch      = "None"
	GoVersion      = "None"
)

Version information.

View Source
var (
	UUIDIndexFilename = "server-uuid.index"
	MetaFilename      = "relay.meta"
)

not support to config yet

View Source
var (
	// OsExit is function placeholder for os.Exit
	OsExit func(int)
)

Functions

func AddSuffixForUUID

func AddSuffixForUUID(uuid string, ID int) string

AddSuffixForUUID adds a suffix for UUID

func CompareBinlogPos

func CompareBinlogPos(a, b mysql.Position, deviation float64) int

CompareBinlogPos compares binlog positions. The result will be 0 if |a-b| < deviation, otherwise -1 if a < b, and +1 if a > b.

func CompareShardingDDLs

func CompareShardingDDLs(s, t []string) bool

CompareShardingDDLs compares s and t ddls only concern in content, ignore order of ddl

func DecodeBinlogPosition

func DecodeBinlogPosition(pos string) (*mysql.Position, error)

DecodeBinlogPosition parses a mysql.Position from string format

func Decrypt

func Decrypt(ciphertextB64 string) (string, error)

Decrypt tries to decrypt base64 encoded ciphertext to plaintext

func DecryptOrPlaintext added in v1.0.6

func DecryptOrPlaintext(ciphertextB64 string) string

DecryptOrPlaintext tries to decrypt base64 encoded ciphertext to plaintext or return plaintext

func Encrypt

func Encrypt(plaintext string) (string, error)

Encrypt tries to encrypt plaintext to base64 encoded ciphertext

func ExtractTable

func ExtractTable(name string) (string, string, error)

ExtractTable extracts schema and table from `schema`.`table`

func FetchAllDoTables

func FetchAllDoTables(db *sql.DB, bw *filter.Filter) (map[string][]string, error)

FetchAllDoTables returns all need to do tables after filtered (fetches from upstream MySQL)

func FetchTargetDoTables

func FetchTargetDoTables(db *sql.DB, bw *filter.Filter, router *router.Table) (map[string][]*filter.Table, error)

FetchTargetDoTables returns all need to do tables after filtered and routed (fetches from upstream MySQL)

func GenFakeRotateEvent

func GenFakeRotateEvent(nextLogName string, logPos uint64, serverID uint32) (*replication.BinlogEvent, error)

GenFakeRotateEvent generates a fake ROTATE_EVENT without checksum ref: https://github.com/mysql/mysql-server/blob/4f1d7cf5fcb11a3f84cff27e37100d7295e7d5ca/sql/rpl_binlog_sender.cc#L855

func GenHashKey

func GenHashKey(key string) uint32

GenHashKey generates key with crc32 algorithm

func GenTableKey

func GenTableKey(schema, table string) string

GenTableKey generates a key for table

func GetAllServerID added in v1.0.2

func GetAllServerID(ctx context.Context, db *sql.DB) (map[uint32]struct{}, error)

GetAllServerID gets all slave server id and master server id

func GetFileSize

func GetFileSize(file string) (int64, error)

GetFileSize return the size of the file.

func GetFlavor added in v1.0.2

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

GetFlavor gets flavor from DB

func GetGlobalVariable

func GetGlobalVariable(db *sql.DB, variable string) (value string, err error)

GetGlobalVariable gets server's global variable

func GetMariaDBGTID

func GetMariaDBGTID(db *sql.DB) (gtid.Set, error)

GetMariaDBGTID gets MariaDB's `gtid_binlog_pos` it can not get by `SHOW MASTER STATUS`

func GetMariaDBGtidDomainID

func GetMariaDBGtidDomainID(db *sql.DB) (uint32, error)

GetMariaDBGtidDomainID gets MariaDB server's `gtid_domain_id`

func GetMariaDBUUID

func GetMariaDBUUID(db *sql.DB) (string, error)

GetMariaDBUUID gets equivalent `server_uuid` for MariaDB `gtid_domain_id` joined `server_id` with domainServerIDSeparator

func GetMasterStatus

func GetMasterStatus(db *sql.DB, flavor string) (gmysql.Position, gtid.Set, error)

GetMasterStatus gets status from master

func GetParser

func GetParser(db *sql.DB, ansiQuotesMode bool) (*parser.Parser, error)

GetParser gets a parser which maybe enabled `ANSI_QUOTES` sql_mode

func GetRawInfo

func GetRawInfo() string

GetRawInfo do what its name tells

func GetSQLMode

func GetSQLMode(db *sql.DB) (tmysql.SQLMode, error)

GetSQLMode returns sql_mode.

func GetServerID

func GetServerID(db *sql.DB) (uint32, error)

GetServerID gets server's `server_id`

func GetServerUUID

func GetServerUUID(db *sql.DB, flavor string) (string, error)

GetServerUUID gets server's `server_uuid`

func GetSlaveServerID added in v1.0.2

func GetSlaveServerID(ctx context.Context, db *sql.DB) (map[uint32]struct{}, error)

GetSlaveServerID gets all slave server id

func GetSuffixUUID

func GetSuffixUUID(indexPath, uuid string) (string, error)

GetSuffixUUID gets UUID (with suffix) by UUID (without suffix) when multi UUIDs (without suffix) are the same, the newest will be return

func GetUUIDBySuffix

func GetUUIDBySuffix(uuids []string, suffix string) string

GetUUIDBySuffix gets UUID from uuids by suffix

func HasAnsiQuotesMode

func HasAnsiQuotesMode(db *sql.DB) (bool, error)

HasAnsiQuotesMode checks whether database has `ANSI_QUOTES` set

func IsBuildInSkipDDL added in v1.0.3

func IsBuildInSkipDDL(sql string) bool

IsBuildInSkipDDL return true when checked sql that will be skipped for syncer

func IsContextCanceledError added in v1.0.3

func IsContextCanceledError(err error) bool

IsContextCanceledError checks whether err is context.Canceled

func IsDirExists

func IsDirExists(name string) bool

IsDirExists checks if dir exists.

func IsErrBinlogPurged

func IsErrBinlogPurged(err error) bool

IsErrBinlogPurged checks whether err is BinlogPurged error

func IsFileExists

func IsFileExists(name string) bool

IsFileExists checks if file exists.

func IsMySQLError

func IsMySQLError(err error, code uint16) bool

IsMySQLError checks whether err is MySQLError error

func IsNoSuchThreadError

func IsNoSuchThreadError(err error) bool

IsNoSuchThreadError checks whether err is NoSuchThreadError

func JoinProcessErrors added in v1.0.4

func JoinProcessErrors(errors []*pb.ProcessError) string

JoinProcessErrors return the string of pb.ProcessErrors joined by ", "

func KillConn

func KillConn(db *sql.DB, connID uint32) error

KillConn kills the DB connection (thread in mysqld)

func ParseMetaData

func ParseMetaData(filename string) (*mysql.Position, error)

ParseMetaData parses mydumper's output meta file and returns binlog position

func ParseSuffixForUUID

func ParseSuffixForUUID(uuid string) (string, int, error)

ParseSuffixForUUID parses UUID (with suffix) to (UUID without suffix, suffix) pair

func ParseUUIDIndex

func ParseUUIDIndex(indexPath string) ([]string, error)

ParseUUIDIndex parses server-uuid.index

func PrintInfo

func PrintInfo(app string, callback func())

PrintInfo prints some information of the app, like git hash, binary build time, etc.

func PrintInfo2

func PrintInfo2(app string)

PrintInfo2 print app's info to stdout

func SuffixIntToStr

func SuffixIntToStr(ID int) string

SuffixIntToStr convert int-represented suffix to string-represented

func TrimCtrlChars

func TrimCtrlChars(s string) string

TrimCtrlChars returns a slice of the string s with all leading and trailing control characters removed.

func TruncateInterface

func TruncateInterface(v interface{}, n int) string

TruncateInterface converts the interface to a string and returns a string with only the leading (at most) n runes of the input string. If the converted string is truncated, a `...` tail will be appended. It is not effective for large structure now.

func TruncateString

func TruncateString(s string, n int) string

TruncateString returns a string with only the leading (at most) n runes of the input string. If the string is truncated, a `...` tail will be appended.

func WaitSomething

func WaitSomething(backoff int, waitTime time.Duration, fn func() bool) bool

WaitSomething waits for something done with `true`.

Types

type StorageSize

type StorageSize struct {
	Capacity  uint64
	Available uint64
}

StorageSize represents the storage's capacity and available size Learn from tidb-binlog source code.

func GetStorageSize

func GetStorageSize(dir string) (size StorageSize, err error)

GetStorageSize gets storage's capacity and available size

Jump to

Keyboard shortcuts

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