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

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

View file

@ -294,6 +294,7 @@ func initObjectService(c *cfg) {
sRange := rangesvc.NewService( sRange := rangesvc.NewService(
rangesvc.WithKeyStorage(keyStorage), rangesvc.WithKeyStorage(keyStorage),
rangesvc.WithClientCache(clientCache),
rangesvc.WithLocalStorage(ls), rangesvc.WithLocalStorage(ls),
rangesvc.WithContainerSource(c.cfgObject.cnrStorage), rangesvc.WithContainerSource(c.cfgObject.cnrStorage),
rangesvc.WithNetworkMapSource(c.cfgObject.netMapStorage), rangesvc.WithNetworkMapSource(c.cfgObject.netMapStorage),

View file

@ -8,6 +8,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-api-go/pkg/token" "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"
"github.com/nspcc-dev/neofs-node/pkg/network/cache"
"github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -26,6 +27,8 @@ type remoteRangeWriter struct {
addr *object.Address addr *object.Address
rng *object.Range rng *object.Range
clientCache *cache.ClientCache
} }
func (r *remoteRangeWriter) WriteTo(w io.Writer) (int64, error) { 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 return 0, err
} }
c, err := client.New(key, c, err := r.clientCache.Get(key, addr)
client.WithAddress(addr),
)
if err != nil { if err != nil {
return 0, errors.Wrapf(err, "(%T) could not create SDK client %s", r, addr) return 0, errors.Wrapf(err, "(%T) could not create SDK client %s", r, addr)
} }

View file

@ -9,6 +9,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/core/netmap" "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/local_object_storage/localstore"
"github.com/nspcc-dev/neofs-node/pkg/network" "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" headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head"
objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
"github.com/nspcc-dev/neofs-node/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/util"
@ -35,6 +36,8 @@ type cfg struct {
localAddrSrc network.LocalAddressSource localAddrSrc network.LocalAddressSource
headSvc *headsvc.Service headSvc *headsvc.Service
clientCache *cache.ClientCache
} }
func defaultCfg() *cfg { func defaultCfg() *cfg {
@ -164,3 +167,9 @@ func WithHeadService(v *headsvc.Service) Option {
c.headSvc = v c.headSvc = v
} }
} }
func WithClientCache(v *cache.ClientCache) Option {
return func(c *cfg) {
c.clientCache = v
}
}

View file

@ -185,6 +185,7 @@ loop:
bearer: p.prm.common.BearerToken(), bearer: p.prm.common.BearerToken(),
addr: objAddr, addr: objAddr,
rng: nextRange, rng: nextRange,
clientCache: p.clientCache,
} }
} }