From 29fd1250ea0eb5e2eaf129bc0c8fa4b3ab56540e Mon Sep 17 00:00:00 2001 From: Zhoubirdblue <820486124@qq.com> Date: Fri, 28 Oct 2016 13:25:32 +0800 Subject: [PATCH] drop foreign key that does not exist error (#1874) --- ddl/ddl_worker_test.go | 22 ++++++++++++++++++++++ ddl/foreign_key.go | 1 + 2 files changed, 23 insertions(+) diff --git a/ddl/ddl_worker_test.go b/ddl/ddl_worker_test.go index 58f65d2565..aa8b4883a1 100644 --- a/ddl/ddl_worker_test.go +++ b/ddl/ddl_worker_test.go @@ -174,6 +174,28 @@ func (s *testDDLSuite) TestTableError(c *C) { c.Assert(err, IsNil) } +func (s *testDDLSuite) TestForeignKeyError(c *C) { + defer testleak.AfterTest(c)() + store := testCreateStore(c, "test_foreign_key_error") + defer store.Close() + + d := newDDL(store, nil, nil, testLease) + defer d.close() + + ctx := testNewContext(c, d) + + doDDLJobErr(c, -1, 1, model.ActionAddForeignKey, nil, ctx, d) + doDDLJobErr(c, -1, 1, model.ActionDropForeignKey, nil, ctx, d) + + dbInfo := testSchemaInfo(c, d, "test") + tblInfo := testTableInfo(c, d, "t", 3) + + testCreateSchema(c, ctx, d, dbInfo) + testCreateTable(c, ctx, d, dbInfo, tblInfo) + + doDDLJobErr(c, dbInfo.ID, tblInfo.ID, model.ActionDropForeignKey, []interface{}{model.NewCIStr("c1_foreign_key")}, ctx, d) +} + func (s *testDDLSuite) TestIndexError(c *C) { defer testleak.AfterTest(c)() store := testCreateStore(c, "test_index_error") diff --git a/ddl/foreign_key.go b/ddl/foreign_key.go index 987bebb6f9..4166fa7605 100644 --- a/ddl/foreign_key.go +++ b/ddl/foreign_key.go @@ -85,6 +85,7 @@ func (d *ddl) onDropForeignKey(t *meta.Meta, job *model.Job) error { } if !found { + job.State = model.JobCancelled return infoschema.ErrForeignKeyNotExists.Gen("foreign key doesn't exist", fkName) }