Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
fix or suppress all linter warnings
Browse files Browse the repository at this point in the history
* wsl is removed from linters list because produces too many noise
* gosimple, staticcheck are added to linters list as useful ones
* linter (govet) warnings are fixed for "DiscoveryHandleBuckets", although this function does not seem correct yet.
      It would be discussed in another issue
* linter (staticcheck) warnings are fixed for "BucketStat", although this function may need additional fixes
  • Loading branch information
nurzhan-saktaganov committed Aug 12, 2024
1 parent 10c8cbb commit fade434
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ linters:
- goconst
- goimports
- gosec
- gosimple
- govet
- ineffassign
- revive
- typecheck
- exportloopref
- prealloc
- wsl
# - wls # excluded from linters list because produces too many noise
- staticcheck
3 changes: 2 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vshard_router
package vshard_router //nolint:revive

import (
"context"
Expand Down Expand Up @@ -64,6 +64,7 @@ type CallOpts struct {
Timeout time.Duration
}

//nolint:revive
const CallTimeoutMin = time.Second / 2

// RouterCallImpl Perform shard operation function will restart operation
Expand Down
12 changes: 5 additions & 7 deletions discovery.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vshard_router
package vshard_router //nolint:revive

import (
"context"
Expand Down Expand Up @@ -127,13 +127,11 @@ func (r *Router) DiscoveryHandleBuckets(ctx context.Context, rs *Replicaset, buc
count++

if oldRs != nil {
bc := oldRs.bucketCount

if _, exists := affected[oldRs]; !exists {
affected[oldRs] = int(bc.Load())
affected[oldRs] = int(oldRs.bucketCount.Load())
}

oldRs.bucketCount.Store(bc.Load() - 1)
oldRs.bucketCount.Add(-1)
} else {
// router.known_bucket_count = router.known_bucket_count + 1
r.knownBucketCount.Add(1)
Expand All @@ -143,13 +141,13 @@ func (r *Router) DiscoveryHandleBuckets(ctx context.Context, rs *Replicaset, buc
}

if count != rs.bucketCount.Load() {
r.cfg.Logger.Info(ctx, fmt.Sprintf("Updated %s buckets: was %d, became %d", rs.info.Name, rs.bucketCount, count))
r.cfg.Logger.Info(ctx, fmt.Sprintf("Updated %s buckets: was %d, became %d", rs.info.Name, rs.bucketCount.Load(), count))
}

rs.bucketCount.Store(count)

for rs, oldBucketCount := range affected {
r.log().Info(ctx, fmt.Sprintf("Affected buckets of %s: was %d, became %d", rs.info.Name, oldBucketCount, rs.bucketCount))
r.log().Info(ctx, fmt.Sprintf("Affected buckets of %s: was %d, became %d", rs.info.Name, oldBucketCount, rs.bucketCount.Load()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion discovery_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vshard_router
package vshard_router //nolint:revive

import (
"sync"
Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vshard_router
package vshard_router //nolint:revive

import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion providers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vshard_router
package vshard_router //nolint:revive

import (
"context"
Expand Down
4 changes: 1 addition & 3 deletions providers/viper/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ func (p *Provider) Init(c vshardrouter.TopologyController) error {
return c.AddReplicasets(context.TODO(), p.rs)
}

func (p *Provider) Close() {
return
}
func (p *Provider) Close() {}

type ClusterInfo struct {
ReplicasetUUID string `yaml:"replicaset_uuid" mapstructure:"replicaset_uuid"`
Expand Down
43 changes: 28 additions & 15 deletions replicaset.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vshard_router
package vshard_router //nolint:revive

import (
"context"
Expand Down Expand Up @@ -38,36 +38,49 @@ func (rs *Replicaset) String() string {
}

func (rs *Replicaset) BucketStat(ctx context.Context, bucketID uint64) (BucketStatInfo, error) {
bsInfo := &BucketStatInfo{}
bsError := &BucketStatError{}
const fnc = "vshard.storage.bucket_stat"

req := tarantool.NewCallRequest("vshard.storage.bucket_stat").
var bsInfo BucketStatInfo

req := tarantool.NewCallRequest(fnc).
Args([]interface{}{bucketID}).
Context(ctx)

future := rs.conn.Do(req, pool.RO)
respData, err := future.Get()
if err != nil {
return BucketStatInfo{}, err
return bsInfo, err
}

var tmp interface{} // todo: fix non-panic crutch
if len(respData) < 1 {
return bsInfo, fmt.Errorf("respData len is 0 for %s", fnc)
}

if respData[0] == nil {
err := future.GetTyped(&[]interface{}{tmp, bsError})
if err != nil {
return BucketStatInfo{}, err

if len(respData) < 2 {
return bsInfo, fmt.Errorf("respData len < 2 when respData[0] is nil for %s", fnc)
}
} else {
// fucking key-code 1
// todo: fix after https://github.com/tarantool/go-tarantool/issues/368
err := mapstructure.Decode(respData[0], bsInfo)

var tmp interface{} // todo: fix non-panic crutch
bsError := &BucketStatError{}

err := future.GetTyped(&[]interface{}{tmp, bsError})
if err != nil {
return BucketStatInfo{}, err
return bsInfo, err
}

return bsInfo, bsError
}

// fucking key-code 1
// todo: fix after https://github.com/tarantool/go-tarantool/issues/368
err = mapstructure.Decode(respData[0], bsInfo)
if err != nil {
return bsInfo, fmt.Errorf("can't decode bsInfo: %w", err)
}

return *bsInfo, bsError
return bsInfo, nil
}

// ReplicaCall perform function on remote storage
Expand Down
2 changes: 1 addition & 1 deletion replicaset_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vshard_router
package vshard_router //nolint:revive

import (
"bytes"
Expand Down
4 changes: 2 additions & 2 deletions topology.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vshard_router
package vshard_router //nolint:revive

import (
"context"
Expand Down Expand Up @@ -123,7 +123,7 @@ func (c *controller) AddReplicasets(ctx context.Context, replicasets map[Replica
return nil
}

func (c *controller) RemoveReplicaset(ctx context.Context, rsID uuid.UUID) []error {
func (c *controller) RemoveReplicaset(_ context.Context, rsID uuid.UUID) []error {
r := c.r

rs := r.idToReplicaset[rsID]
Expand Down
2 changes: 1 addition & 1 deletion topology_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vshard_router
package vshard_router //nolint:revive

import (
"context"
Expand Down
8 changes: 5 additions & 3 deletions vshard.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vshard_router
package vshard_router //nolint:revive

import (
"context"
Expand Down Expand Up @@ -92,7 +92,7 @@ func (ii InstanceInfo) Validate() error {
func NewRouter(ctx context.Context, cfg Config) (*Router, error) {
var err error

cfg, err = prepareCfg(ctx, cfg)
cfg, err = prepareCfg(cfg)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -184,7 +184,7 @@ func (r *Router) RouteMapClean() {
}
}

func prepareCfg(ctx context.Context, cfg Config) (Config, error) {
func prepareCfg(cfg Config) (Config, error) {
err := validateCfg(cfg)
if err != nil {
return Config{}, fmt.Errorf("%v: %v", ErrInvalidConfig, err)
Expand Down Expand Up @@ -239,6 +239,8 @@ func (r *Router) RouterBucketIDStrCRC32(shardKey string) uint64 {
}

// RouterBucketIDMPCRC32 is not supported now
//
//nolint:revive
func RouterBucketIDMPCRC32(total uint64, keys ...string) {}

func (r *Router) RouterBucketCount() uint64 {
Expand Down
2 changes: 1 addition & 1 deletion vshard_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vshard_router
package vshard_router //nolint:revive

import (
"testing"
Expand Down

0 comments on commit fade434

Please sign in to comment.