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

lightning: pick the first file to check schema #27607

Merged
merged 12 commits into from
Aug 27, 2021
6 changes: 5 additions & 1 deletion br/pkg/lightning/restore/check_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,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 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 @@ -2205,6 +2205,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