Skip to content
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

*: fix a data race on TestConnExecutionTimeout #35923

Merged
merged 28 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
33f1684
*: fix a data race on TestConnExecutionTimeout
tiancaiamao Jul 4, 2022
683f27d
Merge branch 'master' into race-35922
tiancaiamao Jul 5, 2022
0481e8c
Merge branch 'master' into race-35922
tiancaiamao Jul 5, 2022
2623316
Merge branch 'master' into race-35922
hawkingrei Jul 5, 2022
49b5a32
Merge branch 'master' into race-35922
tiancaiamao Jul 5, 2022
6faad39
Merge branch 'master' into race-35922
ti-chi-bot Jul 5, 2022
b848d69
Merge branch 'master' into race-35922
ti-chi-bot Jul 5, 2022
18ebfae
Merge branch 'master' into race-35922
ti-chi-bot Jul 5, 2022
c856b6a
Merge branch 'master' into race-35922
ti-chi-bot Jul 5, 2022
4e6c7a2
Merge branch 'master' into race-35922
ti-chi-bot Jul 5, 2022
fe79f9a
Merge branch 'master' into race-35922
hawkingrei Jul 5, 2022
aaba71a
Merge branch 'master' into race-35922
ti-chi-bot Jul 5, 2022
06a794c
Merge branch 'master' into race-35922
ti-chi-bot Jul 5, 2022
25f6344
Merge branch 'master' into race-35922
ti-chi-bot Jul 5, 2022
616becc
Merge branch 'master' into race-35922
ti-chi-bot Jul 5, 2022
08a8d01
Merge branch 'master' into race-35922
ti-chi-bot Jul 6, 2022
c606542
Merge branch 'master' into race-35922
ti-chi-bot Jul 6, 2022
2c76d82
Merge branch 'master' into race-35922
ti-chi-bot Jul 6, 2022
7c2632a
Merge branch 'master' into race-35922
ti-chi-bot Jul 6, 2022
429e9b6
Merge branch 'master' into race-35922
ti-chi-bot Jul 6, 2022
ccc3285
Merge branch 'master' into race-35922
ti-chi-bot Jul 6, 2022
879bc63
debug CI
tiancaiamao Jul 6, 2022
12b9693
Merge branch 'master' into race-35922
hawkingrei Jul 8, 2022
f5d5f99
Merge branch 'master' into race-35922
hawkingrei Jul 8, 2022
c9c9259
Merge branch 'master' into race-35922
tiancaiamao Jul 11, 2022
0ab277d
Merge branch 'master' into race-35922
tiancaiamao Jul 11, 2022
771b2e8
Merge branch 'master' into race-35922
tiancaiamao Jul 11, 2022
94d1473
Merge branch 'master' into race-35922
ti-chi-bot Jul 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"flag"
"fmt"
"sync"
"sync/atomic"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -756,7 +757,8 @@ func (d *ddl) DoDDLJob(ctx sessionctx.Context, job *model.Job) error {
return errors.Trace(err)
}

ctx.GetSessionVars().StmtCtx.IsDDLJobInQueue = true
sessVars := ctx.GetSessionVars()
sessVars.StmtCtx.IsDDLJobInQueue = true

// Notice worker that we push a new job and wait the job done.
d.asyncNotifyWorker(job)
Expand Down Expand Up @@ -798,6 +800,27 @@ func (d *ddl) DoDDLJob(ctx sessionctx.Context, job *model.Job) error {
return context.Canceled
}

// If the connection being killed, we need to CANCEL the DDL job.
if atomic.LoadUint32(&sessVars.Killed) == 1 {
if sessVars.StmtCtx.DDLJobID != 0 {
xhebox marked this conversation as resolved.
Show resolved Hide resolved
sessVars.StmtCtx.DDLJobID = 0 // Avoid repeat.

err := kv.RunInNewTxn(context.Background(), d.store, true, func(ctx context.Context, txn kv.Transaction) error {
// errs is the error per job, there is only one submitted
// err is the error of the overall task
errs, err := CancelJobs(txn, []int64{jobID})
if len(errs) > 0 {
logutil.BgLogger().Warn("error canceling DDL job", zap.Error(errs[0]))
}
return err
})
if err != nil {
logutil.BgLogger().Warn("Kill command could not cancel DDL job", zap.Error(err))
continue
}
}
}

historyJob, err = d.getHistoryDDLJob(jobID)
if err != nil {
logutil.BgLogger().Error("[ddl] get history DDL job failed, check again", zap.Error(err))
Expand Down
19 changes: 0 additions & 19 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import (
"github.com/blacktear23/go-proxyprotocol"
"github.com/pingcap/errors"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/kv"
Expand Down Expand Up @@ -719,24 +718,6 @@ func killConn(conn *clientConn) {
cancelFunc := conn.mu.cancelFunc
conn.mu.RUnlock()

// If the connection being killed is a DDL Job,
// we need to CANCEL the matching jobID first.
if sessVars.StmtCtx.IsDDLJobInQueue {
jobID := sessVars.StmtCtx.DDLJobID
err := kv.RunInNewTxn(context.Background(), conn.ctx.GetStore(), true, func(ctx context.Context, txn kv.Transaction) error {
// errs is the error per job, there is only one submitted
// err is the error of the overall task
errs, err := ddl.CancelJobs(txn, []int64{jobID})
if len(errs) > 0 {
logutil.BgLogger().Warn("error canceling DDL job", zap.Error(errs[0]))
}
return err
})
if err != nil {
logutil.BgLogger().Warn("could not cancel DDL job", zap.Error(err))
}
}

if cancelFunc != nil {
cancelFunc()
}
Expand Down
1 change: 1 addition & 0 deletions util/expensivequery/expensivequery.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (eqh *Handle) Run() {
if len(info.Info) == 0 {
continue
}

costTime := time.Since(info.Time)
if !info.ExceedExpensiveTimeThresh && costTime >= time.Second*time.Duration(threshold) && log.GetLevel() <= zapcore.WarnLevel {
logExpensiveQuery(costTime, info)
Expand Down