From 92d67980ad783ac36286f0865e8c1d72b580dbc4 Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Fri, 18 Feb 2022 16:29:40 +0800 Subject: [PATCH] lightning: fix panic when table name in source file and target cluster is different (#31808) (#32368) close pingcap/tidb#31771 --- br/pkg/lightning/restore/tidb.go | 6 ++++-- br/pkg/lightning/restore/tidb_test.go | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/br/pkg/lightning/restore/tidb.go b/br/pkg/lightning/restore/tidb.go index c27a76604fe04..16e6a55618226 100644 --- a/br/pkg/lightning/restore/tidb.go +++ b/br/pkg/lightning/restore/tidb.go @@ -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 diff --git a/br/pkg/lightning/restore/tidb_test.go b/br/pkg/lightning/restore/tidb_test.go index 1ee90f968bf5a..d6eea8b2b01c1 100644 --- a/br/pkg/lightning/restore/tidb_test.go +++ b/br/pkg/lightning/restore/tidb_test.go @@ -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)) @@ -345,6 +346,10 @@ func (s *tidbSuite) TestLoadSchemaInfo(c *C) { DB: "db", Name: "t2", }, + { + DB: "db", + Name: "t4", + }, }, }, } @@ -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) {