Skip to content

Commit

Permalink
add ErrIncorrectIndexCount
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <ekexium@gmail.com>
  • Loading branch information
ekexium committed Dec 7, 2021
1 parent b985104 commit 5cb41f9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions errno/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ const (
ErrAsOf = 8135
ErrVariableNoLongerSupported = 8136
ErrAnalyzeMissColumn = 8137
ErrIncorrectIndexCount = 8140

// Error codes used by TiDB ddl package
ErrUnsupportedDDLOperation = 8200
Expand Down
1 change: 1 addition & 0 deletions errno/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{
ErrInvalidIncrementAndOffset: mysql.Message("Invalid auto_increment settings: auto_increment_increment: %d, auto_increment_offset: %d, both of them must be in range [1..65535]", nil),
ErrDataInconsistentMismatchCount: mysql.Message("data inconsistency in table: %s, index: %s, index-count:%d != record-count:%d", nil),
ErrDataInconsistentMismatchIndex: mysql.Message("data inconsistency in table: %s, index: %s, col: %s, handle: %#v, index-values:%#v != record-values:%#v, compare err:%#v", []int{3, 4, 5, 6}),
ErrIncorrectIndexCount: mysql.Message("incorrect index count in txn, row insertions: %d, index insertions: %d", nil),

ErrWarnOptimizerHintInvalidInteger: mysql.Message("integer value is out of range in '%s'", nil),
ErrWarnOptimizerHintUnsupportedHint: mysql.Message("Optimizer hint %s is not supported by TiDB and is ignored", nil),
Expand Down
5 changes: 5 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,11 @@ error = '''
column %s can't be in none state
'''

["table:8140"]
error = '''
incorrect index count in txn, row insertions: %d, index insertions: %d
'''

["tikv:1105"]
error = '''
Unknown error
Expand Down
5 changes: 1 addition & 4 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ import (
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/statistics/handle"
"github.com/pingcap/tidb/table/tables"
storeerr "github.com/pingcap/tidb/store/driver/error"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/telemetry"
"github.com/pingcap/tidb/types"
Expand All @@ -89,12 +89,9 @@ import (
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/tableutil"
"github.com/pingcap/tidb/util/timeutil"
"github.com/pingcap/tidb/util/topsql"
"github.com/pingcap/tipb/go-binlog"
tikvstore "github.com/tikv/client-go/v2/kv"
"github.com/tikv/client-go/v2/tikv"
tikvutil "github.com/tikv/client-go/v2/util"
"go.uber.org/zap"
)

var (
Expand Down
8 changes: 6 additions & 2 deletions table/tables/mutation_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@ import (
"fmt"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/dbterror"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/rowcodec"
"go.uber.org/zap"
)

// ErrIncorrectIndexCount indicates that #(index_insertion) is not a multiple of #(row_insertion).
var ErrIncorrectIndexCount = dbterror.ClassTable.NewStd(errno.ErrIncorrectIndexCount)

type mutation struct {
key kv.Key
flags kv.KeyFlags
Expand Down Expand Up @@ -404,8 +409,7 @@ func CheckTxnConsistency(txn kv.Transaction) error {
for tableID, count := range indexInsertionCount {
// TODO: always? what if like backfilling?
if rowInsertionCount[tableID] > 0 && count%rowInsertionCount[tableID] != 0 {
return errors.Errorf("inconsistent index insertion count %d and row insertion count %d",
count, rowInsertionCount[tableID])
return ErrIncorrectIndexCount.GenWithStackByArgs(count, rowInsertionCount[tableID])
}
}
return nil
Expand Down

0 comments on commit 5cb41f9

Please sign in to comment.