Skip to content

Commit

Permalink
*: fix unparam lint
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Fu <fuweid89@gmail.com>
  • Loading branch information
fuweid committed Sep 20, 2023
1 parent 36403e3 commit 2bf208c
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 85 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fuzz:
verify: verify-gofmt verify-bom verify-lint verify-dep verify-shellcheck verify-goword \
verify-govet verify-license-header verify-receiver-name verify-mod-tidy verify-shellcheck \
verify-shellws verify-proto-annotations verify-genproto verify-goimport verify-yamllint \
verify-govet-shadow
verify-govet-shadow verify-unparam-lint
fix: fix-goimports fix-bom fix-lint fix-yamllint
./scripts/fix.sh

Expand All @@ -85,8 +85,13 @@ fix-bom:
verify-dep:
PASSES="dep" ./scripts/test.sh

# TODO: https://github.com/etcd-io/etcd/issues/16610
#
# The golangci-lint doesn't verify sub modules. Before #16610 fixed, verify-lint
# still depends on legacy {ineffassign,nakedret,unparam,...}_pass. These X_pass
# will be removed when the golangci-lint covers all the sub modules.
.PHONY: verify-lint
verify-lint:
verify-lint: verify-unparam-lint
golangci-lint run --config tools/.golangci.yaml

.PHONY: fix-lint
Expand Down Expand Up @@ -145,6 +150,10 @@ verify-yamllint:
verify-govet-shadow:
PASSES="govet_shadow" ./scripts/test.sh

.PHONY: verify-unparam-lint
verify-unparam-lint:
PASSES="unparam" ./scripts/test.sh

YAMLFMT_VERSION = $(shell cd tools/mod && go list -m -f '{{.Version}}' github.com/google/yamlfmt)

.PHONY: fix-yamllint
Expand Down
2 changes: 1 addition & 1 deletion client/internal/v2/cancelreq.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package client

import "net/http"

