Skip to content

Commit

Permalink
Check the consistency with inequal boundary (#9)
Browse files Browse the repository at this point in the history
* Check the consistency with inequal boundary
* Fix for run into the end of table

Signed-off-by: JaySon-Huang <[email protected]>
  • Loading branch information
JaySon-Huang authored May 31, 2022
1 parent 87c877f commit fdbd866
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions cmd/check/rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,20 @@ func haveConsistNumOfRows(db *sql.DB, database, table, rowIdColName string, quer
return numRowsTiKV == numRowsTiFlash, err
}

func min(x, y int64) int64 {
if x < y {
return x
}
return y
}

func max(x, y int64) int64 {
if x > y {
return x
}
return y
}

func getInitQueryRange(db *sql.DB, opts checkRowsOpts) ([]QueryRange, error) {
var queryRanges []QueryRange
if opts.queryLowerBound == 0 && opts.queryUpperBound == 0 {
Expand All @@ -289,14 +303,16 @@ func getInitQueryRange(db *sql.DB, opts checkRowsOpts) ([]QueryRange, error) {

fmt.Printf("RowID range: [%d, %d] (tikv)\n", tikvMinID, tikvMaxID)
fmt.Printf("RowID range: [%d, %d] (tiflash)\n", tiflashMinID, tiflashMaxID)
allMinID := min(tikvMinID, tiflashMinID)
allMaxID := max(tikvMaxID, tiflashMaxID)
if tikvMinID != tiflashMinID {
panic(fmt.Sprintf("tikv min id %d != tiflash min id %d", tikvMinID, tiflashMinID))
fmt.Printf("tikv min id %d != tiflash min id %d, use %d as begin", tikvMinID, tiflashMinID, allMinID)
}
if tikvMaxID != tiflashMaxID {
panic(fmt.Sprintf("tikv max id %d != tiflash max id %d", tikvMaxID, tiflashMaxID))
fmt.Printf("tikv max id %d != tiflash max id %d, use %d as end", tikvMaxID, tiflashMaxID, allMaxID)
}

queryRanges = append(queryRanges, NewMinMax(tikvMinID, tikvMaxID+1))
queryRanges = append(queryRanges, NewMinMax(allMinID, allMaxID+1))
} else if opts.queryLowerBound != 0 && opts.queryUpperBound != 0 {
queryRanges = append(queryRanges, NewMinMax(opts.queryLowerBound, opts.queryUpperBound))
} else if opts.queryLowerBound != 0 {
Expand All @@ -310,6 +326,14 @@ func getInitQueryRange(db *sql.DB, opts checkRowsOpts) ([]QueryRange, error) {
func checkRowsByKey(db *sql.DB, opts checkRowsOpts, pdClient *pd.Client, key tidb.TiKVKey) error {
numSuccess := 0
for {
tableRow, err := key.GetTableRow()
if err != nil {
return err
} else if tableRow.Status == tidb.MaxInf {
// meet the end of this table, done
break
}

region, err := pdClient.GetRegionByKey(key)
if err != nil {
return err
Expand Down

0 comments on commit fdbd866

Please sign in to comment.