From faca8614513a8fab594152b146d89270a0cd4576 Mon Sep 17 00:00:00 2001 From: Alejandro Lopez Date: Tue, 30 May 2023 10:14:37 +0300 Subject: [PATCH] [#411] Remove unnecessary pointers for sync objects Signed-off-by: Alejandro Lopez --- cmd/frostfs-node/cache.go | 8 +++----- cmd/frostfs-node/config.go | 3 +-- pkg/innerring/processors/alphabet/processor.go | 3 +-- pkg/innerring/processors/frostfs/processor.go | 3 +-- .../processors/netmap/cleanup_table.go | 3 +-- pkg/local_object_storage/engine/engine.go | 17 +++++++---------- .../engine/evacuate_limiter.go | 2 +- pkg/morph/client/client.go | 4 ++-- pkg/morph/client/constructor.go | 15 ++++++--------- pkg/morph/subscriber/subscriber.go | 3 +-- pkg/morph/timer/block.go | 4 +--- pkg/services/notificator/nats/service.go | 3 +-- pkg/services/object/get/v2/get_forwarder.go | 4 ++-- .../object/get/v2/get_range_forwarder.go | 2 +- pkg/services/object/get/v2/head_forwarder.go | 2 +- pkg/services/object/get/v2/util.go | 13 ++++--------- .../object/search/v2/request_forwarder.go | 2 +- pkg/services/object/search/v2/util.go | 6 ++---- .../object_manager/placement/traverser.go | 3 +-- .../session/storage/temporary/storage.go | 3 +-- 20 files changed, 39 insertions(+), 64 deletions(-) diff --git a/cmd/frostfs-node/cache.go b/cmd/frostfs-node/cache.go index dfbaf3525..bae38b299 100644 --- a/cmd/frostfs-node/cache.go +++ b/cmd/frostfs-node/cache.go @@ -25,19 +25,18 @@ type valueWithTime[V any] struct { } type locker struct { - mtx *sync.Mutex + mtx sync.Mutex waiters int // not protected by mtx, must used outer mutex to update concurrently } type keyLocker[K comparable] struct { lockers map[K]*locker - lockersMtx *sync.Mutex + lockersMtx sync.Mutex } func newKeyLocker[K comparable]() *keyLocker[K] { return &keyLocker[K]{ - lockers: make(map[K]*locker), - lockersMtx: &sync.Mutex{}, + lockers: make(map[K]*locker), } } @@ -53,7 +52,6 @@ func (l *keyLocker[K]) LockKey(key K) { } locker := &locker{ - mtx: &sync.Mutex{}, waiters: 1, } locker.mtx.Lock() diff --git a/cmd/frostfs-node/config.go b/cmd/frostfs-node/config.go index 30d457967..00ade7ce2 100644 --- a/cmd/frostfs-node/config.go +++ b/cmd/frostfs-node/config.go @@ -327,7 +327,7 @@ type internals struct { log *logger.Logger - wg *sync.WaitGroup + wg sync.WaitGroup workers []worker closers []closer @@ -589,7 +589,6 @@ func initInternals(appCfg *config.Config, log *logger.Logger) internals { appCfg: appCfg, internalErr: make(chan error), log: log, - wg: new(sync.WaitGroup), apiVersion: version.Current(), healthStatus: &healthStatus, } diff --git a/pkg/innerring/processors/alphabet/processor.go b/pkg/innerring/processors/alphabet/processor.go index 972f84281..04dde80f7 100644 --- a/pkg/innerring/processors/alphabet/processor.go +++ b/pkg/innerring/processors/alphabet/processor.go @@ -49,7 +49,7 @@ type ( Processor struct { parsedWallets []util.Uint160 // protects parsedWallets from concurrent change - pwLock *sync.RWMutex + pwLock sync.RWMutex log *logger.Logger metrics metrics.Register pool *ants.Pool @@ -99,7 +99,6 @@ func New(p *Params) (*Processor, error) { return &Processor{ parsedWallets: p.ParsedWallets, - pwLock: new(sync.RWMutex), log: p.Log, metrics: metricsRegister, pool: pool, diff --git a/pkg/innerring/processors/frostfs/processor.go b/pkg/innerring/processors/frostfs/processor.go index e6ee78837..20f44adcd 100644 --- a/pkg/innerring/processors/frostfs/processor.go +++ b/pkg/innerring/processors/frostfs/processor.go @@ -68,7 +68,7 @@ type ( epochState EpochState alphabetState AlphabetState converter PrecisionConverter - mintEmitLock *sync.Mutex + mintEmitLock sync.Mutex mintEmitCache *lru.Cache[string, uint64] mintEmitThreshold uint64 mintEmitValue fixedn.Fixed8 @@ -148,7 +148,6 @@ func New(p *Params) (*Processor, error) { epochState: p.EpochState, alphabetState: p.AlphabetState, converter: p.Converter, - mintEmitLock: new(sync.Mutex), mintEmitCache: lruCache, mintEmitThreshold: p.MintEmitThreshold, mintEmitValue: p.MintEmitValue, diff --git a/pkg/innerring/processors/netmap/cleanup_table.go b/pkg/innerring/processors/netmap/cleanup_table.go index e4024e95f..80117247d 100644 --- a/pkg/innerring/processors/netmap/cleanup_table.go +++ b/pkg/innerring/processors/netmap/cleanup_table.go @@ -9,7 +9,7 @@ import ( type ( cleanupTable struct { - *sync.RWMutex + sync.RWMutex enabled bool threshold uint64 lastAccess map[string]epochStampWithNodeInfo @@ -29,7 +29,6 @@ type ( func newCleanupTable(enabled bool, threshold uint64) cleanupTable { return cleanupTable{ - RWMutex: new(sync.RWMutex), enabled: enabled, threshold: threshold, lastAccess: make(map[string]epochStampWithNodeInfo), diff --git a/pkg/local_object_storage/engine/engine.go b/pkg/local_object_storage/engine/engine.go index 19e7b5237..21e863005 100644 --- a/pkg/local_object_storage/engine/engine.go +++ b/pkg/local_object_storage/engine/engine.go @@ -20,7 +20,7 @@ type StorageEngine struct { removeDuplicatesInProgress atomic.Bool - mtx *sync.RWMutex + mtx sync.RWMutex shards map[string]hashedShard @@ -225,15 +225,12 @@ func New(opts ...Option) *StorageEngine { } return &StorageEngine{ - cfg: c, - mtx: new(sync.RWMutex), - shards: make(map[string]hashedShard), - shardPools: make(map[string]util.WorkerPool), - closeCh: make(chan struct{}), - setModeCh: make(chan setModeRequest), - evacuateLimiter: &evacuationLimiter{ - guard: &sync.RWMutex{}, - }, + cfg: c, + shards: make(map[string]hashedShard), + shardPools: make(map[string]util.WorkerPool), + closeCh: make(chan struct{}), + setModeCh: make(chan setModeRequest), + evacuateLimiter: &evacuationLimiter{}, } } diff --git a/pkg/local_object_storage/engine/evacuate_limiter.go b/pkg/local_object_storage/engine/evacuate_limiter.go index 425fdc775..62795fa1a 100644 --- a/pkg/local_object_storage/engine/evacuate_limiter.go +++ b/pkg/local_object_storage/engine/evacuate_limiter.go @@ -113,7 +113,7 @@ type evacuationLimiter struct { eg *errgroup.Group cancel context.CancelFunc - guard *sync.RWMutex + guard sync.RWMutex } func (l *evacuationLimiter) TryStart(ctx context.Context, shardIDs []string, result *EvacuateShardRes) (*errgroup.Group, context.Context, error) { diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index 6b6e1284b..de29d0c03 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -66,7 +66,7 @@ type Client struct { // switchLock protects endpoints, inactive, and subscription-related fields. // It is taken exclusively during endpoint switch and locked in shared mode // on every normal call. - switchLock *sync.RWMutex + switchLock sync.RWMutex // channel for internal stop closeChan chan struct{} @@ -83,7 +83,7 @@ type Client struct { } type cache struct { - m *sync.RWMutex + m sync.RWMutex nnsHash *util.Uint160 gKey *keys.PublicKey diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 1f2a1eb8d..ff37da728 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "sync" "time" "git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs" @@ -105,13 +104,12 @@ func New(ctx context.Context, key *keys.PrivateKey, opts ...Option) (*Client, er } cli := &Client{ - cache: newClientCache(), - logger: cfg.logger, - acc: acc, - accAddr: accAddr, - cfg: *cfg, - switchLock: &sync.RWMutex{}, - closeChan: make(chan struct{}), + cache: newClientCache(), + logger: cfg.logger, + acc: acc, + accAddr: accAddr, + cfg: *cfg, + closeChan: make(chan struct{}), } cli.endpoints.init(cfg.endpoints) @@ -198,7 +196,6 @@ func newActor(ws *rpcclient.WSClient, acc *wallet.Account, cfg cfg) (*actor.Acto func newClientCache() cache { c, _ := lru.New[util.Uint256, uint32](100) // returns error only if size is negative return cache{ - m: &sync.RWMutex{}, txHeights: c, } } diff --git a/pkg/morph/subscriber/subscriber.go b/pkg/morph/subscriber/subscriber.go index 383d58407..608872dec 100644 --- a/pkg/morph/subscriber/subscriber.go +++ b/pkg/morph/subscriber/subscriber.go @@ -42,7 +42,7 @@ type ( } subscriber struct { - *sync.RWMutex + sync.RWMutex log *logger.Logger client *client.Client @@ -163,7 +163,6 @@ func New(ctx context.Context, p *Params) (Subscriber, error) { } sub := &subscriber{ - RWMutex: new(sync.RWMutex), log: p.Log, client: p.Client, notifyChan: make(chan *state.ContainedNotificationEvent), diff --git a/pkg/morph/timer/block.go b/pkg/morph/timer/block.go index 31c28e2ff..be20d3571 100644 --- a/pkg/morph/timer/block.go +++ b/pkg/morph/timer/block.go @@ -17,7 +17,7 @@ type BlockTickHandler func() type BlockTimer struct { rolledBack bool - mtx *sync.Mutex + mtx sync.Mutex dur BlockMeter @@ -64,7 +64,6 @@ func StaticBlockMeter(d uint32) BlockMeter { // Reset should be called before timer ticking. func NewBlockTimer(dur BlockMeter, h BlockTickHandler) *BlockTimer { return &BlockTimer{ - mtx: new(sync.Mutex), dur: dur, mul: 1, div: 1, @@ -80,7 +79,6 @@ func NewBlockTimer(dur BlockMeter, h BlockTickHandler) *BlockTimer { // Do not use delta handlers with pulse in this timer. func NewOneTickTimer(dur BlockMeter, h BlockTickHandler) *BlockTimer { return &BlockTimer{ - mtx: new(sync.Mutex), dur: dur, mul: 1, div: 1, diff --git a/pkg/services/notificator/nats/service.go b/pkg/services/notificator/nats/service.go index 6a7e80a53..19f0cbde1 100644 --- a/pkg/services/notificator/nats/service.go +++ b/pkg/services/notificator/nats/service.go @@ -25,7 +25,7 @@ type Writer struct { js nats.JetStreamContext nc *nats.Conn - m *sync.RWMutex + m sync.RWMutex createdStreams map[string]struct{} opts } @@ -84,7 +84,6 @@ func (n *Writer) Notify(topic string, address oid.Address) error { // New creates new Writer. func New(oo ...Option) *Writer { w := &Writer{ - m: &sync.RWMutex{}, createdStreams: make(map[string]struct{}), opts: opts{ log: &logger.Logger{Logger: zap.L()}, diff --git a/pkg/services/object/get/v2/get_forwarder.go b/pkg/services/object/get/v2/get_forwarder.go index d11f94b26..bc27f69a2 100644 --- a/pkg/services/object/get/v2/get_forwarder.go +++ b/pkg/services/object/get/v2/get_forwarder.go @@ -23,8 +23,8 @@ import ( ) type getRequestForwarder struct { - OnceResign *sync.Once - OnceHeaderSending *sync.Once + OnceResign sync.Once + OnceHeaderSending sync.Once GlobalProgress int Key *ecdsa.PrivateKey Request *objectV2.GetRequest diff --git a/pkg/services/object/get/v2/get_range_forwarder.go b/pkg/services/object/get/v2/get_range_forwarder.go index 6c744b23a..1137ba33c 100644 --- a/pkg/services/object/get/v2/get_range_forwarder.go +++ b/pkg/services/object/get/v2/get_range_forwarder.go @@ -23,7 +23,7 @@ import ( ) type getRangeRequestForwarder struct { - OnceResign *sync.Once + OnceResign sync.Once GlobalProgress int Key *ecdsa.PrivateKey Request *objectV2.GetRangeRequest diff --git a/pkg/services/object/get/v2/head_forwarder.go b/pkg/services/object/get/v2/head_forwarder.go index 0c91ec5d8..1b0374aea 100644 --- a/pkg/services/object/get/v2/head_forwarder.go +++ b/pkg/services/object/get/v2/head_forwarder.go @@ -25,7 +25,7 @@ import ( type headRequestForwarder struct { Request *objectV2.HeadRequest Response *objectV2.HeadResponse - OnceResign *sync.Once + OnceResign sync.Once ObjectAddr oid.Address Key *ecdsa.PrivateKey } diff --git a/pkg/services/object/get/v2/util.go b/pkg/services/object/get/v2/util.go index 91e7a96a2..519d9afa0 100644 --- a/pkg/services/object/get/v2/util.go +++ b/pkg/services/object/get/v2/util.go @@ -5,7 +5,6 @@ import ( "crypto/sha256" "errors" "hash" - "sync" objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" @@ -59,12 +58,10 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre } forwarder := &getRequestForwarder{ - OnceResign: &sync.Once{}, - OnceHeaderSending: &sync.Once{}, - GlobalProgress: 0, - Key: key, - Request: req, - Stream: streamWrapper, + GlobalProgress: 0, + Key: key, + Request: req, + Stream: streamWrapper, } p.SetRequestForwarder(groupAddressRequestForwarder(forwarder.forwardRequestToNode)) @@ -115,7 +112,6 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get } forwarder := &getRangeRequestForwarder{ - OnceResign: &sync.Once{}, GlobalProgress: 0, Key: key, Request: req, @@ -254,7 +250,6 @@ func (s *Service) toHeadPrm(req *objectV2.HeadRequest, resp *objectV2.HeadRespon forwarder := &headRequestForwarder{ Request: req, Response: resp, - OnceResign: &sync.Once{}, ObjectAddr: objAddr, Key: key, } diff --git a/pkg/services/object/search/v2/request_forwarder.go b/pkg/services/object/search/v2/request_forwarder.go index d8719986f..5a2e9b936 100644 --- a/pkg/services/object/search/v2/request_forwarder.go +++ b/pkg/services/object/search/v2/request_forwarder.go @@ -20,7 +20,7 @@ import ( ) type requestForwarder struct { - OnceResign *sync.Once + OnceResign sync.Once Request *objectV2.SearchRequest Key *ecdsa.PrivateKey } diff --git a/pkg/services/object/search/v2/util.go b/pkg/services/object/search/v2/util.go index 12158a820..cfccaede6 100644 --- a/pkg/services/object/search/v2/util.go +++ b/pkg/services/object/search/v2/util.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "sync" objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client" @@ -51,9 +50,8 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre } forwarder := &requestForwarder{ - OnceResign: &sync.Once{}, - Request: req, - Key: key, + Request: req, + Key: key, } p.SetRequestForwarder(groupAddressRequestForwarder(forwarder.forwardRequest)) diff --git a/pkg/services/object_manager/placement/traverser.go b/pkg/services/object_manager/placement/traverser.go index e46240a86..7b9b26a0b 100644 --- a/pkg/services/object_manager/placement/traverser.go +++ b/pkg/services/object_manager/placement/traverser.go @@ -29,7 +29,7 @@ type Option func(*cfg) // Traverser represents utility for controlling // traversal of object placement vectors. type Traverser struct { - mtx *sync.RWMutex + mtx sync.RWMutex vectors [][]netmap.NodeInfo @@ -107,7 +107,6 @@ func NewTraverser(opts ...Option) (*Traverser, error) { } return &Traverser{ - mtx: new(sync.RWMutex), rem: rem, vectors: ns, }, nil diff --git a/pkg/services/session/storage/temporary/storage.go b/pkg/services/session/storage/temporary/storage.go index 370499e06..ee93dee71 100644 --- a/pkg/services/session/storage/temporary/storage.go +++ b/pkg/services/session/storage/temporary/storage.go @@ -18,7 +18,7 @@ type key struct { // expiring (removing) session tokens. // Must be created only via calling NewTokenStore. type TokenStore struct { - mtx *sync.RWMutex + mtx sync.RWMutex tokens map[key]*storage.PrivateToken } @@ -28,7 +28,6 @@ type TokenStore struct { // The elements of the instance are stored in the map. func NewTokenStore() *TokenStore { return &TokenStore{ - mtx: new(sync.RWMutex), tokens: make(map[key]*storage.PrivateToken), } }