-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ddl: fix can't cancel a job when add index meets panic #8621
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f39cf0f
ddl: fix can't cancel a job when add index meets panic
winkyao 6615b57
address comment
winkyao 5b3f550
Merge remote-tracking branch 'upstream/master' into fix_cancel_panic
winkyao a4d1e02
fix ci
winkyao 8712a35
Merge branch 'master' into fix_cancel_panic
winkyao 0598f8d
Merge branch 'master' into fix_cancel_panic
winkyao a3fadca
Merge branch 'master' into fix_cancel_panic
winkyao aaa2d26
modify gofail
winkyao f6a8079
Merge remote-tracking branch 'upstream/master' into fix_cancel_panic
winkyao b169dbe
make run go test serially
winkyao 3800e37
Merge branch 'master' into fix_cancel_panic
winkyao 188ff17
update go mod
winkyao ad6f9ea
Merge branch 'fix_cancel_panic' of https://github.com/winkyao/tidb in…
winkyao dc12d59
update go mod
winkyao 8ad1223
Merge branch 'master' into fix_cancel_panic
zimulala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ddl_test | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
. "github.com/pingcap/check" | ||
"github.com/pingcap/errors" | ||
gofail "github.com/pingcap/gofail/runtime" | ||
"github.com/pingcap/parser/model" | ||
"github.com/pingcap/tidb/ddl" | ||
"github.com/pingcap/tidb/domain" | ||
"github.com/pingcap/tidb/kv" | ||
"github.com/pingcap/tidb/session" | ||
"github.com/pingcap/tidb/store/mockstore" | ||
"github.com/pingcap/tidb/util/admin" | ||
"github.com/pingcap/tidb/util/mock" | ||
"github.com/pingcap/tidb/util/testkit" | ||
"github.com/pingcap/tidb/util/testleak" | ||
) | ||
|
||
var _ = SerialSuites(&testSerialSuite{}) | ||
|
||
type testSerialSuite struct { | ||
store kv.Storage | ||
dom *domain.Domain | ||
} | ||
|
||
func (s *testSerialSuite) SetUpSuite(c *C) { | ||
testleak.BeforeTest() | ||
session.SetSchemaLease(200 * time.Millisecond) | ||
session.SetStatsLease(0) | ||
|
||
ddl.WaitTimeWhenErrorOccured = 1 * time.Microsecond | ||
var err error | ||
s.store, err = mockstore.NewMockTikvStore() | ||
c.Assert(err, IsNil) | ||
|
||
s.dom, err = session.BootstrapSession(s.store) | ||
c.Assert(err, IsNil) | ||
} | ||
|
||
func (s *testSerialSuite) TearDownSuite(c *C) { | ||
if s.dom != nil { | ||
s.dom.Close() | ||
} | ||
if s.store != nil { | ||
s.store.Close() | ||
} | ||
testleak.AfterTest(c)() | ||
} | ||
|
||
// TestCancelAddIndex1 tests canceling ddl job when the add index worker is not started. | ||
func (s *testSerialSuite) TestCancelAddIndexPanic(c *C) { | ||
gofail.Enable("github.com/pingcap/tidb/ddl/errorMockPanic", `return(true)`) | ||
defer gofail.Disable("github.com/pingcap/tidb/ddl/errorMockPanic") | ||
tk := testkit.NewTestKit(c, s.store) | ||
tk.MustExec("use test") | ||
tk.MustExec("drop table if exists t") | ||
tk.MustExec("create table t(c1 int, c2 int)") | ||
defer tk.MustExec("drop table t;") | ||
for i := 0; i < 5; i++ { | ||
tk.MustExec("insert into t values (?, ?)", i, i) | ||
} | ||
var checkErr error | ||
oldReorgWaitTimeout := ddl.ReorgWaitTimeout | ||
ddl.ReorgWaitTimeout = 50 * time.Millisecond | ||
defer func() { ddl.ReorgWaitTimeout = oldReorgWaitTimeout }() | ||
hook := &ddl.TestDDLCallback{} | ||
hook.OnJobRunBeforeExported = func(job *model.Job) { | ||
if job.Type == model.ActionAddIndex && job.State == model.JobStateRunning && job.SchemaState == model.StateWriteReorganization && job.SnapshotVer != 0 { | ||
jobIDs := []int64{job.ID} | ||
hookCtx := mock.NewContext() | ||
hookCtx.Store = s.store | ||
err := hookCtx.NewTxn(context.Background()) | ||
if err != nil { | ||
checkErr = errors.Trace(err) | ||
return | ||
} | ||
txn, err := hookCtx.Txn(true) | ||
if err != nil { | ||
checkErr = errors.Trace(err) | ||
return | ||
} | ||
errs, err := admin.CancelJobs(txn, jobIDs) | ||
if err != nil { | ||
checkErr = errors.Trace(err) | ||
return | ||
} | ||
if errs[0] != nil { | ||
checkErr = errors.Trace(errs[0]) | ||
return | ||
} | ||
txn, err = hookCtx.Txn(true) | ||
if err != nil { | ||
checkErr = errors.Trace(err) | ||
return | ||
} | ||
checkErr = txn.Commit(context.Background()) | ||
} | ||
} | ||
origHook := s.dom.DDL().GetHook() | ||
defer s.dom.DDL().(ddl.DDLForTest).SetHook(origHook) | ||
s.dom.DDL().(ddl.DDLForTest).SetHook(hook) | ||
rs, err := tk.Exec("alter table t add index idx_c2(c2)") | ||
if rs != nil { | ||
rs.Close() | ||
} | ||
c.Assert(checkErr, IsNil) | ||
c.Assert(err, NotNil) | ||
c.Assert(err.Error(), Equals, "[ddl:12]cancelled DDL job") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want to do it again?