Skip to content

Commit

Permalink
cherry pick pingcap#19425 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
Lingyu Song authored and ti-srebot committed Sep 8, 2020
1 parent b808e13 commit 78e3e22
Show file tree
Hide file tree
Showing 25 changed files with 1,434 additions and 57 deletions.
2 changes: 1 addition & 1 deletion ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (s *testIntegrationSuite2) TestIssue6101(c *C) {
tk.MustExec("create table t1 (quantity decimal(2) unsigned);")
_, err := tk.Exec("insert into t1 values (500), (-500), (~0), (-1);")
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(errno.ErrWarnDataOutOfRange))
c.Assert(terr.Code(), Equals, errors.ErrCode(errno.ErrWarnDataOutOfRange))
tk.MustExec("drop table t1")

tk.MustExec("set sql_mode=''")
Expand Down
13 changes: 13 additions & 0 deletions ddl/rollingback.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/util/logutil"
Expand Down Expand Up @@ -326,6 +327,18 @@ func convertJob2RollbackJob(w *worker, d *ddlCtx, t *meta.Meta, job *model.Job)
}

if err != nil {
<<<<<<< HEAD
=======
if job.Error == nil {
job.Error = toTError(err)
}
if !job.Error.Equal(errCancelledDDLJob) {
job.Error = terror.GetErrClass(job.Error).Synthesize(terror.ErrCode(job.Error.Code()),
fmt.Sprintf("DDL job rollback, error msg: %s", terror.ToSQLError(job.Error).Message))
}
job.ErrorCount++

>>>>>>> 449587a... *: using standard error to replace terror (#19425)
if job.State != model.JobStateRollingback && job.State != model.JobStateCancelled {
logutil.Logger(w.logCtx).Error("[ddl] run DDL job failed", zap.String("job", job.String()), zap.Error(err))
} else {
Expand Down
5 changes: 3 additions & 2 deletions domain/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain/infosync"
"github.com/pingcap/tidb/errno"
Expand Down Expand Up @@ -458,6 +459,6 @@ func (*testSuite) TestSessionPool(c *C) {
}

func (*testSuite) TestErrorCode(c *C) {
c.Assert(int(ErrInfoSchemaExpired.ToSQLError().Code), Equals, errno.ErrInfoSchemaExpired)
c.Assert(int(ErrInfoSchemaChanged.ToSQLError().Code), Equals, errno.ErrInfoSchemaChanged)
c.Assert(int(terror.ToSQLError(ErrInfoSchemaExpired).Code), Equals, errno.ErrInfoSchemaExpired)
c.Assert(int(terror.ToSQLError(ErrInfoSchemaChanged).Code), Equals, errno.ErrInfoSchemaChanged)
}
27 changes: 17 additions & 10 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,12 +1248,12 @@ func (s *testSuiteP2) TestUnion(c *C) {
err := tk.ExecToErr("select 1 from (select a from t limit 1 union all select a from t limit 1) tmp")
c.Assert(err, NotNil)
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrWrongUsage))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrWrongUsage))

err = tk.ExecToErr("select 1 from (select a from t order by a union all select a from t limit 1) tmp")
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrWrongUsage))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrWrongUsage))

_, err = tk.Exec("(select a from t order by a) union all select a from t limit 1 union all select a from t limit 1")
c.Assert(terror.ErrorEqual(err, plannercore.ErrWrongUsage), IsTrue, Commentf("err %v", err))
Expand Down Expand Up @@ -1630,23 +1630,23 @@ func (s *testSuiteP1) TestJSON(c *C) {
_, err = tk.Exec(`create table test_bad_json(a json default '{}')`)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrBlobCantHaveDefault))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrBlobCantHaveDefault))

_, err = tk.Exec(`create table test_bad_json(a blob default 'hello')`)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrBlobCantHaveDefault))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrBlobCantHaveDefault))

_, err = tk.Exec(`create table test_bad_json(a text default 'world')`)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrBlobCantHaveDefault))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrBlobCantHaveDefault))

// check json fields cannot be used as key.
_, err = tk.Exec(`create table test_bad_json(id int, a json, key (a))`)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrJSONUsedAsKey))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrJSONUsedAsKey))

