Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify the if/else logic #191

Merged
merged 2 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions pkg/diff/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *chunkRange) toString(mode string, collation string) (string, []string)

/* for example:
there is a bucket in TiDB, and the lowerbound and upperbound are (v1, v3), (v2, v4), and the columns are `a` and `b`,
this buceket's data range is (a > v1 or (a == v1 and b >= v2)) and (a < v3 or (a == v3 and a <= v4)),
this bucket's data range is (a > v1 or (a == v1 and b >= v2)) and (a < v3 or (a == v3 and a <= v4)),
not (a >= v1 and a <= v3 and b >= v2 and b <= v4)
*/

Expand Down Expand Up @@ -242,26 +242,28 @@ func (s *randomSpliter) splitRange(db *sql.DB, chunk *chunkRange, count int, sch
symbolMin = chunk.bounds[colNum-1].lowerSymbol
symbolMax = chunk.bounds[colNum-1].upperSymbol
} else {
// choose the next column to split data
if len(columns) > colNum {
useNewColumn = true
splitCol = columns[colNum].Name.O

min, max, err = dbutil.GetMinMaxValue(context.Background(), db, schema, table, splitCol, limitRange, utils.StringsToInterfaces(args), s.collation)
if err != nil {
if errors.Cause(err) == dbutil.ErrNoData {
log.Infof("no data found in %s.%s range %s, args %v", schema, table, limitRange, args)
return append(chunks, chunk), nil
}
return nil, errors.Trace(err)
}

symbolMin = gte
symbolMax = lte
} else {
if len(columns) <= colNum {
log.Warnf("chunk %v can't be splited", chunk)
return append(chunks, chunk), nil
}


// choose the next column to split data
useNewColumn = true
splitCol = columns[colNum].Name.O

min, max, err = dbutil.GetMinMaxValue(context.Background(), db, schema, table, splitCol, limitRange, utils.StringsToInterfaces(args), s.collation)
if err != nil {
if errors.Cause(err) == dbutil.ErrNoData {
log.Infof("no data found in %s.%s range %s, args %v", schema, table, limitRange, args)
return append(chunks, chunk), nil
}
return nil, errors.Trace(err)
}

symbolMin = gte
symbolMax = lte

}

splitValues := make([]string, 0, count)
Expand Down Expand Up @@ -359,10 +361,11 @@ func (s *randomSpliter) splitRange(db *sql.DB, chunk *chunkRange, count int, sch
} else {
if i == len(splitValues)-1 {
continue
} else {
upper = splitValues[i+1]
upperSymbol = lt
}

upper = splitValues[i+1]
upperSymbol = lt

}
}

Expand Down Expand Up @@ -462,11 +465,11 @@ func getChunksForTable(table *TableInstance, columns []*model.ColumnInfo, chunkS
if useTiDBStatsInfo {
s := bucketSpliter{}
chunks, err := s.split(table, columns, chunkSize, limits, collation)
if err != nil || len(chunks) == 0 {
log.Warnf("use tidb bucket information to get chunks error: %v, chunks num: %d, will split chunk by random again", errors.Trace(err), len(chunks))
} else {
if err == nil && len(chunks) > 0 {
return chunks, bucketMode, nil
}

log.Warnf("use tidb bucket information to get chunks error: %v, chunks num: %d, will split chunk by random again", errors.Trace(err), len(chunks))
}

// get chunks from tidb bucket information failed, use random.
Expand Down
10 changes: 7 additions & 3 deletions pkg/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,16 @@ func (t *TableDiff) CheckTableData(ctx context.Context) (bool, error) {
func (t *TableDiff) EqualTableData(ctx context.Context) (equal bool, err error) {
var allJobs []*CheckJob

table := t.TargetTable
useTiDB := false

if t.TiDBStatsSource != nil {
allJobs, err = GenerateCheckJob(t.TiDBStatsSource, t.Fields, t.Range, t.ChunkSize, t.Collation, true)
} else {
allJobs, err = GenerateCheckJob(t.TargetTable, t.Fields, t.Range, t.ChunkSize, t.Collation, false)
table = t.TiDBStatsSource
useTiDB = true
}

allJobs, err = GenerateCheckJob(table, t.Fields, t.Range, t.ChunkSize, t.Collation, useTiDB)

if err != nil {
return false, errors.Trace(err)
}
Expand Down