Skip to content

Commit 4f74f89

Browse files
committed
update golangci-lint to 2.2.1
Signed-off-by: Philip Dubé <philip.dube@clickhouse.com>
1 parent 6aca9d2 commit 4f74f89

File tree

30 files changed

+157
-142
lines changed

30 files changed

+157
-142
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
git diff --exit-code
5151
5252
- name: Lint
53-
uses: golangci/golangci-lint-action@v3
53+
uses: golangci/golangci-lint-action@v8
5454
with:
55-
version: v1.61.0
55+
version: v2.2.1
5656
skip-pkg-cache: true

.golangci.yml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1-
run:
2-
timeout: 5m
1+
version: "2"
32
linters:
4-
disable-all: true
3+
default: none
54
enable:
65
- bodyclose
7-
#- depguard
8-
- exportloopref
9-
- gofmt
10-
- goimports
116
- goprintffuncname
12-
- gosimple
137
- govet
148
- ineffassign
159
- misspell
1610
- noctx
1711
- nolintlint
1812
- staticcheck
19-
- typecheck
2013
- unconvert
2114
- unused
15+
exclusions:
16+
generated: lax
17+
presets:
18+
- comments
19+
- common-false-positives
20+
- legacy
21+
- std-error-handling
22+
paths:
23+
- third_party$
24+
- builtin$
25+
- examples$
26+
formatters:
27+
enable:
28+
- gofmt
29+
- goimports
30+
exclusions:
31+
generated: lax
32+
paths:
33+
- third_party$
34+
- builtin$
35+
- examples$

error/error.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ type ErrDeadlock struct {
129129
}
130130

131131
func (d *ErrDeadlock) Error() string {
132-
return d.Deadlock.String()
132+
return d.String()
133133
}
134134

135135
// PDError wraps *pdpb.Error to implement the error interface.
@@ -152,7 +152,7 @@ type ErrKeyExist struct {
152152
}
153153

154154
func (k *ErrKeyExist) Error() string {
155-
return k.AlreadyExist.String()
155+
return k.String()
156156
}
157157

158158
// IsErrKeyExist returns true if it is ErrKeyExist.
@@ -167,7 +167,7 @@ type ErrWriteConflict struct {
167167
}
168168

169169
func (k *ErrWriteConflict) Error() string {
170-
return fmt.Sprintf("write conflict { %s }", k.WriteConflict.String())
170+
return fmt.Sprintf("write conflict { %s }", k.String())
171171
}
172172

173173
// IsErrWriteConflict returns true if it is ErrWriteConflict.
@@ -310,7 +310,7 @@ type ErrLockOnlyIfExistsNoPrimaryKey struct {
310310
}
311311

312312
func (e *ErrAssertionFailed) Error() string {
313-
return fmt.Sprintf("assertion failed { %s }", e.AssertionFailed.String())
313+
return fmt.Sprintf("assertion failed { %s }", e.String())
314314
}
315315

