Skip to content

Commit

Permalink
session: add an error type for session (pingcap#6496)
Browse files Browse the repository at this point in the history
* add an error type for session
  • Loading branch information
jackysp authored and ngaut committed May 8, 2018
1 parent 8d345cd commit 96ac1c7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions mysql/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ const (

// TiDB self-defined errors.
ErrMemExceedThreshold = 8001
ErrForUpdateCantRetry = 8002

// TiKV/PD errors.
ErrPDServerTimeout = 9001
Expand Down
1 change: 1 addition & 0 deletions mysql/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ var MySQLErrName = map[uint16]string{
ErrInvalidJSONData: "Invalid data type for JSON data",
ErrJSONUsedAsKey: "JSON column '%-.192s' cannot be used in key specification.",
ErrMemExceedThreshold: "%s holds %dB memory, exceeds threshold %dB.%s",
ErrForUpdateCantRetry: "[%d] can not retry select for update statement",

// TiKV/PD errors.
ErrPDServerTimeout: "PD server timeout",
Expand Down
2 changes: 1 addition & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (s *session) retry(ctx context.Context, maxCnt uint) error {

connID := s.sessionVars.ConnectionID
if s.sessionVars.TxnCtx.ForUpdate {
return errors.Errorf("[%d] can not retry select for update statement", connID)
return errForUpdateCantRetry.GenByArgs(connID)
}
s.sessionVars.RetryInfo.Retrying = true
var retryCnt uint
Expand Down
14 changes: 14 additions & 0 deletions session/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/terror"
Expand Down Expand Up @@ -330,5 +331,18 @@ func IsQuery(sql string) bool {
return false
}

var (
errForUpdateCantRetry = terror.ClassSession.New(codeForUpdateCantRetry,
mysql.MySQLErrName[mysql.ErrForUpdateCantRetry])
)

const (
codeForUpdateCantRetry terror.ErrCode = mysql.ErrForUpdateCantRetry
)

func init() {
sessionMySQLErrCodes := map[terror.ErrCode]uint16{
codeForUpdateCantRetry: mysql.ErrForUpdateCantRetry,
}
terror.ErrClassToMySQLCodes[terror.ClassSession] = sessionMySQLErrCodes
}
2 changes: 2 additions & 0 deletions terror/terror.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const (
ClassMockTikv
ClassJSON
ClassTiKV
ClassSession
// Add more as needed.
)

Expand Down Expand Up @@ -110,6 +111,7 @@ var errClz2Str = map[ErrClass]string{
ClassMockTikv: "mocktikv",
ClassJSON: "json",
ClassTiKV: "tikv",
ClassSession: "session",
}

// String implements fmt.Stringer interface.
Expand Down

0 comments on commit 96ac1c7

Please sign in to comment.