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 (#31808) (#32368)

close #31771
  • Loading branch information
ti-srebot authored Feb 18, 2022
1 parent 33876a3 commit 92d6798
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 @@ -287,13 +287,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 @@ -320,7 +320,8 @@ func (s *tidbSuite) TestLoadSchemaInfo(c *C) {
"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);",
"", "")
c.Assert(err, IsNil)
tableInfos := make([]*model.TableInfo, 0, len(nodes))
Expand All @@ -345,6 +346,10 @@ func (s *tidbSuite) TestLoadSchemaInfo(c *C) {
DB: "db",
Name: "t2",
},
{
DB: "db",
Name: "t4",
},
},
},
}
Expand All @@ -370,13 +375,19 @@ func (s *tidbSuite) TestLoadSchemaInfo(c *C) {
Name: "t2",
Core: tableInfos[1],
},
"t4": {
ID: 103,
DB: "db",
Name: "t4",
Core: tableInfos[3],
},
},
},
})

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

c.Assert(tableCntAfter-tableCntBefore, Equals, 2.0)
c.Assert(tableCntAfter-tableCntBefore, Equals, 3.0)
}

func (s *tidbSuite) TestLoadSchemaInfoMissing(c *C) {
Expand Down

0 comments on commit 92d6798

Please sign in to comment.