Skip to content

Commit

Permalink
cherry pick pingcap#15592 to release-3.1
Browse files Browse the repository at this point in the history
Signed-off-by: sre-bot <sre-bot@pingcap.com>
  • Loading branch information
tiancaiamao authored and sre-bot committed Mar 24, 2020
1 parent f3de03d commit 5fe2a58
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions distsql/select_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ package distsql
import (
"context"
"fmt"
"sync/atomic"
"time"

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

var (
errQueryInterrupted = terror.ClassExecutor.NewStd(errno.ErrQueryInterrupted)
)

var (
_ SelectResult = (*selectResult)(nil)
_ SelectResult = (*streamResult)(nil)
Expand Down Expand Up @@ -105,13 +111,37 @@ func (r *selectResult) fetch(ctx context.Context) {
var result resultWithErr
resultSubset, err := r.resp.Next(ctx)
if err != nil {
<<<<<<< HEAD
result.err = err
} else if resultSubset == nil {
// If the result is drained, the resultSubset would be nil
return
} else {
result.result = resultSubset
r.memConsume(int64(resultSubset.MemSize()))
=======
return errors.Trace(err)
}
r.selectRespSize = r.selectResp.Size()
r.memConsume(int64(r.selectRespSize))
if err := r.selectResp.Error; err != nil {
return terror.ClassTiKV.Synthesize(terror.ErrCode(err.Code), err.Msg)
}
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.Synthesize(terror.ErrCode(warning.Code), warning.Msg))
}
r.updateCopRuntimeStats(resultSubset.GetExecDetails(), resultSubset.RespTime())
r.feedback.Update(resultSubset.GetStartKey(), r.selectResp.OutputCounts)
r.partialCount++
sc.MergeExecDetails(resultSubset.GetExecDetails(), nil)
if len(r.selectResp.Chunks) != 0 {
break
>>>>>>> 00dc69c... distsql: check the killed flag in the distsql package (#15592)
}

select {
Expand Down

0 comments on commit 5fe2a58

Please sign in to comment.