From e9a6365333ffa99a6187133a33140c026a7f03fe Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 18 Nov 2020 16:03:00 +0300 Subject: [PATCH] [#184] Use SDK client cache in object.Head Signed-off-by: Alex Vanin --- cmd/neofs-node/object.go | 6 +++++- pkg/services/object/head/remote.go | 12 +++++++----- pkg/services/object/head/service.go | 7 +++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 2c52e2f7..70b12bfa 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -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/localstore" "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" objectService "github.com/nspcc-dev/neofs-node/pkg/services/object" "github.com/nspcc-dev/neofs-node/pkg/services/object/acl" @@ -180,6 +181,8 @@ func initObjectService(c *cfg) { nodeOwner.SetNeo3Wallet(neo3Wallet) + clientCache := cache.NewSDKClientCache() + objGC := gc.New( gc.WithLogger(c.log), gc.WithRemover(ls), @@ -220,7 +223,7 @@ func initObjectService(c *cfg) { ), policer.WithTrigger(ch), policer.WithRemoteHeader( - headsvc.NewRemoteHeader(keyStorage), + headsvc.NewRemoteHeader(keyStorage, clientCache), ), policer.WithLocalAddressSource(c), policer.WithHeadTimeout( @@ -274,6 +277,7 @@ func initObjectService(c *cfg) { sHead := headsvc.NewService( headsvc.WithKeyStorage(keyStorage), + headsvc.WithClientCache(clientCache), headsvc.WithLocalStorage(ls), headsvc.WithContainerSource(c.cfgObject.cnrStorage), headsvc.WithNetworkMapSource(c.cfgObject.netMapStorage), diff --git a/pkg/services/object/head/remote.go b/pkg/services/object/head/remote.go index 67343f0f..b1ed7c2b 100644 --- a/pkg/services/object/head/remote.go +++ b/pkg/services/object/head/remote.go @@ -7,6 +7,7 @@ import ( 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/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 @@ import ( // the object header from a remote host. type RemoteHeader struct { keyStorage *util.KeyStorage + + clientCache *cache.ClientCache } // RemoteHeadPrm groups remote header operation parameters. @@ -25,9 +28,10 @@ type RemoteHeadPrm struct { } // 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{ - keyStorage: keyStorage, + keyStorage: keyStorage, + clientCache: cache, } } @@ -61,9 +65,7 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob return nil, err } - c, err := client.New(key, - client.WithAddress(addr), - ) + c, err := h.clientCache.Get(key, addr) if err != nil { return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr) } diff --git a/pkg/services/object/head/service.go b/pkg/services/object/head/service.go index eeb1a3e2..1c86aaa9 100644 --- a/pkg/services/object/head/service.go +++ b/pkg/services/object/head/service.go @@ -8,6 +8,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" objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/util" "github.com/pkg/errors" @@ -134,3 +135,9 @@ func WithRightChildSearcher(v RelationSearcher) Option { c.rightChildSearcher = v } } + +func WithClientCache(v *cache.ClientCache) Option { + return func(c *cfg) { + c.remoteHeader.clientCache = v + } +}