Skip to content

Commit

Permalink
ddl, domain: handle the corner case that putting the MDL key to etcd …
Browse files Browse the repository at this point in the history
…failed (#39418)

close #39416
  • Loading branch information
wjhuang2016 authored Nov 28, 2022
1 parent b3bbe96 commit 43b1c61
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
6 changes: 6 additions & 0 deletions ddl/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 43b1c61

Please sign in to comment.