[#184] Use SDK client cache in object.Rangehash

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-11-18 16:04:59 +03:00 committed by Alex Vanin
parent f85e88c4f8
commit e8fe07edd0
4 changed files with 17 additions and 5 deletions

View file

@ -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),

View file

@ -114,6 +114,7 @@ loop:
hasher = &remoteHasher{
keyStorage: h.keyStorage,
node: addr,
clientCache: h.clientCache,
}
}

View file

@ -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)
}

View file

@ -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
}
}