diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 5b5b043b01..2a0367ca4d 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -317,6 +317,7 @@ func initObjectService(c *cfg) { sRangeHash := rangehashsvc.NewService( rangehashsvc.WithKeyStorage(keyStorage), + rangehashsvc.WithClientCache(clientCache), rangehashsvc.WithLocalStorage(ls), rangehashsvc.WithContainerSource(c.cfgObject.cnrStorage), rangehashsvc.WithNetworkMapSource(c.cfgObject.netMapStorage), diff --git a/pkg/services/object/rangehash/distributed.go b/pkg/services/object/rangehash/distributed.go index 79872cd6b0..da9a45c912 100644 --- a/pkg/services/object/rangehash/distributed.go +++ b/pkg/services/object/rangehash/distributed.go @@ -112,8 +112,9 @@ loop: } } else { hasher = &remoteHasher{ - keyStorage: h.keyStorage, - node: addr, + keyStorage: h.keyStorage, + node: addr, + clientCache: h.clientCache, } } diff --git a/pkg/services/object/rangehash/remote.go b/pkg/services/object/rangehash/remote.go index 4635c8728c..5486a68c46 100644 --- a/pkg/services/object/rangehash/remote.go +++ b/pkg/services/object/rangehash/remote.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/client" "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" ) @@ -15,6 +16,8 @@ type remoteHasher struct { keyStorage *util.KeyStorage node *network.Address + + clientCache *cache.ClientCache } func (h *remoteHasher) hashRange(ctx context.Context, prm *Prm, handler func([][]byte)) error { @@ -28,9 +31,7 @@ func (h *remoteHasher) hashRange(ctx context.Context, prm *Prm, handler func([][ return err } - c, err := client.New(key, - client.WithAddress(addr), - ) + c, err := h.clientCache.Get(key, addr) if err != nil { return errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr) } diff --git a/pkg/services/object/rangehash/service.go b/pkg/services/object/rangehash/service.go index df2052f019..a40dbb8eba 100644 --- a/pkg/services/object/rangehash/service.go +++ b/pkg/services/object/rangehash/service.go @@ -12,6 +12,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" rangesvc "github.com/nspcc-dev/neofs-node/pkg/services/object/range" objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" @@ -41,6 +42,8 @@ type cfg struct { headSvc *headsvc.Service rangeSvc *rangesvc.Service + + clientCache *cache.ClientCache } func defaultCfg() *cfg { @@ -264,3 +267,9 @@ func WithRangeService(v *rangesvc.Service) Option { c.rangeSvc = v } } + +func WithClientCache(v *cache.ClientCache) Option { + return func(c *cfg) { + c.clientCache = v + } +}