func requestCanceler(tr CancelableTransport, req *http.Request) func() {
func requestCanceler(req *http.Request) func() {
ch := make(chan struct{})
req.Cancel = ch

Expand Down
2 changes: 1 addition & 1 deletion client/internal/v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func (c *simpleHTTPClient) Do(ctx context.Context, act httpAction) (*http.Respon
}
defer hcancel()

reqcancel := requestCanceler(c.transport, req)
reqcancel := requestCanceler(req)

rtchan := make(chan roundTripResponse, 1)
go func() {
Expand Down
10 changes: 3 additions & 7 deletions client/pkg/transport/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ func newListener(addr, scheme string, opts ...ListenerOption) (net.Listener, err
switch {
case lnOpts.IsSocketOpts():
// new ListenConfig with socket options.
config, err := newListenConfig(lnOpts.socketOpts)
if err != nil {
return nil, err
}
lnOpts.ListenConfig = config
lnOpts.ListenConfig = newListenConfig(lnOpts.socketOpts)
// check for timeout
fallthrough
case lnOpts.IsTimeout(), lnOpts.IsSocketOpts():
Expand Down Expand Up @@ -129,15 +125,15 @@ func wrapTLS(scheme string, tlsinfo *TLSInfo, l net.Listener) (net.Listener, err
return newTLSListener(l, tlsinfo, checkSAN)
}

func newListenConfig(sopts *SocketOpts) (net.ListenConfig, error) {
func newListenConfig(sopts *SocketOpts) net.ListenConfig {
lc := net.ListenConfig{}
if sopts != nil {
ctls := getControls(sopts)
if len(ctls) > 0 {
lc.Control = ctls.Control
}
}
return lc, nil
return lc
}

type TLSInfo struct {
Expand Down
12 changes: 6 additions & 6 deletions client/v3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ func (c *Client) autoSync() {
}

// dialSetupOpts gives the dial opts prior to any authentication.
func (c *Client) dialSetupOpts(creds grpccredentials.TransportCredentials, dopts ...grpc.DialOption) (opts []grpc.DialOption, err error) {
func (c *Client) dialSetupOpts(creds grpccredentials.TransportCredentials, dopts ...grpc.DialOption) []grpc.DialOption {
var opts []grpc.DialOption

if c.cfg.DialKeepAliveTime > 0 {
params := keepalive.ClientParameters{
Time: c.cfg.DialKeepAliveTime,
Expand Down Expand Up @@ -248,7 +250,7 @@ func (c *Client) dialSetupOpts(creds grpccredentials.TransportCredentials, dopts
grpc.WithUnaryInterceptor(c.unaryClientInterceptor(withMax(defaultUnaryMaxRetries), rrBackoff)),
)

return opts, nil
return opts
}

// Dial connects to a single endpoint using the client's config.
Expand Down Expand Up @@ -289,10 +291,8 @@ func (c *Client) dialWithBalancer(dopts ...grpc.DialOption) (*grpc.ClientConn, e

// dial configures and dials any grpc balancer target.
func (c *Client) dial(creds grpccredentials.TransportCredentials, dopts ...grpc.DialOption) (*grpc.ClientConn, error) {
opts, err := c.dialSetupOpts(creds, dopts...)
if err != nil {
return nil, fmt.Errorf("failed to configure dialer: %v", err)
}
opts := c.dialSetupOpts(creds, dopts...)

if c.authTokenBundle != nil {
opts = append(opts, grpc.WithPerRPCCredentials(c.authTokenBundle.PerRPCCredentials()))
}
Expand Down
2 changes: 1 addition & 1 deletion client/v3/concurrency/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (e *Election) Campaign(ctx context.Context, val string) error {
}
}

_, err = waitDeletes(ctx, client, e.keyPrefix, e.leaderRev-1)
err = waitDeletes(ctx, client, e.keyPrefix, e.leaderRev-1)
if err != nil {
// clean up in case of context cancel
select {
Expand Down
9 changes: 4 additions & 5 deletions client/v3/concurrency/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"errors"

pb "go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/api/v3/mvccpb"
v3 "go.etcd.io/etcd/client/v3"
)
Expand Down Expand Up @@ -47,19 +46,19 @@ func waitDelete(ctx context.Context, client *v3.Client, key string, rev int64) e

// waitDeletes efficiently waits until all keys matching the prefix and no greater
// than the create revision are deleted.
func waitDeletes(ctx context.Context, client *v3.Client, pfx string, maxCreateRev int64) (*pb.ResponseHeader, error) {
func waitDeletes(ctx context.Context, client *v3.Client, pfx string, maxCreateRev int64) error {
getOpts := append(v3.WithLastCreate(), v3.WithMaxCreateRev(maxCreateRev))
for {
resp, err := client.Get(ctx, pfx, getOpts...)
if err != nil {
return nil, err
return err
}
if len(resp.Kvs) == 0 {
return resp.Header, nil
return nil
}
lastKey := string(resp.Kvs[0].Key)
if err = waitDelete(ctx, client, lastKey, resp.Header.Revision); err != nil {
return nil, err
return err
}
}
}
2 changes: 1 addition & 1 deletion client/v3/concurrency/mutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (m *Mutex) Lock(ctx context.Context) error {
client := m.s.Client()
// wait for deletion revisions prior to myKey
// TODO: early termination if the session key is deleted before other session keys with smaller revisions.
_, werr := waitDeletes(ctx, client, m.pfx, m.myRev-1)
werr := waitDeletes(ctx, client, m.pfx, m.myRev-1)
// release lock key if wait failed
if werr != nil {
m.Unlock(client.Ctx())
Expand Down
34 changes: 17 additions & 17 deletions client/v3/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func RetryKVClient(c *Client) pb.KVClient {
}
}
func (rkv *retryKVClient) Range(ctx context.Context, in *pb.RangeRequest, opts ...grpc.CallOption) (resp *pb.RangeResponse, err error) {
return rkv.kc.Range(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rkv.kc.Range(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rkv *retryKVClient) Put(ctx context.Context, in *pb.PutRequest, opts ...grpc.CallOption) (resp *pb.PutResponse, err error) {
Expand Down Expand Up @@ -133,23 +133,23 @@ func RetryLeaseClient(c *Client) pb.LeaseClient {
}

func (rlc *retryLeaseClient) LeaseTimeToLive(ctx context.Context, in *pb.LeaseTimeToLiveRequest, opts ...grpc.CallOption) (resp *pb.LeaseTimeToLiveResponse, err error) {
return rlc.lc.LeaseTimeToLive(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rlc.lc.LeaseTimeToLive(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rlc *retryLeaseClient) LeaseLeases(ctx context.Context, in *pb.LeaseLeasesRequest, opts ...grpc.CallOption) (resp *pb.LeaseLeasesResponse, err error) {
return rlc.lc.LeaseLeases(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rlc.lc.LeaseLeases(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rlc *retryLeaseClient) LeaseGrant(ctx context.Context, in *pb.LeaseGrantRequest, opts ...grpc.CallOption) (resp *pb.LeaseGrantResponse, err error) {
return rlc.lc.LeaseGrant(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rlc.lc.LeaseGrant(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rlc *retryLeaseClient) LeaseRevoke(ctx context.Context, in *pb.LeaseRevokeRequest, opts ...grpc.CallOption) (resp *pb.LeaseRevokeResponse, err error) {
return rlc.lc.LeaseRevoke(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rlc.lc.LeaseRevoke(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rlc *retryLeaseClient) LeaseKeepAlive(ctx context.Context, opts ...grpc.CallOption) (stream pb.Lease_LeaseKeepAliveClient, err error) {
return rlc.lc.LeaseKeepAlive(ctx, append(opts, withRetryPolicy(repeatable))...)
return rlc.lc.LeaseKeepAlive(ctx, append(opts, withRepeatablePolicy())...)
}

type retryClusterClient struct {
Expand All @@ -164,7 +164,7 @@ func RetryClusterClient(c *Client) pb.ClusterClient {
}

func (rcc *retryClusterClient) MemberList(ctx context.Context, in *pb.MemberListRequest, opts ...grpc.CallOption) (resp *pb.MemberListResponse, err error) {
return rcc.cc.MemberList(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rcc.cc.MemberList(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rcc *retryClusterClient) MemberAdd(ctx context.Context, in *pb.MemberAddRequest, opts ...grpc.CallOption) (resp *pb.MemberAddResponse, err error) {
Expand Down Expand Up @@ -195,27 +195,27 @@ func RetryMaintenanceClient(c *Client, conn *grpc.ClientConn) pb.MaintenanceClie
}

func (rmc *retryMaintenanceClient) Alarm(ctx context.Context, in *pb.AlarmRequest, opts ...grpc.CallOption) (resp *pb.AlarmResponse, err error) {
return rmc.mc.Alarm(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rmc.mc.Alarm(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rmc *retryMaintenanceClient) Status(ctx context.Context, in *pb.StatusRequest, opts ...grpc.CallOption) (resp *pb.StatusResponse, err error) {
return rmc.mc.Status(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rmc.mc.Status(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rmc *retryMaintenanceClient) Hash(ctx context.Context, in *pb.HashRequest, opts ...grpc.CallOption) (resp *pb.HashResponse, err error) {
return rmc.mc.Hash(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rmc.mc.Hash(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rmc *retryMaintenanceClient) HashKV(ctx context.Context, in *pb.HashKVRequest, opts ...grpc.CallOption) (resp *pb.HashKVResponse, err error) {
return rmc.mc.HashKV(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rmc.mc.HashKV(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rmc *retryMaintenanceClient) Snapshot(ctx context.Context, in *pb.SnapshotRequest, opts ...grpc.CallOption) (stream pb.Maintenance_SnapshotClient, err error) {
return rmc.mc.Snapshot(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rmc.mc.Snapshot(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rmc *retryMaintenanceClient) MoveLeader(ctx context.Context, in *pb.MoveLeaderRequest, opts ...grpc.CallOption) (resp *pb.MoveLeaderResponse, err error) {
return rmc.mc.MoveLeader(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rmc.mc.MoveLeader(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rmc *retryMaintenanceClient) Defragment(ctx context.Context, in *pb.DefragmentRequest, opts ...grpc.CallOption) (resp *pb.DefragmentResponse, err error) {
Expand All @@ -238,19 +238,19 @@ func RetryAuthClient(c *Client) pb.AuthClient {
}

func (rac *retryAuthClient) UserList(ctx context.Context, in *pb.AuthUserListRequest, opts ...grpc.CallOption) (resp *pb.AuthUserListResponse, err error) {
return rac.ac.UserList(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rac.ac.UserList(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rac *retryAuthClient) UserGet(ctx context.Context, in *pb.AuthUserGetRequest, opts ...grpc.CallOption) (resp *pb.AuthUserGetResponse, err error) {
return rac.ac.UserGet(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rac.ac.UserGet(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rac *retryAuthClient) RoleGet(ctx context.Context, in *pb.AuthRoleGetRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleGetResponse, err error) {
return rac.ac.RoleGet(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rac.ac.RoleGet(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rac *retryAuthClient) RoleList(ctx context.Context, in *pb.AuthRoleListRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleListResponse, err error) {
return rac.ac.RoleList(ctx, in, append(opts, withRetryPolicy(repeatable))...)
return rac.ac.RoleList(ctx, in, append(opts, withRepeatablePolicy())...)
}

func (rac *retryAuthClient) AuthEnable(ctx context.Context, in *pb.AuthEnableRequest, opts ...grpc.CallOption) (resp *pb.AuthEnableResponse, err error) {
Expand Down
6 changes: 3 additions & 3 deletions client/v3/retry_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ var (
// with the next iteration.
type backoffFunc func(attempt uint) time.Duration

// withRetryPolicy sets the retry policy of this call.
func withRetryPolicy(rp retryPolicy) retryOption {
// withRepeatablePolicy sets the repeatable policy of this call.
func withRepeatablePolicy() retryOption {
return retryOption{applyFunc: func(o *options) {
o.retryPolicy = rp
o.retryPolicy = repeatable
}}
}

Expand Down
2 changes: 1 addition & 1 deletion etcdutl/etcdutl/backup_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func raftEntryToNoOp(entry *raftpb.Entry) {
}

// saveDB copies the v3 backend and strips cluster information.
func saveDB(lg *zap.Logger, destDB, srcDB string, idx uint64, term uint64, desired *desiredCluster) {
func saveDB(lg *zap.Logger, destDB, srcDB string, _ uint64 /* idx */, _ uint64 /* term */, desired *desiredCluster) {
// open src db to safely copy db state
var src *bolt.DB
ch := make(chan *bolt.DB, 1)
Expand Down
1 change: 0 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ function govet_shadow_pass {
}

function unparam_pass {
# TODO: transport/listener.go:129:60: newListenConfig - result 1 (error) is always nil
run_for_modules generic_checker run_go_tool "mvdan.cc/unparam"
}

Expand Down
16 changes: 6 additions & 10 deletions server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,10 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
}
e.Server.Start()

if err = e.servePeers(); err != nil {
return e, err
}
if err = e.serveClients(); err != nil {
return e, err
}
e.servePeers()

e.serveClients()

if err = e.serveMetrics(); err != nil {
return e, err
}
Expand Down Expand Up @@ -563,7 +561,7 @@ func configurePeerListeners(cfg *Config) (peers []*peerListener, err error) {
}

// configure peer handlers after rafthttp.Transport started
func (e *Etcd) servePeers() (err error) {
func (e *Etcd) servePeers() {
ph := etcdhttp.NewPeerHandler(e.GetLogger(), e.Server)

for _, p := range e.Peers {
Expand Down Expand Up @@ -611,7 +609,6 @@ func (e *Etcd) servePeers() (err error) {
e.errHandler(l.serve())
}(pl)
}
return nil
}

func configureClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
Expand Down Expand Up @@ -729,7 +726,7 @@ func resolveUrl(u url.URL) (addr string, secure bool, network string) {
return addr, secure, network
}

func (e *Etcd) serveClients() (err error) {
func (e *Etcd) serveClients() {
if !e.cfg.ClientTLSInfo.Empty() {
e.cfg.logger.Info(
"starting with client TLS",
Expand Down Expand Up @@ -773,7 +770,6 @@ func (e *Etcd) serveClients() (err error) {
e.errHandler(s.serve(e.Server, &e.cfg.ClientTLSInfo, mux, e.errHandler, e.grpcGatewayDial(splitHttp), splitHttp, gopts...))
}(sctx)
}
return nil
}

func (e *Etcd) grpcGatewayDial(splitHttp bool) (grpcDial func(ctx context.Context) (*grpc.ClientConn, error)) {
Expand Down
3 changes: 1 addition & 2 deletions server/etcdmain/grpc_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,7 @@ func mustHTTPListener(lg *zap.Logger, m cmux.CMux, tlsinfo *transport.TLSInfo, c
func mustNewHTTPClient(lg *zap.Logger) *http.Client {
transport, err := newHTTPTransport(grpcProxyCA, grpcProxyCert, grpcProxyKey)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
lg.Fatal("failed to new http transport", zap.Error(err))
}
return &http.Client{Transport: transport}
}
Expand Down
10 changes: 3 additions & 7 deletions server/etcdserver/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ func bootstrap(cfg config.ServerConfig) (b *bootstrappedServer, err error) {
return nil, err
}

s, err := bootstrapStorage(cfg, st, backend, bwal, cluster)
if err != nil {
backend.Close()
return nil, err
}
s := bootstrapStorage(cfg, st, backend, bwal, cluster)

if err = cluster.Finalize(cfg, s); err != nil {
backend.Close()
Expand Down Expand Up @@ -165,7 +161,7 @@ type bootstrappedRaft struct {
storage *raft.MemoryStorage
}

func bootstrapStorage(cfg config.ServerConfig, st v2store.Store, be *bootstrappedBackend, wal *bootstrappedWAL, cl *bootstrapedCluster) (b *bootstrappedStorage, err error) {
func bootstrapStorage(cfg config.ServerConfig, st v2store.Store, be *bootstrappedBackend, wal *bootstrappedWAL, cl *bootstrapedCluster) *bootstrappedStorage {
if wal == nil {
wal = bootstrapNewWAL(cfg, cl)
}
Expand All @@ -174,7 +170,7 @@ func bootstrapStorage(cfg config.ServerConfig, st v2store.Store, be *bootstrappe
backend: be,
st: st,
wal: wal,
}, nil
}
}

func bootstrapSnapshot(cfg config.ServerConfig) *snap.Snapshotter {
Expand Down
Loading

0 comments on commit 2bf208c

Please sign in to comment.