diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index d5020b3a..6a38484c 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -265,6 +265,7 @@ func initObjectService(c *cfg) { sSearch := searchsvc.NewService( searchsvc.WithKeyStorage(keyStorage), + searchsvc.WithClientCache(clientCache), searchsvc.WithLocalStorage(ls), searchsvc.WithContainerSource(c.cfgObject.cnrStorage), searchsvc.WithNetworkMapSource(c.cfgObject.netMapStorage), diff --git a/pkg/services/object/search/remote.go b/pkg/services/object/search/remote.go index 6dbfaab5..14c1c509 100644 --- a/pkg/services/object/search/remote.go +++ b/pkg/services/object/search/remote.go @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/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" ) @@ -16,6 +17,8 @@ type remoteStream struct { keyStorage *util.KeyStorage addr *network.Address + + clientCache *cache.ClientCache } func (s *remoteStream) stream(ctx context.Context, ch chan<- []*object.ID) error { @@ -29,9 +32,7 @@ func (s *remoteStream) stream(ctx context.Context, ch chan<- []*object.ID) error return err } - c, err := client.New(key, - client.WithAddress(addr), - ) + c, err := s.clientCache.Get(key, addr) if err != nil { return errors.Wrapf(err, "(%T) could not create SDK client %s", s, addr) } diff --git a/pkg/services/object/search/service.go b/pkg/services/object/search/service.go index d16bd8f2..b30994a8 100644 --- a/pkg/services/object/search/service.go +++ b/pkg/services/object/search/service.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/localstore" "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" ) @@ -31,6 +32,8 @@ type cfg struct { workerPool util.WorkerPool localAddrSrc network.LocalAddressSource + + clientCache *cache.ClientCache } func defaultCfg() *cfg { @@ -96,3 +99,9 @@ func WithLocalAddressSource(v network.LocalAddressSource) Option { c.localAddrSrc = v } } + +func WithClientCache(v *cache.ClientCache) Option { + return func(c *cfg) { + c.clientCache = v + } +} diff --git a/pkg/services/object/search/streamer.go b/pkg/services/object/search/streamer.go index f8934a21..286b5ec6 100644 --- a/pkg/services/object/search/streamer.go +++ b/pkg/services/object/search/streamer.go @@ -161,9 +161,10 @@ loop: } } else { streamer = &remoteStream{ - prm: prm, - keyStorage: p.keyStorage, - addr: addr, + prm: prm, + keyStorage: p.keyStorage, + addr: addr, + clientCache: p.clientCache, } }