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

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-11-18 16:03:00 +03:00 committed by Alex Vanin
parent fb90827532
commit e9a6365333
3 changed files with 19 additions and 6 deletions

View file

@ -13,6 +13,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/bucket" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/bucket"
"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/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/network/cache"
objectTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/object/grpc" objectTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/object/grpc"
objectService "github.com/nspcc-dev/neofs-node/pkg/services/object" objectService "github.com/nspcc-dev/neofs-node/pkg/services/object"
"github.com/nspcc-dev/neofs-node/pkg/services/object/acl" "github.com/nspcc-dev/neofs-node/pkg/services/object/acl"
@ -180,6 +181,8 @@ func initObjectService(c *cfg) {
nodeOwner.SetNeo3Wallet(neo3Wallet) nodeOwner.SetNeo3Wallet(neo3Wallet)
clientCache := cache.NewSDKClientCache()
objGC := gc.New( objGC := gc.New(
gc.WithLogger(c.log), gc.WithLogger(c.log),
gc.WithRemover(ls), gc.WithRemover(ls),
@ -220,7 +223,7 @@ func initObjectService(c *cfg) {
), ),
policer.WithTrigger(ch), policer.WithTrigger(ch),
policer.WithRemoteHeader( policer.WithRemoteHeader(
headsvc.NewRemoteHeader(keyStorage), headsvc.NewRemoteHeader(keyStorage, clientCache),
), ),
policer.WithLocalAddressSource(c), policer.WithLocalAddressSource(c),
policer.WithHeadTimeout( policer.WithHeadTimeout(
@ -274,6 +277,7 @@ func initObjectService(c *cfg) {
sHead := headsvc.NewService( sHead := headsvc.NewService(
headsvc.WithKeyStorage(keyStorage), headsvc.WithKeyStorage(keyStorage),
headsvc.WithClientCache(clientCache),
headsvc.WithLocalStorage(ls), headsvc.WithLocalStorage(ls),
headsvc.WithContainerSource(c.cfgObject.cnrStorage), headsvc.WithContainerSource(c.cfgObject.cnrStorage),
headsvc.WithNetworkMapSource(c.cfgObject.netMapStorage), headsvc.WithNetworkMapSource(c.cfgObject.netMapStorage),

View file

@ -7,6 +7,7 @@ import (
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/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"
) )
@ -15,6 +16,8 @@ import (
// the object header from a remote host. // the object header from a remote host.
type RemoteHeader struct { type RemoteHeader struct {
keyStorage *util.KeyStorage keyStorage *util.KeyStorage
clientCache *cache.ClientCache
} }
// RemoteHeadPrm groups remote header operation parameters. // RemoteHeadPrm groups remote header operation parameters.
@ -25,9 +28,10 @@ type RemoteHeadPrm struct {
} }
// NewRemoteHeader creates, initializes and returns new RemoteHeader instance. // NewRemoteHeader creates, initializes and returns new RemoteHeader instance.
func NewRemoteHeader(keyStorage *util.KeyStorage) *RemoteHeader { func NewRemoteHeader(keyStorage *util.KeyStorage, cache *cache.ClientCache) *RemoteHeader {
return &RemoteHeader{ return &RemoteHeader{
keyStorage: keyStorage, keyStorage: keyStorage,
clientCache: cache,
} }
} }
@ -61,9 +65,7 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob
return nil, err return nil, err
} }
c, err := client.New(key, c, err := h.clientCache.Get(key, addr)
client.WithAddress(addr),
)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr) return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr)
} }

View file

@ -8,6 +8,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"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -134,3 +135,9 @@ func WithRightChildSearcher(v RelationSearcher) Option {
c.rightChildSearcher = v c.rightChildSearcher = v
} }
} }
func WithClientCache(v *cache.ClientCache) Option {
return func(c *cfg) {
c.remoteHeader.clientCache = v
}
}