From d485a5967db966bb2b7b82b5a1d628a8a03a16a3 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 18 Nov 2020 16:04:09 +0300 Subject: [PATCH] [#184] Use SDK client cache in object.Search Signed-off-by: Alex Vanin --- cmd/neofs-node/object.go | 1 + pkg/services/object/search/remote.go | 7 ++++--- pkg/services/object/search/service.go | 9 +++++++++ pkg/services/object/search/streamer.go | 7 ++++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index d5020b3a3..6a38484c4 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 6dbfaab50..14c1c5094 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 d16bd8f2d..b30994a8c 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 f8934a21c..286b5ec6f 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, } }