forked from ngaut/unistore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
127 lines (104 loc) · 3 KB
/
errors.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
// Copyright 2019-present 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,
// See the License for the specific language governing permissions and
// limitations under the License.
package tikv
import (
"fmt"
"github.com/ngaut/unistore/tikv/mvcc"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
)
// ErrLocked is returned when trying to Read/Write on a locked key. Client should
// backoff or cleanup the lock then retry.
type ErrLocked struct {
Key []byte
Lock *mvcc.MvccLock
}
// BuildLockErr generates ErrKeyLocked objects
func BuildLockErr(key []byte, lock *mvcc.MvccLock) *ErrLocked {
errLocked := &ErrLocked{
Key: key,
Lock: lock,
}
return errLocked
}
// Error formats the lock to a string.
func (e *ErrLocked) Error() string {
lock := e.Lock
return fmt.Sprintf(
"key is locked, key: %q, Type: %v, primary: %q, startTS: %v, forUpdateTS: %v, useAsyncCommit: %v",
e.Key, lock.Op, lock.Primary, lock.StartTS, lock.ForUpdateTS, lock.UseAsyncCommit,
)
}
// ErrRetryable suggests that client may restart the txn. e.g. write conflict.
type ErrRetryable string
func (e ErrRetryable) Error() string {
return fmt.Sprintf("retryable: %s", string(e))
}
var (
ErrLockNotFound = ErrRetryable("lock not found")
ErrAlreadyRollback = ErrRetryable("already rollback")
ErrReplaced = ErrRetryable("replaced by another transaction")
)
type ErrInvalidOp struct {
op kvrpcpb.Op
}
func (e ErrInvalidOp) Error() string {
return fmt.Sprintf("invalid op: %s", e.op.String())
}
// ErrAlreadyCommitted is returned specially when client tries to rollback a
// committed lock.
type ErrAlreadyCommitted uint64
func (e ErrAlreadyCommitted) Error() string {
return "txn already committed"
}
type ErrKeyAlreadyExists struct {
Key []byte
}
func (e ErrKeyAlreadyExists) Error() string {
return "key already exists"
}
// ErrDeadlock is returned when deadlock is detected.
type ErrDeadlock struct {
LockKey []byte
LockTS uint64
DeadlockKeyHash uint64
}
func (e ErrDeadlock) Error() string {
return "deadlock"
}
type ErrConflict struct {
StartTS uint64
ConflictTS uint64
ConflictCommitTS uint64
Key []byte
}
func (e *ErrConflict) Error() string {
return "write conflict"
}
// ErrCommitExpire is returned when commit key commitTs smaller than lock.MinCommitTs
type ErrCommitExpire struct {
StartTs uint64
CommitTs uint64
MinCommitTs uint64
Key []byte
}
func (e *ErrCommitExpire) Error() string {
return "commit expired"
}
// ErrTxnNotFound is returned if the required txn info not found on storage
type ErrTxnNotFound struct {
StartTS uint64
PrimaryKey []byte
}
func (e *ErrTxnNotFound) Error() string {
return "txn not found"
}