Skip to content

Commit

Permalink
distsql: check the killed flag in the distsql package (#15592) (#15616)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Mar 30, 2020
1 parent 979f756 commit e4f5426
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion distsql/select_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package distsql
import (
"context"
"fmt"
"sync/atomic"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/metrics"
Expand All @@ -33,6 +35,10 @@ import (
"go.uber.org/zap"
)

var (
errQueryInterrupted = terror.ClassExecutor.New(mysql.ErrQueryInterrupted, mysql.MySQLErrName[mysql.ErrQueryInterrupted])
)

var (
_ SelectResult = (*selectResult)(nil)
_ SelectResult = (*streamResult)(nil)
Expand Down Expand Up @@ -188,7 +194,11 @@ func (r *selectResult) getSelectResp() error {
if err := r.selectResp.Error; err != nil {
return terror.ClassTiKV.New(terror.ErrCode(err.Code), err.Msg)
}
sc := r.ctx.GetSessionVars().StmtCtx
sessVars := r.ctx.GetSessionVars()
if atomic.CompareAndSwapUint32(&sessVars.Killed, 1, 0) {
return errors.Trace(errQueryInterrupted)
}
sc := sessVars.StmtCtx
for _, warning := range r.selectResp.Warnings {
sc.AppendWarning(terror.ClassTiKV.New(terror.ErrCode(warning.Code), warning.Msg))
}
Expand Down

0 comments on commit e4f5426

Please sign in to comment.