Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to go 119 #522

Merged
merged 12 commits into from
Oct 2, 2023
Merged
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
go_versions: [ '1.18.x', '1.19.x', '1.20.x' ]
go_versions: [ '1.19', '1.20', '1.21' ]
fail-fast: false
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -49,4 +49,3 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: latest
only-new-issues: true
4 changes: 3 additions & 1 deletion client/object_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func TestObjectSearch(t *testing.T) {
}

// nil panic
require.Panics(t, func() { resp.Read(nil) })
require.Panics(t, func() {
_, _ = resp.Read(nil)
})

// no data
resp.stream = newSearchStream(p, io.EOF, []oid.ID{})
Expand Down
30 changes: 20 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
module github.com/nspcc-dev/neofs-sdk-go

go 1.18
go 1.19

require (
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12
github.com/google/uuid v1.3.0
github.com/hashicorp/golang-lru v0.6.0
github.com/google/uuid v1.3.1
github.com/hashicorp/golang-lru/v2 v2.0.6
github.com/mr-tron/base58 v1.2.0
github.com/nspcc-dev/hrw v1.0.9
github.com/nspcc-dev/neo-go v0.100.1
github.com/nspcc-dev/neo-go v0.102.0
github.com/nspcc-dev/neofs-api-go/v2 v2.14.0
github.com/nspcc-dev/tzhash v1.7.0
github.com/stretchr/testify v1.8.4
github.com/testcontainers/testcontainers-go v0.22.0
go.uber.org/atomic v1.10.0
go.uber.org/zap v1.24.0
github.com/testcontainers/testcontainers-go v0.24.1
carpawell marked this conversation as resolved.
Show resolved Hide resolved
go.uber.org/zap v1.26.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.3 // indirect
github.com/containerd/containerd v1.7.6 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.5+incompatible // indirect
github.com/docker/docker v24.0.6+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/patternmatcher v0.5.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
Expand All @@ -46,9 +49,16 @@ require (
github.com/opencontainers/runc v1.1.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.7 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect
golang.org/x/mod v0.12.0 // indirect
Expand Down
95 changes: 79 additions & 16 deletions go.sum

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ func (o *Object) Signature() *neofscrypto.Signature {
}

var sig neofscrypto.Signature
sig.ReadFromV2(*sigv2) // FIXME(@cthulhu-rider): #226 handle error
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved
if err := sig.ReadFromV2(*sigv2); err != nil {
return nil
}

return &sig
}
Expand Down Expand Up @@ -190,7 +192,9 @@ func (o *Object) SetPayload(v []byte) {
func (o *Object) Version() *version.Version {
var ver version.Version
if verV2 := (*object.Object)(o).GetHeader().GetVersion(); verV2 != nil {
ver.ReadFromV2(*verV2) // FIXME(@cthulhu-rider): #226 handle error
if err := ver.ReadFromV2(*verV2); err != nil {
return nil
}
}
return &ver
}
Expand Down
11 changes: 5 additions & 6 deletions pool/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"
"sync/atomic"

lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/nspcc-dev/neofs-sdk-go/session"
)

Expand All @@ -13,7 +13,7 @@ const (
)

type sessionCache struct {
cache *lru.Cache
cache *lru.Cache[string, *cacheValue]
currentEpoch uint64
}

Expand All @@ -22,7 +22,7 @@ type cacheValue struct {
}

func newCache(cacheSize int) (*sessionCache, error) {
cache, err := lru.New(cacheSize)
cache, err := lru.New[string, *cacheValue](cacheSize)
if err != nil {
return nil, err
}
Expand All @@ -34,12 +34,11 @@ func newCache(cacheSize int) (*sessionCache, error) {
// and context related fields. Returns nil if token is missing in the cache.
// It is safe to modify and re-sign returned session token.
func (c *sessionCache) Get(key string) (session.Object, bool) {
valueRaw, ok := c.cache.Get(key)
value, ok := c.cache.Get(key)
if !ok {
return session.Object{}, false
}

value := valueRaw.(*cacheValue)
if c.expired(value) {
c.cache.Remove(key)
return session.Object{}, false
Expand All @@ -56,7 +55,7 @@ func (c *sessionCache) Put(key string, token session.Object) bool {

func (c *sessionCache) DeleteByPrefix(prefix string) {
for _, key := range c.cache.Keys() {
if strings.HasPrefix(key.(string), prefix) {
if strings.HasPrefix(key, prefix) {
c.cache.Remove(key)
}
}
Expand Down
14 changes: 9 additions & 5 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/rand"
"sort"
"sync"
"sync/atomic"
"time"

"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
Expand All @@ -23,7 +24,6 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/session"
"github.com/nspcc-dev/neofs-sdk-go/stat"
"github.com/nspcc-dev/neofs-sdk-go/user"
"go.uber.org/atomic"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -111,17 +111,21 @@ type clientStatusMonitor struct {
healthy *atomic.Bool
errorThreshold uint32

mu sync.RWMutex // protect counters
mu *sync.RWMutex // protect counters
currentErrorCount uint32
overallErrorCount uint64
}

func newClientStatusMonitor(addr string, errorThreshold uint32) clientStatusMonitor {
return clientStatusMonitor{
m := clientStatusMonitor{
Copy link
Member

@carpawell carpawell Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, i got through this in the node repo but that is the second time i see how adapting to sync makes it harder to read and adds more lines. so maybe add some helper atomic constructor func to our repos?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, no. Frankly, I've expected the stdlib sync to be somewhat more friendly, but it's not that bad either. The best thing here is that it's a standard one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love keeping things as standard as they are so wont argue about that

I've expected the stdlib sync to be somewhat more friendly

but +1 here

addr: addr,
healthy: atomic.NewBool(true),
healthy: &atomic.Bool{},
mu: &sync.RWMutex{},
errorThreshold: errorThreshold,
}

m.healthy.Store(true)
return m
}

// clientWrapper is used by default, alternative implementations are intended for testing purposes only.
Expand Down Expand Up @@ -860,7 +864,7 @@ func (p *Pool) updateInnerNodesHealth(ctx context.Context, i int, bufferWeights
pool := p.innerPools[i]
options := p.rebalanceParams

healthyChanged := atomic.NewBool(false)
healthyChanged := &atomic.Bool{}
wg := sync.WaitGroup{}

for j, cli := range pool.clients {
Expand Down
4 changes: 2 additions & 2 deletions stat/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"errors"
"math/rand"
"sync"
"sync/atomic"
"testing"
"time"

"github.com/stretchr/testify/require"
"go.uber.org/atomic"
)

func TestStatisticConcurrency(t *testing.T) {
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestStatisticConcurrency(t *testing.T) {
var err error
if rand.Int63n(2) > 0 {
err = errors.New("some err")
c.errors.Inc()
c.errors.Add(1)
}

duration := time.Duration(rand.Int63n(200)+1) * time.Millisecond
Expand Down
2 changes: 2 additions & 0 deletions storagegroup/storagegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (sg *StorageGroup) SetValidationDataHash(hash checksum.Checksum) {
// See also SetExpirationEpoch.
func (sg StorageGroup) ExpirationEpoch() uint64 {
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved
v2 := (storagegroup.StorageGroup)(sg)
// nolint:staticcheck
return v2.GetExpirationEpoch()
}

Expand All @@ -148,6 +149,7 @@ func (sg StorageGroup) ExpirationEpoch() uint64 {
//
// See also ExpirationEpoch.
func (sg *StorageGroup) SetExpirationEpoch(epoch uint64) {
// nolint:staticcheck
(*storagegroup.StorageGroup)(sg).SetExpirationEpoch(epoch)
}

Expand Down
3 changes: 3 additions & 0 deletions storagegroup/storagegroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestStorageGroup_ReadFromV2(t *testing.T) {
v2.SetMembers(generateOIDList())

size := v2.GetValidationDataSize()
// nolint:staticcheck
epoch := v2.GetExpirationEpoch()
mm := v2.GetMembers()
hashV2 := v2.GetValidationHash()
Expand Down Expand Up @@ -122,6 +123,7 @@ func TestStorageGroup_WriteToV2(t *testing.T) {
require.Nil(t, v2.GetValidationHash())
require.Nil(t, v2.GetMembers())
require.Zero(t, v2.GetValidationDataSize())
// nolint:staticcheck
require.Zero(t, v2.GetExpirationEpoch())
})

Expand All @@ -133,6 +135,7 @@ func TestStorageGroup_WriteToV2(t *testing.T) {

x.WriteToV2(&v2)

// nolint:staticcheck
require.Equal(t, x.ExpirationEpoch(), v2.GetExpirationEpoch())
require.Equal(t, x.ValidationDataSize(), v2.GetValidationDataSize())

Expand Down
Loading