// check CAST AS JSON.
result = tk.MustQuery(`select CAST('3' AS JSON), CAST('{}' AS JSON), CAST(null AS JSON)`)
Expand Down Expand Up @@ -1744,7 +1744,7 @@ func (s *testSuiteP1) TestGeneratedColumnWrite(c *C) {
if tt.err != 0 {
c.Assert(err, NotNil, Commentf("sql is `%v`", tt.stmt))
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(tt.err), Commentf("sql is %v", tt.stmt))
c.Assert(terr.Code(), Equals, errors.ErrCode(tt.err), Commentf("sql is %v", tt.stmt))
} else {
c.Assert(err, IsNil)
}
Expand Down Expand Up @@ -1915,7 +1915,7 @@ func (s *testSuiteP1) TestGeneratedColumnRead(c *C) {
if tt.err != 0 {
c.Assert(err, NotNil)
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(tt.err))
c.Assert(terr.Code(), Equals, errors.ErrCode(tt.err))
} else {
c.Assert(err, IsNil)
}
Expand Down Expand Up @@ -3283,7 +3283,7 @@ func (s *testSuite) TestContainDotColumn(c *C) {
tk.MustExec("drop table if exists t3")
_, err := tk.Exec("create table t3(s.a char);")
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrWrongTableName))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrWrongTableName))
}

func (s *testSuite) TestCheckIndex(c *C) {
Expand Down Expand Up @@ -4201,7 +4201,7 @@ func (s *testSuiteP2) TestSplitRegion(c *C) {
_, err := tk.Exec(`split table t index idx1 by ("abcd");`)
c.Assert(err, NotNil)
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.WarnDataTruncated))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.WarnDataTruncated))

