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

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

View file

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

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "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"
"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"
) )
@ -16,6 +17,8 @@ type remoteStream struct {
keyStorage *util.KeyStorage keyStorage *util.KeyStorage
addr *network.Address addr *network.Address
clientCache *cache.ClientCache
} }
func (s *remoteStream) stream(ctx context.Context, ch chan<- []*object.ID) error { 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 return err
} }
c, err := client.New(key, c, err := s.clientCache.Get(key, addr)
client.WithAddress(addr),
)
if err != nil { if err != nil {
return errors.Wrapf(err, "(%T) could not create SDK client %s", s, addr) return errors.Wrapf(err, "(%T) could not create SDK client %s", s, 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"
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"
) )
@ -31,6 +32,8 @@ type cfg struct {
workerPool util.WorkerPool workerPool util.WorkerPool
localAddrSrc network.LocalAddressSource localAddrSrc network.LocalAddressSource
clientCache *cache.ClientCache
} }
func defaultCfg() *cfg { func defaultCfg() *cfg {
@ -96,3 +99,9 @@ func WithLocalAddressSource(v network.LocalAddressSource) Option {
c.localAddrSrc = v c.localAddrSrc = v
} }
} }
func WithClientCache(v *cache.ClientCache) Option {
return func(c *cfg) {
c.clientCache = v
}
}

View file

@ -164,6 +164,7 @@ loop:
prm: prm, prm: prm,
keyStorage: p.keyStorage, keyStorage: p.keyStorage,
addr: addr, addr: addr,
clientCache: p.clientCache,
} }
} }