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

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

View file

@ -200,7 +200,7 @@ func initObjectService(c *cfg) {
), ),
replicator.WithLocalStorage(ls), replicator.WithLocalStorage(ls),
replicator.WithRemoteSender( replicator.WithRemoteSender(
putsvc.NewRemoteSender(keyStorage), putsvc.NewRemoteSender(keyStorage, clientCache),
), ),
) )
@ -246,6 +246,7 @@ func initObjectService(c *cfg) {
sPut := putsvc.NewService( sPut := putsvc.NewService(
putsvc.WithKeyStorage(keyStorage), putsvc.WithKeyStorage(keyStorage),
putsvc.WithClientCache(clientCache),
putsvc.WithMaxSizeSource(c), putsvc.WithMaxSizeSource(c),
putsvc.WithLocalStorage(ls), putsvc.WithLocalStorage(ls),
putsvc.WithContainerSource(c.cfgObject.cnrStorage), putsvc.WithContainerSource(c.cfgObject.cnrStorage),

View file

@ -7,6 +7,7 @@ import (
"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/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/nspcc-dev/neofs-node/pkg/services/object_manager/transformer" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -26,12 +27,15 @@ type remoteTarget struct {
addr *network.Address addr *network.Address
obj *object.Object obj *object.Object
clientCache *cache.ClientCache
} }
// RemoteSender represents utility for // RemoteSender represents utility for
// sending an object to a remote host. // sending an object to a remote host.
type RemoteSender struct { type RemoteSender struct {
keyStorage *util.KeyStorage keyStorage *util.KeyStorage
clientCache *cache.ClientCache
} }
// RemotePutPrm groups remote put operation parameters. // RemotePutPrm groups remote put operation parameters.
@ -58,9 +62,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
return nil, err return nil, err
} }
c, err := client.New(key, c, err := t.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", t, addr) return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", t, addr)
} }
@ -81,9 +83,10 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
} }
// NewRemoteSender creates, initializes and returns new RemoteSender instance. // NewRemoteSender creates, initializes and returns new RemoteSender instance.
func NewRemoteSender(keyStorage *util.KeyStorage) *RemoteSender { func NewRemoteSender(keyStorage *util.KeyStorage, cache *cache.ClientCache) *RemoteSender {
return &RemoteSender{ return &RemoteSender{
keyStorage: keyStorage, keyStorage: keyStorage,
clientCache: cache,
} }
} }
@ -111,6 +114,7 @@ func (s *RemoteSender) PutObject(ctx context.Context, p *RemotePutPrm) error {
ctx: ctx, ctx: ctx,
keyStorage: s.keyStorage, keyStorage: s.keyStorage,
addr: p.node, addr: p.node,
clientCache: s.clientCache,
} }
if err := t.WriteHeader(object.NewRawFromObject(p.obj)); err != nil { if err := t.WriteHeader(object.NewRawFromObject(p.obj)); err != nil {

View file

@ -8,6 +8,7 @@ import (
"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/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"
) )
@ -46,6 +47,8 @@ type cfg struct {
fmtValidatorOpts []object.FormatValidatorOption fmtValidatorOpts []object.FormatValidatorOption
networkState netmap.State networkState netmap.State
clientCache *cache.ClientCache
} }
func defaultCfg() *cfg { func defaultCfg() *cfg {
@ -128,3 +131,9 @@ func WithNetworkState(v netmap.State) Option {
c.networkState = v c.networkState = v
} }
} }
func WithClientCache(v *cache.ClientCache) Option {
return func(c *cfg) {
c.clientCache = v
}
}

View file

@ -143,6 +143,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget {
token: prm.common.SessionToken(), token: prm.common.SessionToken(),
bearer: prm.common.BearerToken(), bearer: prm.common.BearerToken(),
addr: addr, addr: addr,
clientCache: p.clientCache,
} }
} }
}, },