[#422] pkg/services: Cache clients by address only

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-03-13 18:22:21 +03:00 committed by Leonard Lyubich
parent 55dec28bbb
commit cc7287d6f7
19 changed files with 55 additions and 68 deletions

View file

@ -111,7 +111,7 @@ func (exec execCtx) key() *ecdsa.PrivateKey {
func (exec execCtx) callOptions() []client.CallOption {
return exec.prm.common.RemoteCallOptions(
util.WithNetmapEpoch(exec.curProcEpoch),
)
util.WithKey(exec.key()))
}
func (exec execCtx) remotePrm() *client.GetObjectParams {
@ -276,7 +276,7 @@ func (exec execCtx) remoteClient(node *network.Address) (getClient, bool) {
log.Debug("could not calculate node IP address")
case err == nil:
c, err := exec.svc.clientCache.get(exec.key(), ipAddr)
c, err := exec.svc.clientCache.get(ipAddr)
switch {
default:

View file

@ -2,7 +2,6 @@ package getsvc
import (
"context"
"crypto/ecdsa"
"crypto/rand"
"crypto/sha256"
"fmt"
@ -81,7 +80,7 @@ func (p *testPlacementBuilder) BuildPlacement(addr *objectSDK.Address, _ *netmap
return vs, nil
}
func (c *testClientCache) get(_ *ecdsa.PrivateKey, addr string) (getClient, error) {
func (c *testClientCache) get(addr string) (getClient, error) {
v, ok := c.clients[addr]
if !ok {
return nil, errors.New("could not construct client")

View file

@ -1,8 +1,6 @@
package getsvc
import (
"crypto/ecdsa"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
@ -37,7 +35,7 @@ type cfg struct {
}
clientCache interface {
get(*ecdsa.PrivateKey, string) (getClient, error)
get(string) (getClient, error)
}
traverserGenerator interface {

View file

@ -1,7 +1,6 @@
package getsvc
import (
"crypto/ecdsa"
"io"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
@ -75,8 +74,8 @@ func (s *SimpleObjectWriter) Object() *object.Object {
return s.obj.Object()
}
func (c *clientCacheWrapper) get(key *ecdsa.PrivateKey, addr string) (getClient, error) {
clt, err := c.cache.Get(key, addr, c.opts...)
func (c *clientCacheWrapper) get(addr string) (getClient, error) {
clt, err := c.cache.Get(addr, c.opts...)
return &clientWrapper{
client: clt,

View file

@ -70,7 +70,7 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob
return nil, err
}
c, err := h.clientCache.Get(key, addr, h.clientOpts...)
c, err := h.clientCache.Get(addr, h.clientOpts...)
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr)
}
@ -87,6 +87,7 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob
client.WithTTL(1), // FIXME: use constant
client.WithSession(prm.commonHeadPrm.common.SessionToken()),
client.WithBearer(prm.commonHeadPrm.common.BearerToken()),
client.WithKey(key),
)
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not head object in %s", h, addr)

View file

@ -64,7 +64,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
return nil, err
}
c, err := t.clientCache.Get(key, addr, t.clientOpts...)
c, err := t.clientCache.Get(addr, t.clientOpts...)
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", t, addr)
}
@ -76,6 +76,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
append(
t.commonPrm.RemoteCallOptions(),
client.WithTTL(1), // FIXME: use constant
client.WithKey(key),
)...,
)
if err != nil {

View file

@ -69,6 +69,7 @@ func (exec execCtx) key() *ecdsa.PrivateKey {
func (exec execCtx) callOptions() []client.CallOption {
return exec.prm.common.RemoteCallOptions(
util.WithNetmapEpoch(exec.curProcEpoch),
util.WithKey(exec.key()),
)
}
@ -146,7 +147,7 @@ func (exec execCtx) remoteClient(node *network.Address) (searchClient, bool) {
log.Debug("could not calculate node IP address")
case err == nil:
c, err := exec.svc.clientCache.get(exec.key(), ipAddr)
c, err := exec.svc.clientCache.get(ipAddr)
switch {
default:

View file

@ -2,7 +2,6 @@ package searchsvc
import (
"context"
"crypto/ecdsa"
"crypto/rand"
"crypto/sha256"
"fmt"
@ -83,7 +82,7 @@ func (p *testPlacementBuilder) BuildPlacement(addr *objectSDK.Address, _ *netmap
return res, nil
}
func (c *testClientCache) get(_ *ecdsa.PrivateKey, addr string) (searchClient, error) {
func (c *testClientCache) get(addr string) (searchClient, error) {
v, ok := c.clients[addr]
if !ok {
return nil, errors.New("could not construct client")

View file

@ -1,8 +1,6 @@
package searchsvc
import (
"crypto/ecdsa"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/container"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
@ -36,7 +34,7 @@ type cfg struct {
}
clientCache interface {
get(*ecdsa.PrivateKey, string) (searchClient, error)
get(string) (searchClient, error)
}
traverserGenerator interface {

View file

@ -1,7 +1,6 @@
package searchsvc
import (
"crypto/ecdsa"
"sync"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
@ -71,8 +70,8 @@ func (w *uniqueIDWriter) WriteIDs(list []*objectSDK.ID) error {
return w.writer.WriteIDs(list)
}
func (c *clientCacheWrapper) get(key *ecdsa.PrivateKey, addr string) (searchClient, error) {
clt, err := c.cache.Get(key, addr, c.opts...)
func (c *clientCacheWrapper) get(addr string) (searchClient, error) {
clt, err := c.cache.Get(addr, c.opts...)
return &clientWrapper{
client: clt,

View file

@ -116,6 +116,13 @@ func WithNetmapEpoch(v uint64) DynamicCallOption {
}
}
// WithKey sets key to use for the request.
func WithKey(key *ecdsa.PrivateKey) DynamicCallOption {
return func(o *remoteCallOpts) {
o.opts = append(o.opts, client.WithKey(key))
}
}
func (p *CommonPrm) SessionToken() *token.SessionToken {
if p != nil {
return p.token