diff --git a/lightning/restore/tidb.go b/lightning/restore/tidb.go index 27d3259ba..a301fba56 100644 --- a/lightning/restore/tidb.go +++ b/lightning/restore/tidb.go @@ -22,6 +22,7 @@ import ( tmysql "github.com/go-sql-driver/mysql" "github.com/pingcap/errors" + "github.com/pingcap/failpoint" "github.com/pingcap/parser" "github.com/pingcap/parser/ast" "github.com/pingcap/parser/format" @@ -171,6 +172,9 @@ loopCreate: "create table", logger.With(zap.String("table", common.UniqueTable(database, tbl))), ) + failpoint.Inject("sqlCreateStmts", func() { + err = errors.Errorf("create %s failed", tbl) + }) if err != nil { break loopCreate } diff --git a/lightning/restore/tidb_test.go b/lightning/restore/tidb_test.go index 4b32834bc..32f068f45 100644 --- a/lightning/restore/tidb_test.go +++ b/lightning/restore/tidb_test.go @@ -22,6 +22,7 @@ import ( "github.com/go-sql-driver/mysql" . "github.com/pingcap/check" "github.com/pingcap/errors" + "github.com/pingcap/failpoint" "github.com/pingcap/parser/ast" "github.com/pingcap/parser/model" tmysql "github.com/pingcap/parser/mysql" @@ -224,6 +225,24 @@ 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. + ExpectClose() + + failpoint.Enable("github.com/pingcap/tidb-lightning/lightning/restore/GetRlimitValue", "return") + 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));", + }) + failpoint.Disable("github.com/pingcap/tidb-lightning/lightning/restore/GetRlimitValue") + c.Assert(err, ErrorMatches, "create t1 failed") +} + func (s *tidbSuite) TestInitSchemaUnsupportedSchemaError(c *C) { ctx := context.Background()