From 43b1c61a6811b2583d8e524046d9b255780e7b1c Mon Sep 17 00:00:00 2001 From: wjHuang Date: Mon, 28 Nov 2022 22:15:59 +0800 Subject: [PATCH] ddl, domain: handle the corner case that putting the MDL key to etcd failed (#39418) close pingcap/tidb#39416 --- ddl/db_test.go | 12 ++++++++++++ ddl/mock.go | 6 ++++++ domain/domain.go | 1 + 3 files changed, 19 insertions(+) diff --git a/ddl/db_test.go b/ddl/db_test.go index ce2ea307e97af..e1347276637e4 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -1763,3 +1763,15 @@ func TestDDLBlockedCreateView(t *testing.T) { dom.DDL().SetHook(hook) tk.MustExec("alter table t modify column a char(10)") } + +func TestMDLPutETCDFail(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("create table t(a int)") + + require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/ddl/putEtcdFailed", `return(true)`)) + defer require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/putEtcdFailed")) + tk.MustExec("alter table t add column b int") +} diff --git a/ddl/mock.go b/ddl/mock.go index 57a60794f514a..9475a5c34ee2e 100644 --- a/ddl/mock.go +++ b/ddl/mock.go @@ -66,6 +66,12 @@ func (s *MockSchemaSyncer) WatchGlobalSchemaVer(context.Context) {} // UpdateSelfVersion implements SchemaSyncer.UpdateSelfVersion interface. func (s *MockSchemaSyncer) UpdateSelfVersion(ctx context.Context, jobID int64, version int64) error { + failpoint.Inject("putEtcdFailed", func() { + if mockDDLErrOnce < 3 { + mockDDLErrOnce++ + failpoint.Return(errors.New("mock putEtcdFailed")) + } + }) if variable.EnableMDL.Load() { s.mdlSchemaVersions.Store(jobID, version) } else { diff --git a/domain/domain.go b/domain/domain.go index 66fcf3ca0e3b3..899ad458d78eb 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -724,6 +724,7 @@ func (do *Domain) mdlCheckLoop() { err := do.ddl.SchemaSyncer().UpdateSelfVersion(context.Background(), jobID, ver) if err != nil { logutil.BgLogger().Warn("update self version failed", zap.Error(err)) + jobNeedToSync = true } else { jobCache[jobID] = ver }