utils

package
v0.9.71 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2020 License: Apache-2.0 Imports: 30 Imported by: 23

Documentation

Index

Constants

View Source
const GLOB = "*"

The character which is treated like a glob

Variables

View Source
var (
	Version   = "None"
	BuildTS   = "None"
	GitHash   = "None"
	GitBranch = "None"
)

Version information.

View Source
var TxnTagSQLFormat = fmt.Sprintf("insert into `%s`.`%s`", dbNameV2, tableNameV2)

Only for test purpose

Functions

func CastSliceInterfaceToSliceString added in v0.9.8

func CastSliceInterfaceToSliceString(a []interface{}) ([]string, error)

func CastToSlice added in v0.9.8

func CastToSlice(arg interface{}) (out []interface{}, ok bool)

arg can be slice of any type

func CheckBinlogFormat

func CheckBinlogFormat(db *sql.DB) error

CheckBinlogFormat checks binlog format

func CloseDBConnection

func CloseDBConnection(db *sql.DB) error

func CloseDBConnections

func CloseDBConnections(dbs ...*sql.DB)

func CompareBinlogPos

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

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

func Count added in v0.9.44

func Count(session *mgo.Session, db string, collection string) int64

func CreateDBConnection

func CreateDBConnection(cfg *config.DBConfig) (*sql.DB, error)

func CreateEtcdClient

func CreateEtcdClient(etcdEndpoints string) (*clientv3.Client, error)

func CreateMongoClient added in v0.9.44

func CreateMongoClient(cfg *config.MongoConnConfig) (*mongo.Client, error)

func CreateMongoSession added in v0.9.44

func CreateMongoSession(cfg *config.MongoConnConfig) (*mgo.Session, error)

func EstimateRowsCount

func EstimateRowsCount(db *sql.DB, schemaName string, tableName string) (int64, error)

func GenHashKey

func GenHashKey(key string) uint32

GenHashKey generates key with crc32 algorithm

func GenerateRandomServerID

func GenerateRandomServerID() uint32

func GenerateTxnTagSQL added in v0.9.4

func GenerateTxnTagSQL(pipelineName string) string

func GetExecutable added in v0.9.22

func GetExecutable(url string, dir string, name string) (string, error)

func GetIndexRows

func GetIndexRows(db *sql.DB, statement string) ([][]sql.NullString, error)

func GetLabelEnvString

func GetLabelEnvString() string

func GetLabelsFromEnv

func GetLabelsFromEnv(envString string) (map[string]string, error)

func GetPrimaryKeys

func GetPrimaryKeys(db *sql.DB, schemaName string, tableName string) ([]string, error)

func GetScanPtrSafe

func GetScanPtrSafe(columnIdx int, columnTypes []*sql.ColumnType, vPtrs []interface{}) (interface{}, error)

func GetScanType

func GetScanType(columnType *sql.ColumnType) reflect.Type

GetScanType returns better scan type than go-sql-driver/mysql

func GetServerTimezone

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

GetServerTimezone get timezone of the MySQL server.

func GetTables

func GetTables(db *sql.DB) ([]string, error)

func GetUniqueIndexesWithoutPks

func GetUniqueIndexesWithoutPks(db *sql.DB, schemaName string, tableName string) ([]string, error)

func Glob

func Glob(pattern, subj string) bool

Glob will test a string pattern, potentially containing globs, against a subject string. The result is a simple true/false, determining whether or not the glob pattern matched the subject text.

func InitInternalTxnTags added in v0.9.4

func InitInternalTxnTags(db *sql.DB) error

func IsBinlogPurgedError

func IsBinlogPurgedError(err error) bool

func IsCircularTrafficTag added in v0.9.58

func IsCircularTrafficTag(db string, tbl string) bool

func IsColumnFloat added in v0.9.55

func IsColumnFloat(columnType *sql.ColumnType) bool

float, double is already handled https://github.com/go-sql-driver/mysql/blob/master/fields.go#L166

func IsColumnString

func IsColumnString(columnType *sql.ColumnType) bool

We need to look at this file to check each type https://github.com/go-sql-driver/mysql/blob/master/fields.go

func IsDeadSignal added in v0.9.44

func IsDeadSignal(op *gtm.Op, pipeline string) bool

func IsEmpty added in v0.9.44

func IsEmpty(session *mgo.Session, db string, collection string) bool

func IsTableEmpty added in v0.9.17

func IsTableEmpty(db *sql.DB, schema string, table string, condition string) bool

func IsTiDB added in v0.9.22

func IsTiDB(db *sql.DB) bool

func ListAllUserCollections added in v0.9.44

func ListAllUserCollections(session *mgo.Session) map[string][]string

func LogRawInfo

func LogRawInfo(app string)

LogRotate prints the version information.

func MustAny2Map added in v0.9.35

func MustAny2Map(i interface{}) (ret map[string]interface{})

func MustCreateEtcdClient

func MustCreateEtcdClient(etcdEndpoints string) *clientv3.Client

func MustGetLabelsFromEnv

func MustGetLabelsFromEnv() map[string]string

func NewBinlogSyncer

func NewBinlogSyncer(serverID uint32, dbConfig *config.DBConfig, heartbeatPeriod time.Duration) *replication.BinlogSyncer

func NewBoolPtr

func NewBoolPtr(b bool) *bool

func NewStringPtr

func NewStringPtr(s string) *string

func PrintRawInfo

func PrintRawInfo(app string)

PrintRawInfo prints the version information without log info.

func QueryGeneralRowsDataWithSQL

func QueryGeneralRowsDataWithSQL(db *sql.DB, statement string, args ...interface{}) ([][]interface{}, error)

func SQLWithAnnotation

func SQLWithAnnotation(annotation string, sql string) string

func ScanGeneralRows

func ScanGeneralRows(rows *sql.Rows, columnTypes []*sql.ColumnType) ([]interface{}, error)

func ScanGeneralRowsWithDataPtrs

func ScanGeneralRowsWithDataPtrs(rows *sql.Rows, columnTypes []*sql.ColumnType, vPtrs []interface{}) ([]interface{}, error)

func SendDeadSignal added in v0.9.44

func SendDeadSignal(session *mgo.Session, pipeline string) error

func TableIdentity

func TableIdentity(schemaName string, tableName string) string

func TakeArg added in v0.9.8

func TakeArg(arg interface{}, kind reflect.Kind) (val reflect.Value, ok bool)

func TestCaseMd5Name added in v0.9.17

func TestCaseMd5Name(t *testing.T) string

func TestConfig

func TestConfig() *config.DBConfig

Types

type Closer

type Closer interface {
	Close()
}

type MinMax added in v0.9.44

type MinMax struct {
	Min interface{}
	Max interface{}
}

func BucketAuto added in v0.9.44

func BucketAuto(session *mgo.Session, db string, collection string, sampleCnt int, bucketCnt int) ([]MinMax, error)

func GetMinMax added in v0.9.44

func GetMinMax(session *mgo.Session, db string, collection string) (MinMax, error)

type MySQLDB

type MySQLDB struct {
	*sql.DB
}

func NewMySQLDB

func NewMySQLDB(db *sql.DB) MySQLDB

func (MySQLDB) GetMasterStatus

func (db MySQLDB) GetMasterStatus() (gomysql.Position, gomysql.MysqlGTIDSet, error)

func (MySQLDB) GetServerUUID

func (db MySQLDB) GetServerUUID() (string, error)

type MySQLStatusGetter

type MySQLStatusGetter interface {
	GetMasterStatus() (gomysql.Position, gomysql.MysqlGTIDSet, error)
	GetServerUUID() (string, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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