From bb8f03c78cdc9601d67bcca2e633d44fa6d13e5c Mon Sep 17 00:00:00 2001 From: imtbkcat Date: Mon, 18 Nov 2019 15:09:57 +0800 Subject: [PATCH 1/2] format error code --- util/memory/action.go | 11 ++++++++--- util/memory/tracker_test.go | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/util/memory/action.go b/util/memory/action.go index a71d74a877082..6c64a2667fdf0 100644 --- a/util/memory/action.go +++ b/util/memory/action.go @@ -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 +} diff --git a/util/memory/tracker_test.go b/util/memory/tracker_test.go index 62cc7271f774d..34618fd22b7b9 100644 --- a/util/memory/tracker_test.go +++ b/util/memory/tracker_test.go @@ -22,6 +22,7 @@ import ( "github.com/cznic/mathutil" . "github.com/pingcap/check" "github.com/pingcap/tidb/util/logutil" + "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/util/stringutil" "github.com/pingcap/tidb/util/testleak" ) @@ -260,3 +261,7 @@ func BenchmarkConsume(b *testing.B) { } }) } + +func (s *testSuite) TestErrorCode(c *C) { + c.Assert(int(errMemExceedThreshold.ToSQLError().Code), Equals, mysql.ErrMemExceedThreshold) +} From 80f667a0ecc9ed7e5679ec2a4921fb8a2cc824b8 Mon Sep 17 00:00:00 2001 From: imtbkcat Date: Mon, 18 Nov 2019 15:50:11 +0800 Subject: [PATCH 2/2] fmt project --- util/memory/tracker_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/memory/tracker_test.go b/util/memory/tracker_test.go index 34618fd22b7b9..3256223029ceb 100644 --- a/util/memory/tracker_test.go +++ b/util/memory/tracker_test.go @@ -21,8 +21,8 @@ import ( "github.com/cznic/mathutil" . "github.com/pingcap/check" - "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/parser/mysql" + "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/stringutil" "github.com/pingcap/tidb/util/testleak" )