// Test for split index region.
// Check min value is more than max value.
Expand Down Expand Up @@ -5944,7 +5944,14 @@ func (s *testSplitTable) TestKillTableReader(c *C) {
wg.Add(1)
go func() {
defer wg.Done()
<<<<<<< HEAD
c.Assert(int(errors.Cause(tk.QueryToErr("select * from t")).(*terror.Error).ToSQLError().Code), Equals, int(executor.ErrQueryInterrupted.Code()))
=======
time.Sleep(1 * time.Second)
err := tk.QueryToErr("select * from t")
c.Assert(err, NotNil)
c.Assert(int(terror.ToSQLError(errors.Cause(err).(*terror.Error)).Code), Equals, int(executor.ErrQueryInterrupted.Code()))
>>>>>>> 449587a... *: using standard error to replace terror (#19425)
}()
time.Sleep(1 * time.Second)
atomic.StoreUint32(&tk.Se.GetSessionVars().Killed, 1)
Expand Down
2 changes: 1 addition & 1 deletion executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ func (e *ShowExec) fetchShowWarnings(errOnly bool) error {
warn := errors.Cause(w.Err)
switch x := warn.(type) {
case *terror.Error:
sqlErr := x.ToSQLError()
sqlErr := terror.ToSQLError(x)
e.appendRow([]interface{}{w.Level, int64(sqlErr.Code), sqlErr.Message})
default:
e.appendRow([]interface{}{w.Level, int64(mysql.ErrUnknown), warn.Error()})
Expand Down
4 changes: 2 additions & 2 deletions executor/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (e *TraceExec) executeChild(ctx context.Context, se sqlexec.SQLExecutor) {
if err != nil {
var errCode uint16
if te, ok := err.(*terror.Error); ok {
errCode = te.ToSQLError().Code
errCode = terror.ToSQLError(te).Code
}
logutil.Eventf(ctx, "execute with error(%d): %s", errCode, err.Error())
} else {
Expand All @@ -161,7 +161,7 @@ func drainRecordSet(ctx context.Context, sctx sessionctx.Context, rs sqlexec.Rec
if err != nil {
var errCode uint16
if te, ok := err.(*terror.Error); ok {
errCode = te.ToSQLError().Code
errCode = terror.ToSQLError(te).Code
}
logutil.Eventf(ctx, "execute with error(%d): %s", errCode, err.Error())
} else {
Expand Down
14 changes: 7 additions & 7 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil)
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(rs.Close(), IsNil)

//for exp
Expand All @@ -479,7 +479,7 @@ func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(rs.Close(), IsNil)
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a float)")
Expand All @@ -489,7 +489,7 @@ func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(err.Error(), Equals, "[types:1690]DOUBLE value is out of range in 'exp(test.t.a)'")
c.Assert(rs.Close(), IsNil)

Expand Down Expand Up @@ -529,7 +529,7 @@ func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(rs.Close(), IsNil)

// for round
Expand Down Expand Up @@ -608,7 +608,7 @@ func (s *testIntegrationSuite2) TestMathBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(rs.Close(), IsNil)

// for sign
Expand Down Expand Up @@ -1226,7 +1226,7 @@ func (s *testIntegrationSuite2) TestEncryptionBuiltin(c *C) {
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil, Commentf("%v", len))
terr := errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange), Commentf("%v", len))
c.Assert(terr.Code(), Equals, errors.ErrCode(mysql.ErrDataOutOfRange), Commentf("%v", len))
c.Assert(rs.Close(), IsNil)
}
tk.MustQuery("SELECT RANDOM_BYTES('1');")
Expand Down Expand Up @@ -3691,7 +3691,7 @@ func (s *testIntegrationSuite) TestAggregationBuiltinGroupConcat(c *C) {
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning 1260 Some rows were cut by GROUPCONCAT(test.t.a)"))

_, err := tk.Exec("insert into d select group_concat(a) from t")
c.Assert(errors.Cause(err).(*terror.Error).Code(), Equals, terror.ErrCode(mysql.ErrCutValueGroupConcat))
c.Assert(errors.Cause(err).(*terror.Error).Code(), Equals, errors.ErrCode(mysql.ErrCutValueGroupConcat))

tk.Exec("set sql_mode=''")
tk.MustExec("insert into d select group_concat(a) from t")
Expand Down
20 changes: 20 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
github.com/klauspost/cpuid v1.2.1
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/ngaut/pools v0.0.0-20180318154953-b7bc8c42aac7
github.com/ngaut/sync2 v0.0.0-20141008032647-7a24ed77b2ef
github.com/opentracing/basictracer-go v1.0.0
Expand All @@ -32,7 +34,11 @@ require (
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989
github.com/pingcap/kvproto v0.0.0-20200818080353-7aaed8998596
github.com/pingcap/log v0.0.0-20200828042413-fce0951f1463
<<<<<<< HEAD
github.com/pingcap/parser v0.0.0-20200902091735-5e6adfc24e11
=======
github.com/pingcap/parser v0.0.0-20200908111137-8157d6307003
>>>>>>> 449587a... *: using standard error to replace terror (#19425)
github.com/pingcap/sysutil v0.0.0-20200715082929-4c47bcac246a
github.com/pingcap/tidb-tools v4.0.6-0.20200828085514-03575b185007+incompatible
github.com/pingcap/tipb v0.0.0-20200618092958-4fad48b4c8c3
Expand All @@ -44,20 +50,34 @@ require (
github.com/soheilhy/cmux v0.1.4
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
<<<<<<< HEAD
github.com/tikv/pd v1.1.0-beta.0.20200907080620-6830f5bb92a2
=======
github.com/tikv/pd v1.1.0-beta.0.20200820084926-bcfa77a7a593
github.com/twmb/murmur3 v1.1.3
>>>>>>> 449587a... *: using standard error to replace terror (#19425)
github.com/uber-go/atomic v1.3.2
github.com/uber/jaeger-client-go v2.22.1+incompatible
go.etcd.io/etcd v0.5.0-alpha.5.0.20191023171146-3cf2f69b5738
go.uber.org/atomic v1.6.0
go.uber.org/automaxprocs v1.2.0
<<<<<<< HEAD
go.uber.org/zap v1.15.0
=======
go.uber.org/zap v1.16.0
>>>>>>> 449587a... *: using standard error to replace terror (#19425)
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
golang.org/x/sys v0.0.0-20200819171115-d785dc25833f
golang.org/x/text v0.3.3
golang.org/x/tools v0.0.0-20200820010801-b793a1359eac
<<<<<<< HEAD
=======
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
>>>>>>> 449587a... *: using standard error to replace terror (#19425)
google.golang.org/grpc v1.26.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.3.0 // indirect
sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67
)
Expand Down
Loading

0 comments on commit 78e3e22

Please sign in to comment.