Skip to content

Commit 970883c

Browse files
authored
Replace pingap/errors with pkg/errors (#8)
* replace pingcap/errors with pkg/errors Signed-off-by: disksing <[email protected]> * get compiled Signed-off-by: disksing <[email protected]> * update meta.go Signed-off-by: disksing <[email protected]> * update txnkv.go Signed-off-by: disksing <[email protected]> * update codec.go Signed-off-by: disksing <[email protected]> * update region_cache.go Signed-off-by: disksing <[email protected]> * update mock.go Signed-off-by: disksing <[email protected]> * update txn_committer.go Signed-off-by: disksing <[email protected]> * update mvcc_leveldb.go Signed-off-by: disksing <[email protected]> * update rawkv.go Signed-off-by: disksing <[email protected]> * update snapshot.go Signed-off-by: disksing <[email protected]> * update lock_resolver.go Signed-off-by: disksing <[email protected]> * update scan.go Signed-off-by: disksing <[email protected]> * update region_request.go Signed-off-by: disksing <[email protected]> * update mvcc.go Signed-off-by: disksing <[email protected]> * update rpc.go, backoff.go client.go Signed-off-by: disksing <[email protected]> * update kv/*.go Signed-off-by: disksing <[email protected]> * update txn.go, pd.go Signed-off-by: disksing <[email protected]> * update txn/store/* Signed-off-by: disksing <[email protected]> * go mod tidy Signed-off-by: disksing <[email protected]>
1 parent 50aef7f commit 970883c

38 files changed

+327
-364
lines changed

codec/bytes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package codec
1616
import (
1717
"bytes"
1818

19-
"github.com/pingcap/errors"
19+
"github.com/pkg/errors"
2020
)
2121

2222
const (

codec/meta.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package codec
1515

1616
import (
17-
"github.com/pingcap/errors"
1817
"github.com/pingcap/kvproto/pkg/metapb"
1918
)
2019

@@ -23,14 +22,14 @@ func DecodeRegionMetaKey(r *metapb.Region) error {
2322
if len(r.StartKey) != 0 {
2423
_, decoded, err := DecodeBytes(r.StartKey)
2524
if err != nil {
26-
return errors.Trace(err)
25+
return err
2726
}
2827
r.StartKey = decoded
2928
}
3029
if len(r.EndKey) != 0 {
3130
_, decoded, err := DecodeBytes(r.EndKey)
3231
if err != nil {
33-
return errors.Trace(err)
32+
return err
3433
}
3534
r.EndKey = decoded
3635
}

codec/numbers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package codec
1616
import (
1717
"encoding/binary"
1818

19-
"github.com/pingcap/errors"
19+
"github.com/pkg/errors"
2020
)
2121

2222
const signMask uint64 = 0x8000000000000000

examples/txnkv/txnkv.go

+10-20
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"fmt"
2020
"os"
2121

22-
"github.com/pingcap/errors"
2322
"github.com/tikv/client-go/config"
2423
"github.com/tikv/client-go/key"
2524
"github.com/tikv/client-go/txnkv"
@@ -51,62 +50,53 @@ func initStore() {
5150
func puts(args ...[]byte) error {
5251
tx, err := client.Begin()
5352
if err != nil {
54-
return errors.Trace(err)
53+
return err
5554
}
5655

5756
for i := 0; i < len(args); i += 2 {
5857
key, val := args[i], args[i+1]
5958
err := tx.Set(key, val)
6059
if err != nil {
61-
return errors.Trace(err)
60+
return err
6261
}
6362
}
64-
err = tx.Commit(context.Background())
65-
if err != nil {
66-
return errors.Trace(err)
67-
}
68-
69-
return nil
63+
return tx.Commit(context.Background())
7064
}
7165

7266
func get(k []byte) (KV, error) {
7367
tx, err := client.Begin()
7468
if err != nil {
75-
return KV{}, errors.Trace(err)
69+
return KV{}, err
7670
}
7771
v, err := tx.Get(k)
7872
if err != nil {
79-
return KV{}, errors.Trace(err)
73+
return KV{}, err
8074
}
8175
return KV{K: k, V: v}, nil
8276
}
8377

8478
func dels(keys ...[]byte) error {
8579
tx, err := client.Begin()
8680
if err != nil {
87-
return errors.Trace(err)
81+
return err
8882
}
8983
for _, key := range keys {
9084
err := tx.Delete(key)
9185
if err != nil {
92-
return errors.Trace(err)
86+
return err
9387
}
9488
}
95-
err = tx.Commit(context.Background())
96-
if err != nil {
97-
return errors.Trace(err)
98-
}
99-
return nil
89+
return tx.Commit(context.Background())
10090
}
10191

10292
func scan(keyPrefix []byte, limit int) ([]KV, error) {
10393
tx, err := client.Begin()
10494
if err != nil {
105-
return nil, errors.Trace(err)
95+
return nil, err
10696
}
10797
it, err := tx.Iter(key.Key(keyPrefix), nil)
10898
if err != nil {
109-
return nil, errors.Trace(err)
99+
return nil, err
110100
}
111101
defer it.Close()
112102
var ret []KV

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ require (
2727
github.com/onsi/gomega v1.4.3 // indirect
2828
github.com/opentracing/opentracing-go v1.0.2 // indirect
2929
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8
30-
github.com/pingcap/errors v0.11.0
3130
github.com/pingcap/gofail v0.0.0-20181217135706-6a951c1e42c3 // indirect
3231
github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e
3332
github.com/pingcap/kvproto v0.0.0-20190305055742-ab7debc182d9

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg
8080
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
8181
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8 h1:USx2/E1bX46VG32FIw034Au6seQ2fY9NEILmNh/UlQg=
8282
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8/go.mod h1:B1+S9LNcuMyLH/4HMTViQOJevkGiik3wW2AN9zb2fNQ=
83-
github.com/pingcap/errors v0.11.0 h1:DCJQB8jrHbQ1VVlMFIrbj2ApScNNotVmkSNplu2yUt4=
84-
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
8583
github.com/pingcap/gofail v0.0.0-20181217135706-6a951c1e42c3 h1:04yuCf5NMvLU8rB2m4Qs3rynH7EYpMno3lHkewIOdMo=
8684
github.com/pingcap/gofail v0.0.0-20181217135706-6a951c1e42c3/go.mod h1:DazNTg0PTldtpsQiT9I5tVJwV1onHMKBBgXzmJUlMns=
8785
github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e h1:P73/4dPCL96rGrobssy1nVy2VaVpNCuLpCbr+FEaTA8=

locate/codec.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package locate
1616
import (
1717
"context"
1818

19-
"github.com/pingcap/errors"
2019
"github.com/pingcap/kvproto/pkg/metapb"
2120
pd "github.com/pingcap/pd/client"
2221
"github.com/tikv/client-go/codec"
@@ -51,14 +50,14 @@ func (c *CodecPDClient) GetRegionByID(ctx context.Context, regionID uint64) (*me
5150

5251
func processRegionResult(region *metapb.Region, peer *metapb.Peer, err error) (*metapb.Region, *metapb.Peer, error) {
5352
if err != nil {
54-
return nil, nil, errors.Trace(err)
53+
return nil, nil, err
5554
}
5655
if region == nil {
5756
return nil, nil, nil
5857
}
5958
err = codec.DecodeRegionMetaKey(region)
6059
if err != nil {
61-
return nil, nil, errors.Trace(err)
60+
return nil, nil, err
6261
}
6362
return region, peer, nil
6463
}

locate/region_cache.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121
"time"
2222

2323
"github.com/google/btree"
24-
"github.com/pingcap/errors"
2524
"github.com/pingcap/kvproto/pkg/kvrpcpb"
2625
"github.com/pingcap/kvproto/pkg/metapb"
2726
"github.com/pingcap/pd/client"
27+
"github.com/pkg/errors"
2828
log "github.com/sirupsen/logrus"
2929
"github.com/tikv/client-go/codec"
3030
"github.com/tikv/client-go/metrics"
@@ -108,7 +108,7 @@ func (c *RegionCache) GetRPCContext(bo *retry.Backoffer, id RegionVerID) (*RPCCo
108108

109109
addr, err := c.GetStoreAddr(bo, peer.GetStoreId())
110110
if err != nil {
111-
return nil, errors.Trace(err)
111+
return nil, err
112112
}
113113
if addr == "" {
114114
// Store not found, region must be out of date.
@@ -153,7 +153,7 @@ func (c *RegionCache) LocateKey(bo *retry.Backoffer, key []byte) (*KeyLocation,
153153

154154
r, err := c.loadRegion(bo, key)
155155
if err != nil {
156-
return nil, errors.Trace(err)
156+
return nil, err
157157
}
158158

159159
c.mu.Lock()
@@ -184,7 +184,7 @@ func (c *RegionCache) LocateRegionByID(bo *retry.Backoffer, regionID uint64) (*K
184184

185185
r, err := c.loadRegionByID(bo, regionID)
186186
if err != nil {
187-
return nil, errors.Trace(err)
187+
return nil, err
188188
}
189189

190190
c.mu.Lock()
@@ -209,7 +209,7 @@ func (c *RegionCache) GroupKeysByRegion(bo *retry.Backoffer, keys [][]byte) (map
209209
var err error
210210
lastLoc, err = c.LocateKey(bo, k)
211211
if err != nil {
212-
return nil, first, errors.Trace(err)
212+
return nil, first, err
213213
}
214214
}
215215
id := lastLoc.Region
@@ -226,7 +226,7 @@ func (c *RegionCache) ListRegionIDsInKeyRange(bo *retry.Backoffer, startKey, end
226226
for {
227227
curRegion, err := c.LocateKey(bo, startKey)
228228
if err != nil {
229-
return nil, errors.Trace(err)
229+
return nil, err
230230
}
231231
regionIDs = append(regionIDs, curRegion.Region.id)
232232
if curRegion.Contains(endKey) {
@@ -334,7 +334,7 @@ func (c *RegionCache) loadRegion(bo *retry.Backoffer, key []byte) (*Region, erro
334334
if backoffErr != nil {
335335
err := bo.Backoff(retry.BoPDRPC, backoffErr)
336336
if err != nil {
337-
return nil, errors.Trace(err)
337+
return nil, err
338338
}
339339
}
340340
meta, leader, err := c.pdClient.GetRegion(bo.GetContext(), key)
@@ -368,7 +368,7 @@ func (c *RegionCache) loadRegionByID(bo *retry.Backoffer, regionID uint64) (*Reg
368368
if backoffErr != nil {
369369
err := bo.Backoff(retry.BoPDRPC, backoffErr)
370370
if err != nil {
371-
return nil, errors.Trace(err)
371+
return nil, err
372372
}
373373
}
374374
meta, leader, err := c.pdClient.GetRegionByID(bo.GetContext(), regionID)
@@ -411,7 +411,7 @@ func (c *RegionCache) GetStoreAddr(bo *retry.Backoffer, id uint64) (string, erro
411411
func (c *RegionCache) ReloadStoreAddr(bo *retry.Backoffer, id uint64) (string, error) {
412412
addr, err := c.loadStoreAddr(bo, id)
413413
if err != nil || addr == "" {
414-
return "", errors.Trace(err)
414+
return "", err
415415
}
416416

417417
c.storeMu.Lock()
@@ -436,11 +436,11 @@ func (c *RegionCache) loadStoreAddr(bo *retry.Backoffer, id uint64) (string, err
436436
metrics.RegionCacheCounter.WithLabelValues("get_store", metrics.RetLabel(err)).Inc()
437437
if err != nil {
438438
if errors.Cause(err) == context.Canceled {
439-
return "", errors.Trace(err)
439+
return "", err
440440
}
441441
err = errors.Errorf("loadStore from PD failed, id: %d, err: %v", id, err)
442442
if err = bo.Backoff(retry.BoPDRPC, err); err != nil {
443-
return "", errors.Trace(err)
443+
return "", err
444444
}
445445
continue
446446
}

mockstore/mocktikv/mock.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package mocktikv
1515

1616
import (
17-
"github.com/pingcap/errors"
1817
"github.com/pingcap/pd/client"
1918
)
2019

@@ -29,7 +28,7 @@ func NewTiKVAndPDClient(cluster *Cluster, mvccStore MVCCStore, path string) (*RP
2928
var err error
3029
mvccStore, err = NewMVCCLevelDB(path)
3130
if err != nil {
32-
return nil, nil, errors.Trace(err)
31+
return nil, nil, err
3332
}
3433
}
3534

mockstore/mocktikv/mvcc.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"sort"
2222

2323
"github.com/google/btree"
24-
"github.com/pingcap/errors"
2524
"github.com/pingcap/kvproto/pkg/kvrpcpb"
25+
"github.com/pkg/errors"
2626
"github.com/tikv/client-go/codec"
2727
)
2828

@@ -66,7 +66,7 @@ func (l *mvccLock) MarshalBinary() ([]byte, error) {
6666
mh.WriteSlice(&buf, l.value)
6767
mh.WriteNumber(&buf, l.op)
6868
mh.WriteNumber(&buf, l.ttl)
69-
return buf.Bytes(), errors.Trace(mh.err)
69+
return buf.Bytes(), mh.err
7070
}
7171

7272
// UnmarshalBinary implements encoding.BinaryUnmarshaler interface.
@@ -78,7 +78,7 @@ func (l *mvccLock) UnmarshalBinary(data []byte) error {
7878
mh.ReadSlice(buf, &l.value)
7979
mh.ReadNumber(buf, &l.op)
8080
mh.ReadNumber(buf, &l.ttl)
81-
return errors.Trace(mh.err)
81+
return mh.err
8282
}
8383

8484
// MarshalBinary implements encoding.BinaryMarshaler interface.
@@ -91,7 +91,7 @@ func (v mvccValue) MarshalBinary() ([]byte, error) {
9191
mh.WriteNumber(&buf, v.startTS)
9292
mh.WriteNumber(&buf, v.commitTS)
9393
mh.WriteSlice(&buf, v.value)
94-
return buf.Bytes(), errors.Trace(mh.err)
94+
return buf.Bytes(), mh.err
9595
}
9696

9797
// UnmarshalBinary implements encoding.BinaryUnmarshaler interface.
@@ -104,7 +104,7 @@ func (v *mvccValue) UnmarshalBinary(data []byte) error {
104104
mh.ReadNumber(buf, &v.startTS)
105105
mh.ReadNumber(buf, &v.commitTS)
106106
mh.ReadSlice(buf, &v.value)
107-
return errors.Trace(mh.err)
107+
return mh.err
108108
}
109109

110110
type marshalHelper struct {
@@ -118,11 +118,11 @@ func (mh *marshalHelper) WriteSlice(buf io.Writer, slice []byte) {
118118
var tmp [binary.MaxVarintLen64]byte
119119
off := binary.PutUvarint(tmp[:], uint64(len(slice)))
120120
if err := writeFull(buf, tmp[:off]); err != nil {
121-
mh.err = errors.Trace(err)
121+
mh.err = err
122122
return
123123
}
124124
if err := writeFull(buf, slice); err != nil {
125-
mh.err = errors.Trace(err)
125+
mh.err = err
126126
}
127127
}
128128

@@ -132,7 +132,7 @@ func (mh *marshalHelper) WriteNumber(buf io.Writer, n interface{}) {
132132
}
133133
err := binary.Write(buf, binary.LittleEndian, n)
134134
if err != nil {
135-
mh.err = errors.Trace(err)
135+
mh.err = errors.WithStack(err)
136136
}
137137
}
138138

@@ -141,7 +141,7 @@ func writeFull(w io.Writer, slice []byte) error {
141141
for written < len(slice) {
142142
n, err := w.Write(slice[written:])
143143
if err != nil {
144-
return errors.Trace(err)
144+
return errors.WithStack(err)
145145
}
146146
written += n
147147
}
@@ -154,7 +154,7 @@ func (mh *marshalHelper) ReadNumber(r io.Reader, n interface{}) {
154154
}
155155
err := binary.Read(r, binary.LittleEndian, n)
156156
if err != nil {
157-
mh.err = errors.Trace(err)
157+
mh.err = errors.WithStack(err)
158158
}
159159
}
160160

@@ -164,7 +164,7 @@ func (mh *marshalHelper) ReadSlice(r *bytes.Buffer, slice *[]byte) {
164164
}
165165
sz, err := binary.ReadUvarint(r)
166166
if err != nil {
167-
mh.err = errors.Trace(err)
167+
mh.err = errors.WithStack(err)
168168
return
169169
}
170170
const c10M = 10 * 1024 * 1024
@@ -174,7 +174,7 @@ func (mh *marshalHelper) ReadSlice(r *bytes.Buffer, slice *[]byte) {
174174
}
175175
data := make([]byte, sz)
176176
if _, err := io.ReadFull(r, data); err != nil {
177-
mh.err = errors.Trace(err)
177+
mh.err = errors.WithStack(err)
178178
return
179179
}
180180
*slice = data

0 commit comments

Comments
 (0)