// EqualTableData checks data is equal or not.
EqualTableData checks data is equal or not.
// EqualTableData checks data is equal or not .
func (df *Diff) EqualTableData(table *TableCheckCfg) (bool, error) {
	allJobs, err := GenerateCheckJob(df.db1, df.schema, table.Info, table.Field, table.Range, df.chunkSize, df.sample, df.useRowID)
	if err != nil {
		return false, errors.Trace(err)
	}
	checkNums := len(allJobs) * df.sample / 100
	checkNumArr := getRandomN(len(allJobs), checkNums)
	log.Infof("total has %d check jobs, check %+v", len(allJobs), checkNumArr)
	checkResultCh := make(chan bool, df.checkThreadCount)
	defer close(checkResultCh)
	for i := 0; i < df.checkThreadCount; i++ {
		checkJobs := make([]*CheckJob, 0, len(checkNumArr))
		for j := len(checkNumArr) * i / df.checkThreadCount; j < len(checkNumArr)*(i+1)/df.checkThreadCount && j < len(checkNumArr); j++ {
			checkJobs = append(checkJobs, allJobs[checkNumArr[j]])
		}
		go func() {
			eq, err := df.checkChunkDataEqual(checkJobs, table)
			if err != nil {
				log.Errorf("check chunk data equal failed, error %v", errors.ErrorStack(err))
			}
			checkResultCh <- eq
		}()
	}
	num := 0
	equal := true
CheckResult:
	for {
		select {
		case eq := <-checkResultCh:
			num++
			if !eq {
				equal = false
			}
			if num == df.checkThreadCount {
				break CheckResult
			}
		case <-df.ctx.Done():
			return equal, nil
		}
	}
	return equal, nil
}
func ( df * Diff ) EqualTableData ( table * TableCheckCfg ) ( bool , error ) { allJobs , err := GenerateCheckJob ( df . db1 , df . schema , table . Info , table . Field , table . Range , df . chunkSize , df . sample , df . useRowID ) if err != nil { return false , errors . Trace ( err ) } checkNums := len ( allJobs ) * df . sample / 100 checkNumArr := getRandomN ( len ( allJobs ) , checkNums ) log . Infof ( " " , len ( allJobs ) , checkNumArr ) checkResultCh := make ( chan bool , df . checkThreadCount ) defer close ( checkResultCh ) for i := 0 ; i < df . checkThreadCount ; i ++ { checkJobs := make ( [ ] * CheckJob , 0 , len ( checkNumArr ) ) for j := len ( checkNumArr ) * i / df . checkThreadCount ; j < len ( checkNumArr ) * ( i + 1 ) / df . checkThreadCount && j < len ( checkNumArr ) ; j ++ { checkJobs = append ( checkJobs , allJobs [ checkNumArr [ j ] ] ) } go func ( ) { eq , err := df . checkChunkDataEqual ( checkJobs , table ) if err != nil { log . Errorf ( " " , errors . ErrorStack ( err ) ) } checkResultCh <- eq } ( ) } num := 0 equal := true CheckResult : for { select { case eq := <- checkResultCh : num ++ if ! eq { equal = false } if num == df . checkThreadCount { break CheckResult } case <- df . ctx . Done ( ) : return equal , nil } } return equal , nil }
EqualTableData checks data is equal or not.
EqualTableData checks data is equal or not .
// TODO: now only check data between source data's min and max, need check data less than min and greater than max.