utils

package
v5.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzeTable

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

AnalyzeTable do 'ANALYZE TABLE `table`' SQL.

func CalculateChunkSize

func CalculateChunkSize(rowCount int64) int64

CalculateChunkSize returns chunkSize according to table rows count.

func CompareData

func CompareData(map1, map2 map[string]*dbutil.ColumnData, orderKeyCols, columns []*model.ColumnInfo) (equal bool, cmp int32, err error)

CompareData compare two row datas. equal = true: map1 = map2 equal = false:

  1. cmp = 0: map1 and map2 have the same orderkeycolumns, but other columns are in difference.
  2. cmp = -1: map1 < map2 (by comparing the orderkeycolumns)
  3. cmp = 1: map1 > map2

func CompareStruct

func CompareStruct(upstreamTableInfos []*model.TableInfo, downstreamTableInfo *model.TableInfo) (isEqual bool, isPanic bool)

CompareStruct compare tables' columns and indices from upstream and downstream. There are 2 return values:

isEqual	: result of comparing tables' columns and indices
isPanic	: the differences of tables' struct can not be ignored. Need to skip data comparing.

func EscapeName

func EscapeName(name string) string

EscapeName replaces all "`" in name with "“"

func GenerateDeleteDML

func GenerateDeleteDML(data map[string]*dbutil.ColumnData, table *model.TableInfo, schema string) string

GerateReplaceDMLWithAnnotation returns the delete SQL for the specific row.

func GenerateReplaceDML

func GenerateReplaceDML(data map[string]*dbutil.ColumnData, table *model.TableInfo, schema string) string

GenerateReplaceDML returns the insert SQL for the specific row values.

func GenerateReplaceDMLWithAnnotation

func GenerateReplaceDMLWithAnnotation(source, target map[string]*dbutil.ColumnData, table *model.TableInfo, schema string) string

GerateReplaceDMLWithAnnotation returns the replace SQL for the specific 2 rows. And add Annotations to show the different columns.

func GetApproximateMidBySize

func GetApproximateMidBySize(ctx context.Context, db *sql.DB, schema, table string, indexColumns []*model.ColumnInfo, limitRange string, args []interface{}, count int64) (map[string]string, error)

GetApproximateMidBySize return the `count`th row in rows that meet the `limitRange`.

func GetBetterIndex

func GetBetterIndex(ctx context.Context, db *sql.DB, schema, table string, tableInfo *model.TableInfo) ([]*model.IndexInfo, error)

GetBetterIndex returns the index more dinstict. If the index is primary key or unique, it can be return directly. Otherwise select the index which has higher value of `COUNT(DISTINCT a)/COUNT(*)`.

func GetChunkIDFromSQLFileName

func GetChunkIDFromSQLFileName(fileIDStr string) (int, int, int, int, error)

GetChunkIDFromSQLFileName convert the filename to chunk's `Index`.

func GetColumnsFromIndex

func GetColumnsFromIndex(index *model.IndexInfo, tableInfo *model.TableInfo) []*model.ColumnInfo

GetColumnsFromIndex returns `ColumnInfo`s of the specified index.

func GetCountAndCRC32Checksum

func GetCountAndCRC32Checksum(ctx context.Context, db *sql.DB, schemaName, tableName string, tbInfo *model.TableInfo, limitRange string, args []interface{}) (int64, int64, error)

GetCountAndCRC32Checksum returns checksum code and count of some data by given condition

func GetPDAddrs

func GetPDAddrs(ctx context.Context, db *sql.DB) ([]string, error)

GetPDAddrs gets PD address from TiDB

func GetPDClientForGC

func GetPDClientForGC(ctx context.Context, db *sql.DB) (pd.Client, error)

GetPDClientForGC is an initialization step.

func GetSQLFileName

func GetSQLFileName(index *chunk.ChunkID) string

GetSQLFileName returns filename of fix-SQL identified by chunk's `Index`.

func GetSelectivity

func GetSelectivity(ctx context.Context, db *sql.DB, schemaName, tableName, columnName string, tbInfo *model.TableInfo) (float64, error)

GetSelectivity returns the value of `COUNT(DISTINCT col)/COUNT(1)` SQL.

func GetSnapshot

func GetSnapshot(ctx context.Context, db *sql.DB) ([]string, error)

func GetSpecifiedColumnValueAndClose

func GetSpecifiedColumnValueAndClose(rows *sql.Rows, columnName string) ([]string, error)

GetSpecifiedColumnValueAndClose get columns' values whose name is equal to columnName and close the given rows

func GetTableRowsQueryFormat

func GetTableRowsQueryFormat(schema, table string, tableInfo *model.TableInfo, collation string) (string, []*model.ColumnInfo)

GetTableRowsQueryFormat returns a rowsQuerySQL template for the specific table.

e.g. SELECT /*!40001 SQL_NO_CACHE */ `a`, `b` FROM `schema`.`table` WHERE %s ORDER BY `a`.

func GetTableSize

func GetTableSize(ctx context.Context, db *sql.DB, schemaName, tableName string) (int64, error)

GetTableSize loads the TableSize from `information_schema`.`tables`.

func MinLenInSlices

func MinLenInSlices(slices [][]string) int

MinLenInSlices returns the smallest length among slices.

func NeedQuotes

func NeedQuotes(tp byte) bool

NeedQuotes determines whether an escape character is required for `'`.

func ResetColumns

func ResetColumns(tableInfo *model.TableInfo, columns []string) (*model.TableInfo, bool)

ResetColumns removes index from `tableInfo.Indices`, whose columns appear in `columns`. And removes column from `tableInfo.Columns`, which appears in `columns`. And initializes the offset of the column of each index to new `tableInfo.Columns`.

Return the new tableInfo and the flag whether the columns have timestamp type.

func SliceToMap

func SliceToMap(slice []string) map[string]interface{}

SliceToMap converts Slice to Set

func StartGCSavepointUpdateService

func StartGCSavepointUpdateService(ctx context.Context, pdCli pd.Client, db *sql.DB, snapshot string) error

StartGCSavepointUpdateService keeps GC safePoint stop moving forward.

func UniqueID

func UniqueID(schema string, table string) string

UniqueID returns `schema:table`

Types

type Worker

type Worker struct {
	ID uint64
}

Worker identified by ID.

type WorkerPool

type WorkerPool struct {
	// contains filtered or unexported fields
}

WorkerPool contains a pool of workers. The number of workers in the channel represents how many goruntines can be created to execute the task. After the task is done, worker will be sent back to the channel.

func NewWorkerPool

func NewWorkerPool(limit uint, name string) *WorkerPool

NewWorkerPool returns a WorkerPool with `limit` workers in the channel.

func (*WorkerPool) Apply

func (pool *WorkerPool) Apply(fn taskFunc)

Apply wait for an idle worker to run `taskFunc`. Notice: function `Apply` and `WaitFinished` cannot be called in parallel

func (*WorkerPool) HasWorker

func (pool *WorkerPool) HasWorker() bool

HasWorker checks if the pool has unallocated workers.

func (*WorkerPool) WaitFinished

func (pool *WorkerPool) WaitFinished()

WaitFinished waits till the pool finishs all the tasks.

Jump to

Keyboard shortcuts

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