Skip to content

Commit

Permalink
lightning: pick the first file to check schema (#27607) (#27623)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Oct 13, 2021
1 parent 7cd215c commit 29933b4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
11 changes: 6 additions & 5 deletions br/pkg/lightning/restore/check_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ func (rc *Controller) SchemaIsValid(ctx context.Context, tableInfo *mydump.MDTab
// tidb_rowid have a default value.
defaultCols[model.ExtraHandleName.String()] = struct{}{}

for _, dataFile := range tableInfo.DataFiles {
// only check the first file of this table.
if len(tableInfo.DataFiles) > 0 {
dataFile := tableInfo.DataFiles[0]
log.L().Info("datafile to check", zap.String("db", tableInfo.DB),
zap.String("table", tableInfo.Name), zap.String("path", dataFile.FileMeta.Path))
// get columns name from data file.
dataFileMeta := dataFile.FileMeta

Expand All @@ -461,7 +465,7 @@ func (rc *Controller) SchemaIsValid(ctx context.Context, tableInfo *mydump.MDTab
}
if colsFromDataFile == nil && colCountFromDataFile == 0 {
log.L().Info("file contains no data, skip checking against schema validity", zap.String("path", dataFileMeta.Path))
continue
return msgs, nil
}

if colsFromDataFile == nil {
Expand Down Expand Up @@ -522,9 +526,6 @@ func (rc *Controller) SchemaIsValid(ctx context.Context, tableInfo *mydump.MDTab
tableInfo.DB, tableInfo.Name, col, col))
}
}
if len(msgs) > 0 {
return msgs, nil
}
}
return msgs, nil
}
Expand Down
59 changes: 59 additions & 0 deletions br/pkg/lightning/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,65 @@ func (s *tableRestoreSuite) TestSchemaIsValid(c *C) {
},
},
},
// Case 4:
// table4 has two datafiles for table. we only check the first file.
// we expect the check success.
{
[]*config.IgnoreColumns{
{
DB: "db1",
Table: "table2",
Columns: []string{"cola"},
},
},
"",
0,
true,
map[string]*checkpoints.TidbDBInfo{
"db1": {
Name: "db1",
Tables: map[string]*checkpoints.TidbTableInfo{
"table2": {
ID: 1,
DB: "db1",
Name: "table2",
Core: &model.TableInfo{
Columns: []*model.ColumnInfo{
{
// colB has the default value
Name: model.NewCIStr("colB"),
DefaultIsExpr: true,
},
},
},
},
},
},
},
&mydump.MDTableMeta{
DB: "db1",
Name: "table2",
DataFiles: []mydump.FileInfo{
{
FileMeta: mydump.SourceFileMeta{
FileSize: 1 * units.TiB,
Path: case2File,
Type: mydump.SourceTypeCSV,
},
},
{
FileMeta: mydump.SourceFileMeta{
FileSize: 1 * units.TiB,
Path: case2File,
// This type will make the check failed.
// but it's the second file for table.
// so it's unreachable so this case will success.
Type: mydump.SourceTypeIgnore,
},
},
},
},
},
}

for _, ca := range cases {
Expand Down

0 comments on commit 29933b4

Please sign in to comment.