Skip to content

Commit

Permalink
simplify the if/else logic (pingcap#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
lewgun authored and WangXiangUSTC committed Feb 11, 2019
1 parent 692f1f7 commit 2a0b5ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
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

0 comments on commit 2a0b5ad

Please sign in to comment.