Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#43781
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
wjhuang2016 authored and ti-chi-bot committed May 15, 2023
1 parent dfd1e31 commit 5fa8c41
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ddl/metadatalocktest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ go_test(
"mdl_test.go",
],
flaky = True,
<<<<<<< HEAD
=======
shard_count = 32,
>>>>>>> cde395dc597 (ddl, domain: fix a bug which causes MDL blocking (#43781))
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 @@ -22,6 +22,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 @@ -1118,3 +1119,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 @@ -66,6 +66,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
10 changes: 10 additions & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ func (do *Domain) mdlCheckLoop() {
if !variable.EnableMDL.Load() {
continue
}
<<<<<<< HEAD

do.mdlCheckTableInfo.mu.Lock()
maxVer := do.mdlCheckTableInfo.newestVer
Expand All @@ -686,6 +687,15 @@ func (do *Domain) mdlCheckLoop() {
// Schema doesn't change, and no job to check in the last run.
do.mdlCheckTableInfo.mu.Unlock()
continue
=======
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
>>>>>>> cde395dc597 (ddl, domain: fix a bug which causes MDL blocking (#43781))
}

jobNeedToCheckCnt := len(do.mdlCheckTableInfo.jobsVerMap)
Expand Down

0 comments on commit 5fa8c41

Please sign in to comment.