-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
Copy patherror.go
170 lines (142 loc) · 5.63 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package error //nolint: predeclared
import (
stderrs "errors"
"github.com/pingcap/errors"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/terror"
"github.com/pingcap/tidb/util/dbterror"
tikverr "github.com/tikv/client-go/v2/error"
)
// tikv error instance
var (
// ErrTokenLimit is the error that token is up to the limit.
ErrTokenLimit = dbterror.ClassTiKV.NewStd(errno.ErrTiKVStoreLimit)
// ErrTiKVServerTimeout is the error when tikv server is timeout.
ErrTiKVServerTimeout = dbterror.ClassTiKV.NewStd(errno.ErrTiKVServerTimeout)
ErrTiFlashServerTimeout = dbterror.ClassTiKV.NewStd(errno.ErrTiFlashServerTimeout)
// ErrGCTooEarly is the error that GC life time is shorter than transaction duration
ErrGCTooEarly = dbterror.ClassTiKV.NewStd(errno.ErrGCTooEarly)
// ErrTiKVStaleCommand is the error that the command is stale in tikv.
ErrTiKVStaleCommand = dbterror.ClassTiKV.NewStd(errno.ErrTiKVStaleCommand)
// ErrQueryInterrupted is the error when the query is interrupted.
ErrQueryInterrupted = dbterror.ClassTiKV.NewStd(errno.ErrQueryInterrupted)
// ErrTiKVMaxTimestampNotSynced is the error that tikv's max timestamp is not synced.
ErrTiKVMaxTimestampNotSynced = dbterror.ClassTiKV.NewStd(errno.ErrTiKVMaxTimestampNotSynced)
// ErrLockAcquireFailAndNoWaitSet is the error that acquire the lock failed while no wait is setted.
ErrLockAcquireFailAndNoWaitSet = dbterror.ClassTiKV.NewStd(errno.ErrLockAcquireFailAndNoWaitSet)
ErrResolveLockTimeout = dbterror.ClassTiKV.NewStd(errno.ErrResolveLockTimeout)
// ErrLockWaitTimeout is the error that wait for the lock is timeout.
ErrLockWaitTimeout = dbterror.ClassTiKV.NewStd(errno.ErrLockWaitTimeout)
// ErrTiKVServerBusy is the error when tikv server is busy.
ErrTiKVServerBusy = dbterror.ClassTiKV.NewStd(errno.ErrTiKVServerBusy)
// ErrTiFlashServerBusy is the error that tiflash server is busy.
ErrTiFlashServerBusy = dbterror.ClassTiKV.NewStd(errno.ErrTiFlashServerBusy)
// ErrPDServerTimeout is the error when pd server is timeout.
ErrPDServerTimeout = dbterror.ClassTiKV.NewStd(errno.ErrPDServerTimeout)
// ErrRegionUnavailable is the error when region is not available.
ErrRegionUnavailable = dbterror.ClassTiKV.NewStd(errno.ErrRegionUnavailable)
// ErrUnknown is the unknow error.
ErrUnknown = dbterror.ClassTiKV.NewStd(errno.ErrUnknown)
)
// Registers error returned from TiKV.
var (
_ = dbterror.ClassTiKV.NewStd(errno.ErrDataOutOfRange)
_ = dbterror.ClassTiKV.NewStd(errno.ErrTruncatedWrongValue)
_ = dbterror.ClassTiKV.NewStd(errno.ErrDivisionByZero)
)
// ToTiDBErr checks and converts a tikv error to a tidb error.
func ToTiDBErr(err error) error {
if err == nil {
return nil
}
if tikverr.IsErrNotFound(err) {
return kv.ErrNotExist
}
var writeConflictInLatch *tikverr.ErrWriteConflictInLatch
if stderrs.As(err, &writeConflictInLatch) {
return kv.ErrWriteConflictInTiDB.FastGenByArgs(writeConflictInLatch.StartTS)
}
var txnTooLarge *tikverr.ErrTxnTooLarge
if stderrs.As(err, &txnTooLarge) {
return kv.ErrTxnTooLarge.GenWithStackByArgs(txnTooLarge.Size)
}
if stderrs.Is(err, tikverr.ErrCannotSetNilValue) {
return kv.ErrCannotSetNilValue
}
var entryTooLarge *tikverr.ErrEntryTooLarge
if stderrs.As(err, &entryTooLarge) {
return kv.ErrEntryTooLarge.GenWithStackByArgs(entryTooLarge.Limit, entryTooLarge.Size)
}
if stderrs.Is(err, tikverr.ErrInvalidTxn) {
return kv.ErrInvalidTxn
}
if stderrs.Is(err, tikverr.ErrTiKVServerTimeout) {
return ErrTiKVServerTimeout
}
var pdServerTimeout *tikverr.ErrPDServerTimeout
if stderrs.As(err, &pdServerTimeout) {
if len(pdServerTimeout.Error()) == 0 {
return ErrPDServerTimeout
}
return ErrPDServerTimeout.GenWithStackByArgs(pdServerTimeout.Error())
}
if stderrs.Is(err, tikverr.ErrTiFlashServerTimeout) {
return ErrTiFlashServerTimeout
}
if stderrs.Is(err, tikverr.ErrQueryInterrupted) {
return ErrQueryInterrupted
}
if stderrs.Is(err, tikverr.ErrTiKVServerBusy) {
return ErrTiKVServerBusy
}
if stderrs.Is(err, tikverr.ErrTiFlashServerBusy) {
return ErrTiFlashServerBusy
}
var gcTooEarly *tikverr.ErrGCTooEarly
if stderrs.As(err, &gcTooEarly) {
return ErrGCTooEarly.GenWithStackByArgs(gcTooEarly.TxnStartTS, gcTooEarly.GCSafePoint)
}
if stderrs.Is(err, tikverr.ErrTiKVStaleCommand) {
return ErrTiKVStaleCommand
}
if stderrs.Is(err, tikverr.ErrTiKVMaxTimestampNotSynced) {
return ErrTiKVMaxTimestampNotSynced
}
if stderrs.Is(err, tikverr.ErrLockAcquireFailAndNoWaitSet) {
return ErrLockAcquireFailAndNoWaitSet
}
if stderrs.Is(err, tikverr.ErrResolveLockTimeout) {
return ErrResolveLockTimeout
}
if stderrs.Is(err, tikverr.ErrLockWaitTimeout) {
return ErrLockWaitTimeout
}
if stderrs.Is(err, tikverr.ErrRegionUnavailable) {
return ErrRegionUnavailable
}
var tokenLimit *tikverr.ErrTokenLimit
if stderrs.As(err, &tokenLimit) {
return ErrTokenLimit.GenWithStackByArgs(tokenLimit.StoreID)
}
if stderrs.Is(err, tikverr.ErrUnknown) {
return ErrUnknown
}
if tikverr.IsErrorUndetermined(err) {
return terror.ErrResultUndetermined
}
return errors.Trace(err)
}