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

diff: add config to only use checksum, skip select data #215

Merged
merged 5 commits into from
Apr 2, 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
8 changes: 8 additions & 0 deletions pkg/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type TableDiff struct {
// set false if want to comapre the data directly
UseChecksum bool

// set true if just want compare data by checksum, will skip select data when checksum is not equal
OnlyUseChecksum bool

// collation config in mysql/tidb, should corresponding to charset.
Collation string

Expand Down Expand Up @@ -285,6 +288,11 @@ func (t *TableDiff) checkChunkDataEqual(ctx context.Context, checkJobs []*CheckJ
log.Warn("checksum is not equal", zap.String("table", dbutil.TableName(job.Schema, job.Table)), zap.String("where", job.Where), zap.Reflect("args", job.Args), zap.Int64("source checksum", sourceChecksum), zap.Int64("target checksum", targetChecksum))
}

if t.UseChecksum && t.OnlyUseChecksum {
equal = false
continue
}

// if checksum is not equal or don't need compare checksum, compare the data
log.Info("select data and then check data", zap.String("table", dbutil.TableName(job.Schema, job.Table)), zap.String("where", job.Where), zap.Reflect("args", job.Args))
sourceRows := make(map[string][]map[string]*dbutil.ColumnData)
Expand Down
15 changes: 15 additions & 0 deletions sync_diff_inspector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ type Config struct {
// set false if want to comapre the data directly
UseChecksum bool `toml:"use-checksum" json:"use-checksum"`

// set true if just want compare data by checksum, will skip select data when checksum is not equal.
OnlyUseChecksum bool `toml:"only-use-checksum" json:"only-use-checksum"`

// the name of the file which saves sqls used to fix different data
FixSQLFile string `toml:"fix-sql-file" json:"fix-sql-file"`

Expand Down Expand Up @@ -313,5 +316,17 @@ func (c *Config) checkConfig() bool {
}
}

if c.OnlyUseChecksum {
if !c.UseChecksum {
log.Error("need set use-checksum = true")
csuzhangxc marked this conversation as resolved.
Show resolved Hide resolved
return false
}
} else {
if len(c.FixSQLFile) == 0 {
WangXiangUSTC marked this conversation as resolved.
Show resolved Hide resolved
log.Warn("fix-sql-file is invalid, will use default value 'fix.sql'")
c.FixSQLFile = "fix.sql"
}
}

return true
}
6 changes: 5 additions & 1 deletion sync_diff_inspector/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ sample-percent = 100
use-rowid = false

# calculate the data's checksum, and compare data by checksum.
# set false if want to comapre the data directly
use-checksum = true

# set true if just want compare data by checksum, will skip select data when checksum is not equal.
only-use-checksum = false

# ignore check table's data
ignore-data-check = false

# ignore check table's struct
ignore-struct-check = false

# the name of the file which saves sqls used to fix different data
# the name of the file which saves sqls used to fix different data.
fix-sql-file = "fix.sql"

# use this tidb's statistics information to split chunk
Expand Down
3 changes: 3 additions & 0 deletions sync_diff_inspector/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Diff struct {
checkThreadCount int
useRowID bool
useChecksum bool
onlyUseChecksum bool
ignoreDataCheck bool
ignoreStructCheck bool
tables map[string]map[string]*TableConfig
Expand All @@ -57,6 +58,7 @@ func NewDiff(ctx context.Context, cfg *Config) (diff *Diff, err error) {
checkThreadCount: cfg.CheckThreadCount,
useRowID: cfg.UseRowID,
useChecksum: cfg.UseChecksum,
onlyUseChecksum: cfg.OnlyUseChecksum,
ignoreDataCheck: cfg.IgnoreDataCheck,
ignoreStructCheck: cfg.IgnoreStructCheck,
tidbInstanceID: cfg.TiDBInstanceID,
Expand Down Expand Up @@ -405,6 +407,7 @@ func (df *Diff) Equal() (err error) {
CheckThreadCount: df.checkThreadCount,
UseRowID: df.useRowID,
UseChecksum: df.useChecksum,
OnlyUseChecksum: df.onlyUseChecksum,
IgnoreStructCheck: df.ignoreStructCheck,
IgnoreDataCheck: df.ignoreDataCheck,
TiDBStatsSource: tidbStatsSource,
Expand Down