Skip to content

Commit

Permalink
ddl, domain: fix a bug which causes MDL blocking (#43781) (#43785)
Browse files Browse the repository at this point in the history
close #43755
  • Loading branch information
ti-chi-bot authored May 18, 2023
1 parent 2561314 commit 06803f0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ddl/metadatalocktest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ go_test(
"mdl_test.go",
],
flaky = True,
shard_count = 31,
shard_count = 32,
deps = [
"//config",
"//ddl",
"//errno",
"//server",
"//testkit",
"//testkit/testsetup",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//require",
"@org_uber_go_goleak//:goleak",
],
Expand Down
16 changes: 16 additions & 0 deletions ddl/metadatalocktest/mdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"
"time"

"github.com/pingcap/failpoint"
mysql "github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/server"
"github.com/pingcap/tidb/testkit"
Expand Down Expand Up @@ -1165,3 +1166,18 @@ func TestMDLPrepareFail(t *testing.T) {

tk2.MustExec("alter table test.t add column c int")
}

func TestMDLUpdateEtcdFail(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/mockUpdateMDLToETCDError", `3*return(true)`))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/mockUpdateMDLToETCDError"))
}()

tk.MustExec("alter table test.t add column c int")
}
5 changes: 5 additions & 0 deletions ddl/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ 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("mockUpdateMDLToETCDError", func(val failpoint.Value) {
if val.(bool) {
failpoint.Return(errors.New("mock update mdl to etcd error"))
}
})
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 @@ -833,6 +833,7 @@ func (do *Domain) mdlCheckLoop() {
logutil.BgLogger().Info("mdl gets lock, update to owner", zap.Int64("jobID", jobID), zap.Int64("version", ver))
err := do.ddl.SchemaSyncer().UpdateSelfVersion(context.Background(), jobID, ver)
if err != nil {
jobNeedToSync = true
logutil.BgLogger().Warn("update self version failed", zap.Error(err))
} else {
jobCache[jobID] = ver
Expand Down

0 comments on commit 06803f0

Please sign in to comment.