diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index 7f127f68..b38169a6 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -195,7 +195,9 @@ type remoteLoadAnnounceProvider struct { loadAddrSrc network.LocalAddressSource - clientCache *cache.ClientCache + clientCache interface { + Get(string) (apiClient.Client, error) + } deadEndProvider loadcontroller.WriterProvider } diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 2f5f19b3..0f6e19d7 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -230,7 +230,7 @@ func initObjectService(c *cfg) { sPut := putsvc.NewService( putsvc.WithKeyStorage(keyStorage), - putsvc.WithClientCache(clientCache), + putsvc.WithClientConstructor(clientCache), putsvc.WithMaxSizeSource(c), putsvc.WithLocalStorage(ls), putsvc.WithContainerSource(c.cfgObject.cnrStorage), @@ -251,7 +251,7 @@ func initObjectService(c *cfg) { sSearch := searchsvc.New( searchsvc.WithLogger(c.log), searchsvc.WithLocalStorageEngine(ls), - searchsvc.WithClientCache(clientCache), + searchsvc.WithClientConstructor(clientCache), searchsvc.WithTraverserGenerator( traverseGen.WithTraverseOptions( placement.WithoutSuccessTracking(), @@ -268,7 +268,7 @@ func initObjectService(c *cfg) { sGet := getsvc.New( getsvc.WithLogger(c.log), getsvc.WithLocalStorageEngine(ls), - getsvc.WithClientCache(clientCache), + getsvc.WithClientConstructor(clientCache), getsvc.WithTraverserGenerator( traverseGen.WithTraverseOptions( placement.SuccessAfter(1), diff --git a/pkg/innerring/rpc.go b/pkg/innerring/rpc.go index fa4f56e7..7e81f70c 100644 --- a/pkg/innerring/rpc.go +++ b/pkg/innerring/rpc.go @@ -21,8 +21,10 @@ import ( type ( ClientCache struct { log *zap.Logger - cache *cache.ClientCache - key *ecdsa.PrivateKey + cache interface { + Get(string) (client.Client, error) + } + key *ecdsa.PrivateKey sgTimeout, headTimeout, rangeTimeout time.Duration } diff --git a/pkg/services/object/get/service.go b/pkg/services/object/get/service.go index 54c9e15d..386747aa 100644 --- a/pkg/services/object/get/service.go +++ b/pkg/services/object/get/service.go @@ -1,11 +1,11 @@ package getsvc import ( + "github.com/nspcc-dev/neofs-api-go/pkg/client" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" - "github.com/nspcc-dev/neofs-node/pkg/network/cache" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/util/logger" @@ -91,8 +91,12 @@ func WithLocalStorageEngine(e *engine.StorageEngine) Option { } } -// WithClientCache returns option to set cache of remote node clients. -func WithClientCache(v *cache.ClientCache) Option { +type ClientConstructor interface { + Get(string) (client.Client, error) +} + +// WithClientConstructor returns option to set constructor of remote node clients. +func WithClientConstructor(v ClientConstructor) Option { return func(c *cfg) { c.clientCache.(*clientCacheWrapper).cache = v } diff --git a/pkg/services/object/get/util.go b/pkg/services/object/get/util.go index 1b19ad04..01a55ede 100644 --- a/pkg/services/object/get/util.go +++ b/pkg/services/object/get/util.go @@ -8,7 +8,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" - "github.com/nspcc-dev/neofs-node/pkg/network/cache" ) type SimpleObjectWriter struct { @@ -18,7 +17,7 @@ type SimpleObjectWriter struct { } type clientCacheWrapper struct { - cache *cache.ClientCache + cache ClientConstructor } type clientWrapper struct { diff --git a/pkg/services/object/head/remote.go b/pkg/services/object/head/remote.go index 39f31be0..450d48c5 100644 --- a/pkg/services/object/head/remote.go +++ b/pkg/services/object/head/remote.go @@ -7,17 +7,20 @@ import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/network" - "github.com/nspcc-dev/neofs-node/pkg/network/cache" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/pkg/errors" ) +type ClientConstructor interface { + Get(string) (client.Client, error) +} + // RemoteHeader represents utility for getting // the object header from a remote host. type RemoteHeader struct { keyStorage *util.KeyStorage - clientCache *cache.ClientCache + clientCache ClientConstructor } // RemoteHeadPrm groups remote header operation parameters. @@ -30,7 +33,7 @@ type RemoteHeadPrm struct { var ErrNotFound = errors.New("object header not found") // NewRemoteHeader creates, initializes and returns new RemoteHeader instance. -func NewRemoteHeader(keyStorage *util.KeyStorage, cache *cache.ClientCache) *RemoteHeader { +func NewRemoteHeader(keyStorage *util.KeyStorage, cache ClientConstructor) *RemoteHeader { return &RemoteHeader{ keyStorage: keyStorage, clientCache: cache, diff --git a/pkg/services/object/put/remote.go b/pkg/services/object/put/remote.go index dc5a21ab..3c2b1535 100644 --- a/pkg/services/object/put/remote.go +++ b/pkg/services/object/put/remote.go @@ -6,7 +6,6 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/network" - "github.com/nspcc-dev/neofs-node/pkg/network/cache" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer" "github.com/pkg/errors" @@ -25,7 +24,7 @@ type remoteTarget struct { obj *object.Object - clientCache *cache.ClientCache + clientConstructor ClientConstructor } // RemoteSender represents utility for @@ -33,7 +32,7 @@ type remoteTarget struct { type RemoteSender struct { keyStorage *util.KeyStorage - clientCache *cache.ClientCache + clientConstructor ClientConstructor } // RemotePutPrm groups remote put operation parameters. @@ -60,7 +59,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) { return nil, err } - c, err := t.clientCache.Get(addr) + c, err := t.clientConstructor.Get(addr) if err != nil { return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", t, addr) } @@ -84,10 +83,10 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) { } // NewRemoteSender creates, initializes and returns new RemoteSender instance. -func NewRemoteSender(keyStorage *util.KeyStorage, cache *cache.ClientCache) *RemoteSender { +func NewRemoteSender(keyStorage *util.KeyStorage, cons ClientConstructor) *RemoteSender { return &RemoteSender{ - keyStorage: keyStorage, - clientCache: cache, + keyStorage: keyStorage, + clientConstructor: cons, } } @@ -112,10 +111,10 @@ func (p *RemotePutPrm) WithObject(v *object.Object) *RemotePutPrm { // PutObject sends object to remote node. func (s *RemoteSender) PutObject(ctx context.Context, p *RemotePutPrm) error { t := &remoteTarget{ - ctx: ctx, - keyStorage: s.keyStorage, - addr: p.node, - clientCache: s.clientCache, + ctx: ctx, + keyStorage: s.keyStorage, + addr: p.node, + clientConstructor: s.clientConstructor, } if err := t.WriteHeader(object.NewRawFromObject(p.obj)); err != nil { diff --git a/pkg/services/object/put/service.go b/pkg/services/object/put/service.go index 186ffe1d..b4ddd657 100644 --- a/pkg/services/object/put/service.go +++ b/pkg/services/object/put/service.go @@ -3,12 +3,12 @@ package putsvc import ( "context" + "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" "github.com/nspcc-dev/neofs-node/pkg/network" - "github.com/nspcc-dev/neofs-node/pkg/network/cache" objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/util/logger" @@ -29,6 +29,10 @@ type Service struct { type Option func(*cfg) +type ClientConstructor interface { + Get(string) (client.Client, error) +} + type cfg struct { keyStorage *objutil.KeyStorage @@ -50,7 +54,7 @@ type cfg struct { networkState netmap.State - clientCache *cache.ClientCache + clientConstructor ClientConstructor log *logger.Logger } @@ -138,9 +142,9 @@ func WithNetworkState(v netmap.State) Option { } } -func WithClientCache(v *cache.ClientCache) Option { +func WithClientConstructor(v ClientConstructor) Option { return func(c *cfg) { - c.clientCache = v + c.clientConstructor = v } } diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index 9e158a3d..5305c48d 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -139,11 +139,11 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget { } return &remoteTarget{ - ctx: p.ctx, - keyStorage: p.keyStorage, - commonPrm: prm.common, - addr: addr, - clientCache: p.clientCache, + ctx: p.ctx, + keyStorage: p.keyStorage, + commonPrm: prm.common, + addr: addr, + clientConstructor: p.clientConstructor, } }, fmt: p.fmtValidator, diff --git a/pkg/services/object/search/exec.go b/pkg/services/object/search/exec.go index 4803770f..3b376f83 100644 --- a/pkg/services/object/search/exec.go +++ b/pkg/services/object/search/exec.go @@ -147,7 +147,7 @@ func (exec execCtx) remoteClient(node *network.Address) (searchClient, bool) { log.Debug("could not calculate node IP address") case err == nil: - c, err := exec.svc.clientCache.get(ipAddr) + c, err := exec.svc.clientConstructor.get(ipAddr) switch { default: diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index 4def0f93..f803c2b4 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -257,7 +257,7 @@ func TestGetRemoteSmall(t *testing.T) { curEpoch: b, }, } - svc.clientCache = c + svc.clientConstructor = c svc.currentEpochReceiver = testEpochReceiver(curEpoch) return svc @@ -376,7 +376,7 @@ func TestGetFromPastEpoch(t *testing.T) { }, } - svc.clientCache = &testClientCache{ + svc.clientConstructor = &testClientCache{ clients: map[string]*testStorage{ as[0][0]: c11, as[0][1]: c12, diff --git a/pkg/services/object/search/service.go b/pkg/services/object/search/service.go index f8ad71b9..b0097b34 100644 --- a/pkg/services/object/search/service.go +++ b/pkg/services/object/search/service.go @@ -1,11 +1,11 @@ package searchsvc import ( + "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" - "github.com/nspcc-dev/neofs-node/pkg/network/cache" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/util/logger" @@ -25,6 +25,10 @@ type searchClient interface { searchObjects(*execCtx) ([]*object.ID, error) } +type ClientConstructor interface { + Get(string) (client.Client, error) +} + type cfg struct { log *logger.Logger @@ -32,7 +36,7 @@ type cfg struct { search(*execCtx) ([]*object.ID, error) } - clientCache interface { + clientConstructor interface { get(string) (searchClient, error) } @@ -47,8 +51,8 @@ type cfg struct { func defaultCfg() *cfg { return &cfg{ - log: zap.L(), - clientCache: new(clientCacheWrapper), + log: zap.L(), + clientConstructor: new(clientConstructorWrapper), } } @@ -81,10 +85,10 @@ func WithLocalStorageEngine(e *engine.StorageEngine) Option { } } -// WithClientCache returns option to set cache of remote node clients. -func WithClientCache(v *cache.ClientCache) Option { +// WithClientConstructor returns option to set constructor of remote node clients. +func WithClientConstructor(v ClientConstructor) Option { return func(c *cfg) { - c.clientCache.(*clientCacheWrapper).cache = v + c.clientConstructor.(*clientConstructorWrapper).constructor = v } } diff --git a/pkg/services/object/search/util.go b/pkg/services/object/search/util.go index fc446a93..bb25e870 100644 --- a/pkg/services/object/search/util.go +++ b/pkg/services/object/search/util.go @@ -8,7 +8,6 @@ import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" - "github.com/nspcc-dev/neofs-node/pkg/network/cache" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" ) @@ -21,8 +20,8 @@ type uniqueIDWriter struct { writer IDListWriter } -type clientCacheWrapper struct { - cache *cache.ClientCache +type clientConstructorWrapper struct { + constructor ClientConstructor } type clientWrapper struct { @@ -68,8 +67,8 @@ func (w *uniqueIDWriter) WriteIDs(list []*objectSDK.ID) error { return w.writer.WriteIDs(list) } -func (c *clientCacheWrapper) get(addr string) (searchClient, error) { - clt, err := c.cache.Get(addr) +func (c *clientConstructorWrapper) get(addr string) (searchClient, error) { + clt, err := c.constructor.Get(addr) return &clientWrapper{ client: clt,