// GenerateCheckJob generates some CheckJobs.
GenerateCheckJob generates some CheckJobs.
// GenerateCheckJob generates some CheckJobs .
func GenerateCheckJob(db *sql.DB, Schema string, table *model.TableInfo, splitField string,
	limitRange string, chunkSize int, sample int, useRowID bool) ([]*CheckJob, error) {
	jobBucket := make([]*CheckJob, 0, 10)
	var jobCnt int
	var column *model.ColumnInfo
	var err error
	if splitField == "" {
		column, err = findSuitableField(db, Schema, table)
		if err != nil {
			return nil, errors.Trace(err)
		}
	} else {
		column = dbutil.FindColumnByName(table.Columns, splitField)
		if column == nil {
			return nil, errors.NotFoundf("column %s in table %s", splitField, table.Name.O)
		}
	}
	if limitRange == "" {
		limitRange = "true"
	}
	chunks, err := getChunksForTable(db, Schema, table.Name.O, column, limitRange, chunkSize, sample)
	if err != nil {
		return nil, errors.Trace(err)
	}
	if chunks == nil {
		return nil, nil
	}
	log.Debugf("chunks: %+v", chunks)
	jobCnt += len(chunks)
	for {
		length := len(chunks)
		if length == 0 {
			break
		}
		chunk := chunks[0]
		chunks = chunks[1:]
		gt := ">"
		lt := "<"
		if chunk.containBegin {
			gt = ">="
		}
		if chunk.containEnd {
			lt = "<="
		}
		where := fmt.Sprintf("(`%s` %s ? AND `%s` %s ? AND %s)", column.Name, gt, column.Name, lt, limitRange)
		log.Debugf("%s.%s create dump job, where: %s, begin: %v, end: %v", Schema, table.Name.O, where, chunk.begin, chunk.end)
		jobBucket = append(jobBucket, &CheckJob{
			Schema: Schema,
			Table:  table.Name.O,
			Column: column,
			Where:  where,
			Args:   []interface{}{chunk.begin, chunk.end},
			Chunk:  chunk,
		})
	}
	return jobBucket, nil
}
func GenerateCheckJob ( db * sql . DB , Schema string , table * model . TableInfo , splitField string , limitRange string , chunkSize int , sample int , useRowID bool ) ( [ ] * CheckJob , error ) { jobBucket := make ( [ ] * CheckJob , 0 , 10 ) var jobCnt int var column * model . ColumnInfo var err error if splitField == " " { column , err = findSuitableField ( db , Schema , table ) if err != nil { return nil , errors . Trace ( err ) } } else { column = dbutil . FindColumnByName ( table . Columns , splitField ) if column == nil { return nil , errors . NotFoundf ( " " , splitField , table . Name . O ) } } if limitRange == " " { limitRange = " " } chunks , err := getChunksForTable ( db , Schema , table . Name . O , column , limitRange , chunkSize , sample ) if err != nil { return nil , errors . Trace ( err ) } if chunks == nil { return nil , nil } log . Debugf ( " " , chunks ) jobCnt += len ( chunks ) for { length := len ( chunks ) if length == 0 { break } chunk := chunks [ 0 ] chunks = chunks [ 1 : ] gt := " " lt := " " if chunk . containBegin { gt = " " } if chunk . containEnd { lt = " " } where := fmt . Sprintf ( " " , column . Name , gt , column . Name , lt , limitRange ) log . Debugf ( " " , Schema , table . Name . O , where , chunk . begin , chunk . end ) jobBucket = append ( jobBucket , & CheckJob { Schema : Schema , Table : table . Name . O , Column : column , Where : where , Args : [ ] interface { } { chunk . begin , chunk . end } , Chunk : chunk , } ) } return jobBucket , nil }
GenerateCheckJob generates some CheckJobs.
GenerateCheckJob generates some CheckJobs .
// find a column for split data // setting limitRange to "true" can make the code more simple, no need to judge the limitRange's value. // for example: sql will looks like "select * from itest where a > 10 AND true" if don't set range in config.