316316
func (e *ErrLockOnlyIfExistsNoReturnValue) Error() string {

internal/apicodec/codec.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,27 @@ func DecodeKey(encoded []byte, version kvrpcpb.APIVersion) ([]byte, []byte, erro
9292
}
9393

9494
func setAPICtx(c Codec, r *tikvrpc.Request) {
95-
r.Context.ApiVersion = c.GetAPIVersion()
96-
r.Context.KeyspaceId = uint32(c.GetKeyspaceID())
95+
r.ApiVersion = c.GetAPIVersion()
96+
r.KeyspaceId = uint32(c.GetKeyspaceID())
9797
keyspaceMeta := c.GetKeyspaceMeta()
9898
if keyspaceMeta != nil {
99-
r.Context.KeyspaceName = keyspaceMeta.Name
99+
r.KeyspaceName = keyspaceMeta.Name
100100
}
101101

102102
switch r.Type {
103103
case tikvrpc.CmdMPPTask:
104104
mpp := *r.DispatchMPPTask()
105105
// Shallow copy the meta to avoid concurrent modification.
106106
meta := *mpp.Meta
107-
meta.KeyspaceId = r.Context.KeyspaceId
108-
meta.ApiVersion = r.Context.ApiVersion
107+
meta.KeyspaceId = r.KeyspaceId
108+
meta.ApiVersion = r.ApiVersion
109109
mpp.Meta = &meta
110110
r.Req = &mpp
111111

112112
case tikvrpc.CmdCompact:
113113
compact := *r.Compact()
114-
compact.KeyspaceId = r.Context.KeyspaceId
115-
compact.ApiVersion = r.Context.ApiVersion
114+
compact.KeyspaceId = r.KeyspaceId
115+
compact.ApiVersion = r.ApiVersion
116116
r.Req = &compact
117117
}
118118
}

internal/client/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (a *connArray) Init(addr string, security config.Security, idleNotify *uint
310310
allowBatch := (cfg.TiKVClient.MaxBatchSize > 0) && enableBatch
311311
if allowBatch {
312312
a.batchConn = newBatchConn(uint(len(a.v)), cfg.TiKVClient.MaxBatchSize, idleNotify)
313-
a.batchConn.initMetrics(a.target)
313+
a.initMetrics(a.target)
314314
}
315315
keepAlive := cfg.TiKVClient.GrpcKeepAliveTime
316316
for i := range a.v {
@@ -723,7 +723,7 @@ func (c *RPCClient) getCopStreamResponse(ctx context.Context, client tikvpb.Tikv
723723
// Put the lease object to the timeout channel, so it would be checked periodically.
724724
copStream := resp.Resp.(*tikvrpc.CopStreamResponse)
725725
copStream.Timeout = timeout
726-
copStream.Lease.Cancel = cancel
726+
copStream.Cancel = cancel
727727
connArray.streamTimeout <- &copStream.Lease
728728

729729
// Read the first streaming response to get CopStreamResponse.
@@ -758,7 +758,7 @@ func (c *RPCClient) getBatchCopStreamResponse(ctx context.Context, client tikvpb
758758
// Put the lease object to the timeout channel, so it would be checked periodically.
759759
copStream := resp.Resp.(*tikvrpc.BatchCopStreamResponse)
760760
copStream.Timeout = timeout
761-
copStream.Lease.Cancel = cancel
761+
copStream.Cancel = cancel
762762
connArray.streamTimeout <- &copStream.Lease
763763

764764
// Read the first streaming response to get CopStreamResponse.
@@ -792,7 +792,7 @@ func (c *RPCClient) getMPPStreamResponse(ctx context.Context, client tikvpb.Tikv
792792
// Put the lease object to the timeout channel, so it would be checked periodically.
793793
copStream := resp.Resp.(*tikvrpc.MPPStreamResponse)
794794
copStream.Timeout = timeout
795-
copStream.Lease.Cancel = cancel
795+
copStream.Cancel = cancel
796796
connArray.streamTimeout <- &copStream.Lease
797797

798798
// Read the first streaming response to get CopStreamResponse.

internal/client/client_batch.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ func (t *turboBatchTrigger) turboWaitTime() time.Duration {
486486
}
487487

488488
func (t *turboBatchTrigger) needFetchMore(reqArrivalInterval time.Duration) bool {
489-
if t.opts.V == turboBatchTimeBased {
489+
switch t.opts.V {
490+
case turboBatchTimeBased:
490491
thisArrivalInterval := reqArrivalInterval.Seconds()
491492
if t.maxArrivalInterval == 0 {
492493
t.maxArrivalInterval = t.turboWaitSeconds() * float64(t.opts.N)
@@ -500,14 +501,14 @@ func (t *turboBatchTrigger) needFetchMore(reqArrivalInterval time.Duration) bool
500501
t.estArrivalInterval = t.opts.W*thisArrivalInterval + (1-t.opts.W)*t.estArrivalInterval
501502
}
502503
return t.estArrivalInterval < t.turboWaitSeconds()*t.opts.P
503-
} else if t.opts.V == turboBatchProbBased {
504+
case turboBatchProbBased:
504505
thisProb := .0
505506
if reqArrivalInterval.Seconds() < t.turboWaitSeconds() {
506507
thisProb = 1
507508
}
508509
t.estFetchMoreProb = t.opts.W*thisProb + (1-t.opts.W)*t.estFetchMoreProb
509510
return t.estFetchMoreProb > t.opts.P
510-
} else {
511+
default:
511512
return true
512513
}
513514
}

internal/client/client_collapse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (r reqCollapse) SendRequestAsync(ctx context.Context, addr string, req *tik
8787
}
8888
if req.Type == tikvrpc.CmdResolveLock && len(req.ResolveLock().Keys) == 0 && len(req.ResolveLock().TxnInfos) == 0 {
8989
// try collapse resolve lock request.
90-
key := strconv.FormatUint(req.Context.RegionId, 10) + "-" + strconv.FormatUint(req.ResolveLock().StartVersion, 10)
90+
key := strconv.FormatUint(req.RegionId, 10) + "-" + strconv.FormatUint(req.ResolveLock().StartVersion, 10)
9191
copyReq := *req
9292
rsC := resolveRegionSf.DoChan(key, func() (interface{}, error) {
9393
// resolveRegionSf will call this function in a goroutine, thus use SendRequest directly.
@@ -124,7 +124,7 @@ func (r reqCollapse) tryCollapseRequest(ctx context.Context, addr string, req *t
124124
return
125125
}
126126
canCollapse = true
127-
key := strconv.FormatUint(req.Context.RegionId, 10) + "-" + strconv.FormatUint(resolveLock.StartVersion, 10)
127+
key := strconv.FormatUint(req.RegionId, 10) + "-" + strconv.FormatUint(resolveLock.StartVersion, 10)
128128
resp, err = r.collapse(ctx, key, &resolveRegionSf, addr, req, timeout)
129129
return
130130
default:

internal/client/client_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func TestSendWhenReconnect(t *testing.T) {
142142
assert.Nil(t, err)
143143

144144
// Suppose all connections are re-establishing.
145-
for _, client := range conn.batchConn.batchCommandsClients {
145+
for _, client := range conn.batchCommandsClients {
146146
client.lockForRecreate()
147147
}
148148

@@ -707,9 +707,9 @@ func TestBatchClientRecoverAfterServerRestart(t *testing.T) {
707707
grpcConn := conn.Get()
708708
require.NotNil(t, grpcConn)
709709
var cli *batchCommandsClient
710-
for i := range conn.batchConn.batchCommandsClients {
710+
for i := range conn.batchCommandsClients {
711711
if conn.batchConn.batchCommandsClients[i].tryLockForSend() {
712-
cli = conn.batchConn.batchCommandsClients[i]
712+
cli = conn.batchCommandsClients[i]
713713
break
714714
}
715715
}
@@ -966,7 +966,7 @@ func TestRandomRestartStoreAndForwarding(t *testing.T) {
966966
}
967967
wg.Wait()
968968

969-
for _, cli := range conn.batchConn.batchCommandsClients {
969+
for _, cli := range conn.batchCommandsClients {
970970
require.Equal(t, int64(9223372036854775807), cli.maxConcurrencyRequestLimit.Load())
971971
require.True(t, cli.available() > 0, fmt.Sprintf("sent: %d", cli.sent.Load()))
972972
require.True(t, cli.sent.Load() >= 0, fmt.Sprintf("sent: %d", cli.sent.Load()))
@@ -1036,7 +1036,7 @@ func TestFastFailWhenNoAvailableConn(t *testing.T) {
10361036
_, err = sendBatchRequest(context.Background(), addr, "", conn.batchConn, req, time.Second, 0)
10371037
require.NoError(t, err)
10381038

1039-
for _, c := range conn.batchConn.batchCommandsClients {
1039+
for _, c := range conn.batchCommandsClients {
10401040
// mock all client a in recreate.
10411041
c.lockForRecreate()
10421042
}

internal/latch/scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (scheduler *LatchesScheduler) wakeup(wakeupList []*Lock) {
103103
// Close closes LatchesScheduler.
104104
func (scheduler *LatchesScheduler) Close() {
105105
scheduler.RWMutex.Lock()
106-
defer scheduler.RWMutex.Unlock()
106+
defer scheduler.Unlock()
107107
if !scheduler.closed {
108108
close(scheduler.unlockCh)
109109
scheduler.closed = true

internal/locate/region_request.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import (
6666
"github.com/tikv/client-go/v2/tikvrpc"
6767
"github.com/tikv/client-go/v2/util"
6868
"github.com/tikv/client-go/v2/util/async"
69-
"github.com/tikv/pd/client/errs"
7069
pderr "github.com/tikv/pd/client/errs"
7170
)
7271

@@ -482,8 +481,8 @@ func (s *RegionRequestSender) SendReqAsync(
482481
return
483482
}
484483

485-
if req.Context.MaxExecutionDurationMs == 0 {
486-
req.Context.MaxExecutionDurationMs = uint64(timeout.Milliseconds())
484+
if req.MaxExecutionDurationMs == 0 {
485+
req.MaxExecutionDurationMs = uint64(timeout.Milliseconds())
487486
}
488487

489488
s.reset()
@@ -989,7 +988,7 @@ func (s *sendReqState) next() (done bool) {
989988
logutil.Eventf(bo.GetCtx(), "send %s request to region %d at %s", req.Type, s.args.regionID.id, s.vars.rpcCtx.Addr)
990989
s.storeAddr = s.vars.rpcCtx.Addr
991990

992-
req.Context.ClusterId = s.vars.rpcCtx.ClusterID
991+
req.ClusterId = s.vars.rpcCtx.ClusterID
993992
if req.InputRequestSource != "" && s.replicaSelector != nil {
994993
patchRequestSource(req, s.replicaSelector.replicaType())
995994
}
@@ -1240,7 +1239,7 @@ func (s *sendReqState) initForAsyncRequest() (ok bool) {
12401239

12411240
// set access location based on source and target "zone" label.
12421241
s.setReqAccessLocation(req)
1243-
req.Context.ClusterId = s.vars.rpcCtx.ClusterID
1242+
req.ClusterId = s.vars.rpcCtx.ClusterID
12441243
if req.InputRequestSource != "" && s.replicaSelector != nil {
12451244
patchRequestSource(req, s.replicaSelector.replicaType())
12461245
}
@@ -1425,8 +1424,8 @@ func (s *RegionRequestSender) SendReqCtx(
14251424

14261425
// If the MaxExecutionDurationMs is not set yet, we set it to be the RPC timeout duration
14271426
// so TiKV can give up the requests whose response TiDB cannot receive due to timeout.
1428-
if req.Context.MaxExecutionDurationMs == 0 {
1429-
req.Context.MaxExecutionDurationMs = uint64(timeout.Milliseconds())
1427+
if req.MaxExecutionDurationMs == 0 {
1428+
req.MaxExecutionDurationMs = uint64(timeout.Milliseconds())
14301429
}
14311430

14321431
state := &sendReqState{
@@ -1513,7 +1512,7 @@ func (s *RegionRequestSender) logSendReqError(bo *retry.Backoffer, msg string, r
15131512
builder.WriteString(", timeout: ")
15141513
builder.WriteString(util.FormatDuration(timeout))
15151514
builder.WriteString(", req-max-exec-timeout: ")
1516-
builder.WriteString(util.FormatDuration(time.Duration(int64(req.Context.MaxExecutionDurationMs) * int64(time.Millisecond))))
1515+
builder.WriteString(util.FormatDuration(time.Duration(int64(req.MaxExecutionDurationMs) * int64(time.Millisecond))))
15171516
builder.WriteString(", retry-times: ")
15181517
builder.WriteString(strconv.Itoa(retryTimes))
15191518
if s.AccessStats != nil {
@@ -1600,7 +1599,7 @@ func fetchRespInfo(resp *tikvrpc.Response) string {
16001599

16011600
func isRPCError(err error) bool {
16021601
// exclude ErrClientResourceGroupThrottled
1603-
return err != nil && errs.ErrClientResourceGroupThrottled.NotEqual(err)
1602+
return err != nil && pderr.ErrClientResourceGroupThrottled.NotEqual(err)
16041603
}
16051604

16061605
func storeIDLabel(rpcCtx *RPCContext) string {

0 commit comments

Comments
 (0)