Skip to content

Commit

Permalink
lightning: fix panic when table name in source file and target cluste…
Browse files Browse the repository at this point in the history
…r is different (pingcap#31808)

close pingcap#31771
  • Loading branch information
sleepymole authored Feb 15, 2022
1 parent 886650b commit 167228a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions br/pkg/lightning/restore/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,15 @@ func LoadSchemaInfo(
if err != nil {
return nil, errors.Trace(err)
}
// Table names are case-sensitive in mydump.MDTableMeta.
// We should always use the original tbl.Name in checkpoints.
tableInfo := &checkpoints.TidbTableInfo{
ID: tblInfo.ID,
DB: schema.Name,
Name: tableName,
Name: tbl.Name,
Core: tblInfo,
}
dbInfo.Tables[tableName] = tableInfo
dbInfo.Tables[tbl.Name] = tableInfo
}

result[schema.Name] = dbInfo
Expand Down
15 changes: 13 additions & 2 deletions br/pkg/lightning/restore/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ func TestLoadSchemaInfo(t *testing.T) {
"CREATE TABLE `t1` (`a` INT PRIMARY KEY);"+
"CREATE TABLE `t2` (`b` VARCHAR(20), `c` BOOL, KEY (`b`, `c`));"+
// an extra table that not exists in dbMetas
"CREATE TABLE `t3` (`d` VARCHAR(20), `e` BOOL);",
"CREATE TABLE `t3` (`d` VARCHAR(20), `e` BOOL);"+
"CREATE TABLE `T4` (`f` BIGINT PRIMARY KEY);",
"", "")
require.NoError(t, err)
tableInfos := make([]*model.TableInfo, 0, len(nodes))
Expand All @@ -309,6 +310,10 @@ func TestLoadSchemaInfo(t *testing.T) {
DB: "db",
Name: "t2",
},
{
DB: "db",
Name: "t4",
},
},
},
}
Expand All @@ -334,13 +339,19 @@ func TestLoadSchemaInfo(t *testing.T) {
Name: "t2",
Core: tableInfos[1],
},
"t4": {
ID: 103,
DB: "db",
Name: "t4",
Core: tableInfos[3],
},
},
},
}, loaded)

tableCntAfter := metric.ReadCounter(metric.TableCounter.WithLabelValues(metric.TableStatePending, metric.TableResultSuccess))

require.Equal(t, 2.0, tableCntAfter-tableCntBefore)
require.Equal(t, 3.0, tableCntAfter-tableCntBefore)
}

func TestLoadSchemaInfoMissing(t *testing.T) {
Expand Down

0 comments on commit 167228a

Please sign in to comment.