Skip to content

Commit

Permalink
*: admin check table return tidb specific error code. (pingcap#7363)
Browse files Browse the repository at this point in the history
  • Loading branch information
winkyao authored and zz-jason committed Aug 14, 2018
1 parent 7523566 commit d1f2587
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"

. "github.com/pingcap/check"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/types"
Expand Down Expand Up @@ -100,6 +101,7 @@ func (s *testSuite) TestAdminRecoverIndex(c *C) {
c.Assert(err, IsNil)
_, err = tk.Exec("admin check table admin_test")
c.Assert(err, NotNil)
c.Assert(executor.ErrAdminCheckTable.Equal(err), IsTrue)
_, err = tk.Exec("admin check index admin_test c2")
c.Assert(err, NotNil)

Expand Down
2 changes: 2 additions & 0 deletions executor/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var (
ErrPasswordFormat = terror.ClassExecutor.New(mysql.ErrPasswordFormat, mysql.MySQLErrName[mysql.ErrPasswordFormat])
ErrCantChangeTxCharacteristics = terror.ClassExecutor.New(mysql.ErrCantChangeTxCharacteristics, mysql.MySQLErrName[mysql.ErrCantChangeTxCharacteristics])
ErrPsManyParam = terror.ClassExecutor.New(mysql.ErrPsManyParam, mysql.MySQLErrName[mysql.ErrPsManyParam])
ErrAdminCheckTable = terror.ClassExecutor.New(mysql.ErrAdminCheckTable, mysql.MySQLErrName[mysql.ErrAdminCheckTable])
)

func init() {
Expand All @@ -53,6 +54,7 @@ func init() {
mysql.ErrPasswordFormat: mysql.ErrPasswordFormat,
mysql.ErrCantChangeTxCharacteristics: mysql.ErrCantChangeTxCharacteristics,
mysql.ErrPsManyParam: mysql.ErrPsManyParam,
mysql.ErrAdminCheckTable: mysql.ErrAdminCheckTable,
}
terror.ErrClassToMySQLCodes[terror.ClassExecutor] = tableMySQLErrCodes
}
4 changes: 4 additions & 0 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ func (e *CheckTableExec) Next(ctx context.Context, chk *chunk.Chunk) error {
}
if err != nil {
log.Warnf("%v error:%v", t.Name, errors.ErrorStack(err))
if admin.ErrDataInConsistent.Equal(err) {
return ErrAdminCheckTable.Gen("%v err:%v", t.Name, err)
}

return errors.Errorf("%v err:%v", t.Name, err)
}
}
Expand Down
1 change: 1 addition & 0 deletions mysql/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ const (
// TiDB self-defined errors.
ErrMemExceedThreshold = 8001
ErrForUpdateCantRetry = 8002
ErrAdminCheckTable = 8003

// TiKV/PD errors.
ErrPDServerTimeout = 9001
Expand Down
7 changes: 5 additions & 2 deletions mysql/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,11 @@ var MySQLErrName = map[uint16]string{
ErrInvalidJSONPath: "Invalid JSON path expression %s.",
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",

// TiDB errors.
ErrMemExceedThreshold: "%s holds %dB memory, exceeds threshold %dB.%s",
ErrForUpdateCantRetry: "[%d] can not retry select for update statement",
ErrAdminCheckTable: "TiDB admin check table failed.",

// TiKV/PD errors.
ErrPDServerTimeout: "PD server timeout",
Expand Down
17 changes: 9 additions & 8 deletions util/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func checkIndexAndRecord(sessCtx sessionctx.Context, txn kv.Transaction, t table
vals2 = tables.TruncateIndexValuesIfNeeded(t.Meta(), idx.Meta(), vals2)
if kv.ErrNotExist.Equal(err) {
record := &RecordData{Handle: h, Values: vals1}
err = errDateNotEqual.Gen("index:%#v != record:%#v", record, nil)
err = ErrDataInConsistent.Gen("index:%#v != record:%#v", record, nil)
}
if err != nil {
return errors.Trace(err)
Expand All @@ -375,7 +375,7 @@ func checkIndexAndRecord(sessCtx sessionctx.Context, txn kv.Transaction, t table
if !reflect.DeepEqual(vals1, vals2) {
record1 := &RecordData{Handle: h, Values: vals1}
record2 := &RecordData{Handle: h, Values: vals2}
return errDateNotEqual.Gen("index:%#v != record:%#v", record1, record2)
return ErrDataInConsistent.Gen("index:%#v != record:%#v", record1, record2)
}
}

Expand Down Expand Up @@ -410,14 +410,14 @@ func CheckRecordAndIndex(sessCtx sessionctx.Context, txn kv.Transaction, t table
if kv.ErrKeyExists.Equal(err) {
record1 := &RecordData{Handle: h1, Values: vals1}
record2 := &RecordData{Handle: h2, Values: vals1}
return false, errDateNotEqual.Gen("index:%#v != record:%#v", record2, record1)
return false, ErrDataInConsistent.Gen("index:%#v != record:%#v", record2, record1)
}
if err != nil {
return false, errors.Trace(err)
}
if !isExist {
record := &RecordData{Handle: h1, Values: vals1}
return false, errDateNotEqual.Gen("index:%#v != record:%#v", nil, record)
return false, ErrDataInConsistent.Gen("index:%#v != record:%#v", nil, record)
}

return true, nil
Expand Down Expand Up @@ -505,7 +505,7 @@ func CompareTableRecord(sessCtx sessionctx.Context, txn kv.Transaction, t table.
vals2, ok := m[h]
if !ok {
record := &RecordData{Handle: h, Values: vals}
return false, errDateNotEqual.Gen("data:%#v != record:%#v", nil, record)
return false, ErrDataInConsistent.Gen("data:%#v != record:%#v", nil, record)
}
if !exact {
delete(m, h)
Expand All @@ -515,7 +515,7 @@ func CompareTableRecord(sessCtx sessionctx.Context, txn kv.Transaction, t table.
if !reflect.DeepEqual(vals, vals2) {
record1 := &RecordData{Handle: h, Values: vals2}
record2 := &RecordData{Handle: h, Values: vals}
return false, errDateNotEqual.Gen("data:%#v != record:%#v", record1, record2)
return false, ErrDataInConsistent.Gen("data:%#v != record:%#v", record1, record2)
}

delete(m, h)
Expand All @@ -529,7 +529,7 @@ func CompareTableRecord(sessCtx sessionctx.Context, txn kv.Transaction, t table.

for h, vals := range m {
record := &RecordData{Handle: h, Values: vals}
return errDateNotEqual.Gen("data:%#v != record:%#v", record, nil)
return ErrDataInConsistent.Gen("data:%#v != record:%#v", record, nil)
}

return nil
Expand Down Expand Up @@ -660,7 +660,8 @@ const (
)

var (
errDateNotEqual = terror.ClassAdmin.New(codeDataNotEqual, "data isn't equal")
// ErrDataInConsistent indicate that meets inconsistent data.
ErrDataInConsistent = terror.ClassAdmin.New(codeDataNotEqual, "data isn't equal")
errRepeatHandle = terror.ClassAdmin.New(codeRepeatHandle, "handle is repeated")
errInvalidColumnState = terror.ClassAdmin.New(codeInvalidColumnState, "invalid column state")
)

0 comments on commit d1f2587

Please sign in to comment.