From f85e88c4f8f86c83d6388206cdc538412575a853 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 18 Nov 2020 16:04:33 +0300 Subject: [PATCH] [#184] Use SDK client cache in object.Range Signed-off-by: Alex Vanin --- cmd/neofs-node/object.go | 1 + pkg/services/object/range/remote.go | 7 ++++--- pkg/services/object/range/service.go | 9 +++++++++ pkg/services/object/range/streamer.go | 15 ++++++++------- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 6a38484c..5b5b043b 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -294,6 +294,7 @@ func initObjectService(c *cfg) { sRange := rangesvc.NewService( rangesvc.WithKeyStorage(keyStorage), + rangesvc.WithClientCache(clientCache), rangesvc.WithLocalStorage(ls), rangesvc.WithContainerSource(c.cfgObject.cnrStorage), rangesvc.WithNetworkMapSource(c.cfgObject.netMapStorage), diff --git a/pkg/services/object/range/remote.go b/pkg/services/object/range/remote.go index 1ad9389a..b9281db7 100644 --- a/pkg/services/object/range/remote.go +++ b/pkg/services/object/range/remote.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/token" "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" ) @@ -26,6 +27,8 @@ type remoteRangeWriter struct { addr *object.Address rng *object.Range + + clientCache *cache.ClientCache } func (r *remoteRangeWriter) WriteTo(w io.Writer) (int64, error) { @@ -39,9 +42,7 @@ func (r *remoteRangeWriter) WriteTo(w io.Writer) (int64, error) { return 0, err } - c, err := client.New(key, - client.WithAddress(addr), - ) + c, err := r.clientCache.Get(key, addr) if err != nil { return 0, errors.Wrapf(err, "(%T) could not create SDK client %s", r, addr) } diff --git a/pkg/services/object/range/service.go b/pkg/services/object/range/service.go index 5d088e0f..2cc7849a 100644 --- a/pkg/services/object/range/service.go +++ b/pkg/services/object/range/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" headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head" objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/util" @@ -35,6 +36,8 @@ type cfg struct { localAddrSrc network.LocalAddressSource headSvc *headsvc.Service + + clientCache *cache.ClientCache } func defaultCfg() *cfg { @@ -164,3 +167,9 @@ func WithHeadService(v *headsvc.Service) Option { c.headSvc = v } } + +func WithClientCache(v *cache.ClientCache) Option { + return func(c *cfg) { + c.clientCache = v + } +} diff --git a/pkg/services/object/range/streamer.go b/pkg/services/object/range/streamer.go index 54a95610..ebc71401 100644 --- a/pkg/services/object/range/streamer.go +++ b/pkg/services/object/range/streamer.go @@ -178,13 +178,14 @@ loop: } } else { rngWriter = &remoteRangeWriter{ - ctx: p.ctx, - keyStorage: p.keyStorage, - node: addr, - token: p.prm.common.SessionToken(), - bearer: p.prm.common.BearerToken(), - addr: objAddr, - rng: nextRange, + ctx: p.ctx, + keyStorage: p.keyStorage, + node: addr, + token: p.prm.common.SessionToken(), + bearer: p.prm.common.BearerToken(), + addr: objAddr, + rng: nextRange, + clientCache: p.clientCache, } }