[#74] pool: move to sync/atomic

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-05-19 14:58:30 +03:00
parent d04d96b42e
commit 9803c2816a
4 changed files with 11 additions and 8 deletions

2
go.mod
View file

@ -13,7 +13,6 @@ require (
github.com/mr-tron/base58 v1.2.0
github.com/nspcc-dev/neo-go v0.100.1
github.com/stretchr/testify v1.8.2
go.uber.org/atomic v1.10.0
go.uber.org/zap v1.24.0
)
@ -42,6 +41,7 @@ require (
go.opentelemetry.io/otel/sdk v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/exp v0.0.0-20221227203929-1b447090c38c // indirect

BIN
go.sum

Binary file not shown.

View file

@ -10,7 +10,7 @@ import (
type sessionCache struct {
cache *lru.Cache[string, *cacheValue]
currentEpoch uint64
currentEpoch atomic.Uint64
}
type cacheValue struct {
@ -58,14 +58,14 @@ func (c *sessionCache) DeleteByPrefix(prefix string) {
}
func (c *sessionCache) updateEpoch(newEpoch uint64) {
epoch := atomic.LoadUint64(&c.currentEpoch)
epoch := c.currentEpoch.Load()
if newEpoch > epoch {
atomic.StoreUint64(&c.currentEpoch, newEpoch)
c.currentEpoch.Store(newEpoch)
}
}
func (c *sessionCache) expired(val *cacheValue) bool {
epoch := atomic.LoadUint64(&c.currentEpoch)
epoch := c.currentEpoch.Load()
// use epoch+1 (clear cache beforehand) to prevent 'expired session token' error right after epoch tick
return val.token.ExpiredAt(epoch + 1)
}

View file

@ -11,6 +11,7 @@ import (
"math/rand"
"sort"
"sync"
"sync/atomic"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/accounting"
@ -29,7 +30,6 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
"github.com/google/uuid"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"go.uber.org/atomic"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
@ -194,10 +194,13 @@ func newClientStatusMonitor(logger *zap.Logger, addr string, errorThreshold uint
methods[i] = &methodStatus{name: i.String()}
}
healthy := new(atomic.Bool)
healthy.Store(true)
return clientStatusMonitor{
logger: logger,
addr: addr,
healthy: atomic.NewBool(true),
healthy: healthy,
errorThreshold: errorThreshold,
methods: methods,
}
@ -1796,7 +1799,7 @@ func (p *Pool) updateInnerNodesHealth(ctx context.Context, i int, bufferWeights
pool := p.innerPools[i]
options := p.rebalanceParams
healthyChanged := atomic.NewBool(false)
healthyChanged := new(atomic.Bool)
wg := sync.WaitGroup{}
for j, cli := range pool.clients {