Skip to content

Commit

Permalink
Upgrade to go lint 1.61 (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlimat authored Sep 13, 2024
1 parent ad609a0 commit 2d1aa2a
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 33 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/pr_build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ jobs:
run: make build

- name: golangci-lint
uses: golangci/golangci-lint-action@0ad9a0988b3973e851ab0a07adf248ec2e100376 #v3.3.1
uses: golangci/golangci-lint-action@v6.1.0
with:
version: v1.55.2
version: v1.61.0
args: --timeout=10m
skip-pkg-cache: true

- name: Test
run: make test
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ linters-settings:
- name: bare-return
severity: warning
disabled: false
gosec:
excludes:
- G115

issues:
fix: true
Expand Down
2 changes: 1 addition & 1 deletion cmd/coordinator/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func exec(*cobra.Command, []string) error {
return loadClusterConfig(v)
}

v.OnConfigChange(func(e fsnotify.Event) {
v.OnConfigChange(func(_ fsnotify.Event) {
conf.ClusterConfigChangeNotifications <- nil
})

Expand Down
4 changes: 2 additions & 2 deletions common/security/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (tls *TLSOption) MakeClientTLSConf() (*libtls.Config, error) {
tlsConf.RootCAs = certPool
}

tlsConf.GetClientCertificate = func(unused *libtls.CertificateRequestInfo) (cert *libtls.Certificate, err error) {
tlsConf.GetClientCertificate = func(_ *libtls.CertificateRequestInfo) (cert *libtls.Certificate, err error) {
c, err := libtls.LoadX509KeyPair(tls.CertFile, tls.KeyFile)
return &c, err
}
Expand All @@ -130,7 +130,7 @@ func (tls *TLSOption) MakeServerTLSConf() (*libtls.Config, error) {
if err != nil {
return nil, err
}
tlsConf.GetCertificate = func(clientHello *libtls.ClientHelloInfo) (cert *libtls.Certificate, err error) {
tlsConf.GetCertificate = func(_ *libtls.ClientHelloInfo) (cert *libtls.Certificate, err error) {
c, err := libtls.LoadX509KeyPair(tls.CertFile, tls.KeyFile)
return &c, err
}
Expand Down
2 changes: 1 addition & 1 deletion maelstrom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func receiveInit(scanner *bufio.Scanner) error {
init := req.(*Message[Init])

thisNode = init.Body.NodeId
allNodes = init.Body.NodesIds
allNodes = init.Body.NodesIDs

slog.Info(
"Received init request",
Expand Down
2 changes: 1 addition & 1 deletion maelstrom/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type BaseMessageBody struct {
type Init struct {
BaseMessageBody
NodeId string `json:"node_id"`
NodesIds []string `json:"node_ids"`
NodesIDs []string `json:"node_ids"`
}

type Read struct {
Expand Down
18 changes: 9 additions & 9 deletions oxia/async_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ func (c *clientImpl) DeleteRange(minKeyInclusive string, maxKeyExclusive string,
}

// If there is no partition key, we will make the request to delete-range on all the shards
shardIds := c.shardManager.GetAll()
wg := common.NewWaitGroup(len(shardIds))
shardIDs := c.shardManager.GetAll()
wg := common.NewWaitGroup(len(shardIDs))

for _, shardId := range shardIds {
for _, shardId := range shardIDs {
// chInner := make(chan error, 1)
c.writeBatchManager.Get(shardId).Add(model.DeleteRangeCall{
MinKeyInclusive: minKeyInclusive,
Expand Down Expand Up @@ -360,10 +360,10 @@ func (c *clientImpl) List(ctx context.Context, minKeyInclusive string, maxKeyExc
}()
} else {
// Do the list on all shards and aggregate the responses
shardIds := c.shardManager.GetAll()
shardIDs := c.shardManager.GetAll()

wg := common.NewWaitGroup(len(shardIds))
for _, shardId := range shardIds {
wg := common.NewWaitGroup(len(shardIDs))
for _, shardId := range shardIDs {
shardIdPtr := shardId
go func() {
defer wg.Done()
Expand Down Expand Up @@ -425,10 +425,10 @@ func (c *clientImpl) RangeScan(ctx context.Context, minKeyInclusive string, maxK
}()
} else {
// Do the list on all shards and aggregate the responses
shardIds := c.shardManager.GetAll()
channels := make([]chan GetResult, len(shardIds))
shardIDs := c.shardManager.GetAll()
channels := make([]chan GetResult, len(shardIDs))

for i, shardId := range shardIds {
for i, shardId := range shardIDs {
shardIdPtr := shardId
ch := make(chan GetResult)
channels[i] = ch
Expand Down
4 changes: 2 additions & 2 deletions oxia/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (m *Metrics) DecorateGet(get model.GetCall) model.GetCall {

func (m *Metrics) WriteCallback() func(time.Time, *proto.WriteRequest, *proto.WriteResponse, error) {
metricContext := m.metricContextFunc("write")
return func(executionStart time.Time, request *proto.WriteRequest, response *proto.WriteResponse, err error) {
return func(executionStart time.Time, request *proto.WriteRequest, _ *proto.WriteResponse, err error) {
ctx, batchStart, _attrs := metricContext(err)
m.batchTotalTime.Record(ctx, m.sinceFunc(batchStart), _attrs)
m.batchExecTime.Record(ctx, m.sinceFunc(executionStart), _attrs)
Expand All @@ -122,7 +122,7 @@ func (m *Metrics) WriteCallback() func(time.Time, *proto.WriteRequest, *proto.Wr

func (m *Metrics) ReadCallback() func(time.Time, *proto.ReadRequest, *proto.ReadResponse, error) {
metricContext := m.metricContextFunc("read")
return func(executionStart time.Time, request *proto.ReadRequest, response *proto.ReadResponse, err error) {
return func(executionStart time.Time, _ *proto.ReadRequest, response *proto.ReadResponse, err error) {
ctx, batchStart, attrs := metricContext(err)
m.batchTotalTime.Record(ctx, m.sinceFunc(batchStart), attrs)
m.batchExecTime.Record(ctx, m.sinceFunc(executionStart), attrs)
Expand Down
6 changes: 3 additions & 3 deletions oxia/internal/shard_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ func (s *shardManagerImpl) GetAll() []int64 {
s.RLock()
defer s.RUnlock()

shardIds := make([]int64, 0, len(s.shards))
shardIDs := make([]int64, 0, len(s.shards))
for shardId := range s.shards {
shardIds = append(shardIds, shardId)
shardIDs = append(shardIDs, shardId)
}
return shardIds
return shardIDs
}

func (s *shardManagerImpl) Leader(shardId int64) string {
Expand Down
6 changes: 3 additions & 3 deletions server/assignment_dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@ func TestShardAssignmentDispatcher_MultipleNamespaces(t *testing.T) {
assert.NoError(t, dispatcher.Close())
}

func newShardAssignment(id int64, leader string, min uint32, max uint32) *proto.ShardAssignment {
func newShardAssignment(id int64, leader string, minHashInclusive uint32, maxHashInclusive uint32) *proto.ShardAssignment {
return &proto.ShardAssignment{
Shard: id,
Leader: leader,
ShardBoundaries: &proto.ShardAssignment_Int32HashRange{
Int32HashRange: &proto.Int32HashRange{
MinHashInclusive: min,
MaxHashInclusive: max,
MinHashInclusive: minHashInclusive,
MaxHashInclusive: maxHashInclusive,
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions server/auth/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ type GrpcAuthenticationDelegator struct {
}

func (delegator *GrpcAuthenticationDelegator) GetUnaryInterceptor() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
return func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
_, err := delegator.validate(ctx, delegator.provider)
if err != nil {
return nil, status.Errorf(codes.Unauthenticated, err.Error())
return nil, status.Error(codes.Unauthenticated, err.Error())
}
// todo: set username to metadata to support authorization
return handler(ctx, req)
}
}

func (delegator *GrpcAuthenticationDelegator) GetStreamInterceptor() grpc.StreamServerInterceptor {
return func(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
return func(srv any, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
_, err := delegator.validate(ss.Context(), delegator.provider)
if err != nil {
return status.Errorf(codes.Unauthenticated, err.Error())
return status.Error(codes.Unauthenticated, err.Error())
}
// todo: set username to metadata to support authorization
return handler(srv, ss)
Expand Down
2 changes: 1 addition & 1 deletion server/session_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (m mockWriteBatch) DeleteRange(_, _ string) error {
}

func (m mockWriteBatch) KeyRangeScan(_, _ string) (kv.KeyIterator, error) {
return nil, nil
return nil, kv.ErrKeyNotFound
}

func (m mockWriteBatch) Commit() error {
Expand Down
2 changes: 1 addition & 1 deletion server/wal/treemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (m *treeMap[K, V]) Size() int {

func (m *treeMap[K, V]) Keys() []K {
keys := make([]K, 0, m.tree.Size())
m.Each(func(k K, v V) bool {
m.Each(func(k K, _ V) bool {
keys = append(keys, k)
return true
})
Expand Down
4 changes: 2 additions & 2 deletions server/wal/wal_ro_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (r *readOnlySegmentsGroup) Close() error {
defer r.Unlock()

var err error
r.openSegments.Each(func(id int64, segment common.RefCount[ReadOnlySegment]) bool {
r.openSegments.Each(func(_ int64, segment common.RefCount[ReadOnlySegment]) bool {
err = multierr.Append(err, segment.(io.Closer).Close())
return true
})
Expand Down Expand Up @@ -293,7 +293,7 @@ func (r *readOnlySegmentsGroup) PollHighestSegment() (common.RefCount[ReadOnlySe
defer r.Unlock()

if r.allSegments.Empty() {
return nil, nil
return nil, nil // nolint: nilnil
}

offset, _ := r.allSegments.Max()
Expand Down

0 comments on commit 2d1aa2a

Please sign in to comment.