Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

restore: fix error lost in create schema #530

Merged
merged 8 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lightning/restore/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"

"github.com/pingcap/tidb-lightning/lightning/glue"

. "github.com/pingcap/tidb-lightning/lightning/checkpoints"
Expand Down Expand Up @@ -154,6 +155,7 @@ func InitSchema(ctx context.Context, g glue.Glue, database string, tablesSchema

task := logger.Begin(zap.InfoLevel, "create tables")
var sqlCreateStmts []string
loopCreate:
for tbl, sqlCreateTable := range tablesSchema {
task.Debug("create table", zap.String("schema", sqlCreateTable))

Expand All @@ -171,7 +173,7 @@ func InitSchema(ctx context.Context, g glue.Glue, database string, tablesSchema
logger.With(zap.String("table", common.UniqueTable(database, tbl))),
)
if err != nil {
break
break loopCreate
}
}
}
Expand Down
27 changes: 26 additions & 1 deletion lightning/restore/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
tmysql "github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb-lightning/lightning/glue"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/util/mock"

"github.com/pingcap/tidb-lightning/lightning/glue"

"github.com/pingcap/tidb-lightning/lightning/checkpoints"
"github.com/pingcap/tidb-lightning/lightning/mydump"
)
Expand Down Expand Up @@ -224,6 +225,30 @@ func (s *tidbSuite) TestInitSchemaSyntaxError(c *C) {
c.Assert(err, NotNil)
}

func (s *tidbSuite) TestInitSchemaErrorLost(c *C) {
ctx := context.Background()

s.mockDB.
ExpectExec("CREATE DATABASE IF NOT EXISTS `db`").
WillReturnResult(sqlmock.NewResult(1, 1))

s.mockDB.
ExpectExec("CREATE TABLE IF NOT EXISTS.*").
WillReturnError(&mysql.MySQLError{
Number: tmysql.ErrTooBigFieldlength,
Message: "Column length too big",
})

s.mockDB.
ExpectClose()

err := InitSchema(ctx, s.tiGlue, "db", map[string]string{
"t1": "create table `t1` (a int);",
"t2": "create table t2 (a int primary key, b varchar(200));",
})
c.Assert(err, ErrorMatches, ".*Column length too big.*")
}

func (s *tidbSuite) TestInitSchemaUnsupportedSchemaError(c *C) {
ctx := context.Background()

Expand Down