Skip to content

Commit

Permalink
util: format error code for memory package (pingcap#13540)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingyu Song authored and XiaTianliang committed Dec 21, 2019
1 parent b569824 commit d600361
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions util/memory/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,17 @@ func (a *PanicOnExceed) Action(t *Tracker) {
func (a *PanicOnExceed) SetFallback(ActionOnExceed) {}

var (
errMemExceedThreshold = terror.ClassExecutor.New(codeMemExceedThreshold, mysql.MySQLErrName[mysql.ErrMemExceedThreshold])
errMemExceedThreshold = terror.ClassUtil.New(mysql.ErrMemExceedThreshold, mysql.MySQLErrName[mysql.ErrMemExceedThreshold])
)

const (
codeMemExceedThreshold terror.ErrCode = 8001

// PanicMemoryExceed represents the panic message when out of memory quota.
PanicMemoryExceed string = "Out Of Memory Quota!"
)

func init() {
errCodes := map[terror.ErrCode]uint16{
mysql.ErrMemExceedThreshold: mysql.ErrMemExceedThreshold,
}
terror.ErrClassToMySQLCodes[terror.ClassUtil] = errCodes
}
5 changes: 5 additions & 0 deletions util/memory/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/cznic/mathutil"
. "github.com/pingcap/check"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/stringutil"
"github.com/pingcap/tidb/util/testleak"
Expand Down Expand Up @@ -260,3 +261,7 @@ func BenchmarkConsume(b *testing.B) {
}
})
}

func (s *testSuite) TestErrorCode(c *C) {
c.Assert(int(errMemExceedThreshold.ToSQLError().Code), Equals, mysql.ErrMemExceedThreshold)
}

0 comments on commit d600361

Please sign in to comment.