-
Notifications
You must be signed in to change notification settings - Fork 198
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
sync-diff-inspector: skip validation for tables that exist only upstream or downstream and print skipped information in summary and progress #693
Changes from 1 commit
aa34581
1e47104
d8c7f6d
72a2bb6
5b586f6
54dc8df
f701426
5a42342
54e2ab9
8a0f59f
4736864
3f254c8
5af05c2
b928386
a8b82a9
34293bb
03b86f3
8581b7b
a637154
8d7c343
4d78f73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,8 +297,8 @@ func (df *Diff) StructEqual(ctx context.Context) error { | |
tableIndex = df.startRange.ChunkRange.Index.TableIndex | ||
} | ||
for ; tableIndex < len(tables); tableIndex++ { | ||
isEqual, isSkip, isAllTableExist := false, true, tables[tableIndex].NeedSkippedTable | ||
if source.AllTableExist(tables[tableIndex]) { | ||
isEqual, isSkip, isAllTableExist := false, true, tables[tableIndex].TableLack | ||
if common.AllTableExist(tables[tableIndex].TableLack) { | ||
var err error | ||
isEqual, isSkip, err = df.compareStruct(ctx, tableIndex) | ||
if err != nil { | ||
|
@@ -421,9 +421,9 @@ func (df *Diff) consume(ctx context.Context, rangeInfo *splitter.RangeInfo) bool | |
if rangeInfo.ChunkRange.Type == chunk.Empty { | ||
dml.node.State = checkpoints.IgnoreState | ||
// for tables that don't exist upstream or downstream | ||
if !source.AllTableExist(tableDiff) { | ||
upCount, _ := dbutil.GetRowCount(ctx, df.upstream.GetDB(), schema, table, "", nil) | ||
downCount, _ := dbutil.GetRowCount(ctx, df.downstream.GetDB(), schema, table, "", nil) | ||
if !common.AllTableExist(tableDiff.TableLack) { | ||
upCount := df.upstream.GetCountAndCrc32(ctx, rangeInfo).Count | ||
downCount := df.downstream.GetCountAndCrc32(ctx, rangeInfo).Count | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only need count here. However, this function will also compute checksum. I'm afraid this will affect the efficiency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. I defined a new interface |
||
df.report.SetTableDataCheckResult(schema, table, false, int(upCount), int(downCount), upCount, downCount, id) | ||
return false | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -69,7 +69,7 @@ func getMatchedSourcesForTable(sourceTablesMap map[string][]*common.TableShardSo | |||||||||||
log.Fatal("unreachable, source tables map shouldn't be nil.") | ||||||||||||
} | ||||||||||||
matchSources, ok := sourceTablesMap[utils.UniqueID(table.Schema, table.Table)] | ||||||||||||
if !ok { | ||||||||||||
if !ok && common.AllTableExist(table.TableLack) { | ||||||||||||
log.Fatal("unreachable, no match source tables in mysql shard source.") | ||||||||||||
} | ||||||||||||
return matchSources | ||||||||||||
|
@@ -97,42 +97,44 @@ func (s *MySQLSources) GetCountAndCrc32(ctx context.Context, tableRange *splitte | |||||||||||
beginTime := time.Now() | ||||||||||||
table := s.tableDiffs[tableRange.GetTableIndex()] | ||||||||||||
chunk := tableRange.GetChunk() | ||||||||||||
|
||||||||||||
// for tables that do not exist upstream or downstream | ||||||||||||
if !AllTableExist(table) { | ||||||||||||
return &ChecksumInfo{ | ||||||||||||
Count: 0, | ||||||||||||
} | ||||||||||||
} | ||||||||||||
matchSources := getMatchedSourcesForTable(s.sourceTablesMap, table) | ||||||||||||
infoCh := make(chan *ChecksumInfo, len(s.sourceTablesMap)) | ||||||||||||
|
||||||||||||
for _, ms := range matchSources { | ||||||||||||
go func(ms *common.TableShardSource) { | ||||||||||||
count, checksum, err := utils.GetCountAndCRC32Checksum(ctx, ms.DBConn, ms.OriginSchema, ms.OriginTable, table.Info, chunk.Where, chunk.Args) | ||||||||||||
infoCh <- &ChecksumInfo{ | ||||||||||||
Checksum: checksum, | ||||||||||||
Count: count, | ||||||||||||
Err: err, | ||||||||||||
} | ||||||||||||
}(ms) | ||||||||||||
} | ||||||||||||
defer close(infoCh) | ||||||||||||
|
||||||||||||
var ( | ||||||||||||
err error | ||||||||||||
totalCount int64 | ||||||||||||
totalChecksum int64 | ||||||||||||
) | ||||||||||||
matchSources := getMatchedSourcesForTable(s.sourceTablesMap, table) | ||||||||||||
|
||||||||||||
if common.AllTableExist(table.TableLack) { | ||||||||||||
infoCh := make(chan *ChecksumInfo, len(s.sourceTablesMap)) | ||||||||||||
for _, ms := range matchSources { | ||||||||||||
go func(ms *common.TableShardSource) { | ||||||||||||
count, checksum, err := utils.GetCountAndCRC32Checksum(ctx, ms.DBConn, ms.OriginSchema, ms.OriginTable, table.Info, chunk.Where, chunk.Args) | ||||||||||||
infoCh <- &ChecksumInfo{ | ||||||||||||
Checksum: checksum, | ||||||||||||
Count: count, | ||||||||||||
Err: err, | ||||||||||||
} | ||||||||||||
}(ms) | ||||||||||||
} | ||||||||||||
defer close(infoCh) | ||||||||||||
|
||||||||||||
for range matchSources { | ||||||||||||
info := <-infoCh | ||||||||||||
// catch the first error | ||||||||||||
if err == nil && info.Err != nil { | ||||||||||||
err = info.Err | ||||||||||||
for range matchSources { | ||||||||||||
info := <-infoCh | ||||||||||||
// catch the first error | ||||||||||||
if err == nil && info.Err != nil { | ||||||||||||
err = info.Err | ||||||||||||
} | ||||||||||||
totalCount += info.Count | ||||||||||||
totalChecksum ^= info.Checksum | ||||||||||||
} | ||||||||||||
} else { | ||||||||||||
var count int64 | ||||||||||||
if matchSources != nil { | ||||||||||||
for _, ms := range matchSources { | ||||||||||||
count, err = dbutil.GetRowCount(ctx, ms.DBConn, ms.OriginSchema, ms.OriginTable, "", nil) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error will be returned in |
||||||||||||
totalCount += count | ||||||||||||
} | ||||||||||||
} | ||||||||||||
totalCount += info.Count | ||||||||||||
totalChecksum ^= info.Checksum | ||||||||||||
} | ||||||||||||
|
||||||||||||
cost := time.Since(beginTime) | ||||||||||||
|
@@ -169,7 +171,7 @@ func (s *MySQLSources) GetRowsIterator(ctx context.Context, tableRange *splitter | |||||||||||
|
||||||||||||
table := s.tableDiffs[tableRange.GetTableIndex()] | ||||||||||||
// for tables that do not exist upstream or downstream | ||||||||||||
if !AllTableExist(table) { | ||||||||||||
if !common.AllTableExist(table.TableLack) { | ||||||||||||
return nil, nil | ||||||||||||
} | ||||||||||||
matchSources := getMatchedSourcesForTable(s.sourceTablesMap, table) | ||||||||||||
|
@@ -234,7 +236,7 @@ func (s *MySQLSources) GetSnapshot() string { | |||||||||||
func (s *MySQLSources) GetSourceStructInfo(ctx context.Context, tableIndex int) ([]*model.TableInfo, error) { | ||||||||||||
tableDiff := s.GetTables()[tableIndex] | ||||||||||||
// for tables that do not exist upstream or downstream | ||||||||||||
if !AllTableExist(tableDiff) { | ||||||||||||
if !common.AllTableExist(tableDiff.TableLack) { | ||||||||||||
return nil, nil | ||||||||||||
} | ||||||||||||
tableSources := getMatchedSourcesForTable(s.sourceTablesMap, tableDiff) | ||||||||||||
|
@@ -334,12 +336,14 @@ func NewMySQLSources(ctx context.Context, tableDiffs []*common.TableDiff, ds []* | |||||||||||
} | ||||||||||||
} | ||||||||||||
uniqueId := utils.UniqueID(targetSchema, targetTable) | ||||||||||||
var isMatched bool | ||||||||||||
// get all tables from all source db instance | ||||||||||||
if f.MatchTable(targetSchema, targetTable) { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
// if match the filter, we should respect it and check target has this table later. | ||||||||||||
sourceTablesAfterRoute[uniqueId] = struct{}{} | ||||||||||||
isMatched = true | ||||||||||||
} | ||||||||||||
if _, ok := targetUniqueTableMap[uniqueId]; !ok { | ||||||||||||
if _, ok := targetUniqueTableMap[uniqueId]; !ok && !(isMatched && skipNonExistingTable) { | ||||||||||||
continue | ||||||||||||
} | ||||||||||||
maxSourceRouteTableCount[uniqueId]++ | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,9 +124,20 @@ func (s *TiDBSource) GetCountAndCrc32(ctx context.Context, tableRange *splitter. | |
beginTime := time.Now() | ||
table := s.tableDiffs[tableRange.GetTableIndex()] | ||
chunk := tableRange.GetChunk() | ||
var ( | ||
checksum int64 | ||
count int64 | ||
err error | ||
) | ||
|
||
matchSource := getMatchSource(s.sourceTableMap, table) | ||
count, checksum, err := utils.GetCountAndCRC32Checksum(ctx, s.dbConn, matchSource.OriginSchema, matchSource.OriginTable, table.Info, chunk.Where, chunk.Args) | ||
if common.AllTableExist(table.TableLack) { | ||
count, checksum, err = utils.GetCountAndCRC32Checksum(ctx, s.dbConn, matchSource.OriginSchema, matchSource.OriginTable, table.Info, chunk.Where, chunk.Args) | ||
} else { | ||
if matchSource != nil { | ||
count, err = dbutil.GetRowCount(ctx, s.dbConn, matchSource.OriginSchema, matchSource.OriginTable, "", nil) | ||
} | ||
} | ||
|
||
cost := time.Since(beginTime) | ||
return &ChecksumInfo{ | ||
|
@@ -236,11 +247,13 @@ func NewTiDBSource(ctx context.Context, tableDiffs []*common.TableDiff, ds *conf | |
} | ||
|
||
uniqueId := utils.UniqueID(targetSchema, targetTable) | ||
var isMatched bool | ||
if f.MatchTable(targetSchema, targetTable) { | ||
// if match the filter, we should respect it and check target has this table later. | ||
sourceTablesAfterRoute[uniqueId] = struct{}{} | ||
isMatched = true | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modified. |
||
if _, ok := targetUniqueTableMap[uniqueId]; ok { | ||
if _, ok := targetUniqueTableMap[uniqueId]; ok || (isMatched && skipNonExistingTable) { | ||
if _, ok := sourceTableMap[uniqueId]; ok { | ||
log.Error("TiDB source don't support compare multiple source tables with one downstream table," + | ||
" if this happening when diff on same instance is fine. otherwise we are not guarantee this diff result is right") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.