[#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

@ -362,6 +362,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
MorphClient: server.morphClient,
IRList: server,
ClientCache: clientCache,
Key: server.key,
RPCSearchTimeout: cfg.GetDuration("audit.timeout.search"),
TaskManager: auditTaskManager,
Reporter: server,

View file

@ -136,7 +136,7 @@ func (ap *Processor) findStorageGroups(cid *container.ID, shuffled netmap.Nodes)
sgSearchParams.WithSearchFilters(sgFilter)
ctx, cancel := context.WithTimeout(context.Background(), ap.searchTimeout)
result, err := cli.SearchObject(ctx, sgSearchParams)
result, err := cli.SearchObject(ctx, sgSearchParams, client.WithKey(ap.key))
cancel()
if err != nil {

View file

@ -2,6 +2,7 @@ package audit
import (
"context"
"crypto/ecdsa"
"time"
"github.com/nspcc-dev/neo-go/pkg/util"
@ -46,6 +47,7 @@ type (
morphClient *client.Client
irList Indexer
clientCache NeoFSClientCache
key *ecdsa.PrivateKey
searchTimeout time.Duration
containerClient *wrapContainer.Wrapper
@ -68,6 +70,7 @@ type (
RPCSearchTimeout time.Duration
TaskManager TaskManager
Reporter audit.Reporter
Key *ecdsa.PrivateKey
}
)
@ -97,6 +100,8 @@ func New(p *Params) (*Processor, error) {
return nil, errors.New("ir/audit: audit task manager is not set")
case p.Reporter == nil:
return nil, errors.New("ir/audit: audit result reporter is not set")
case p.Key == nil:
return nil, errors.New("ir/audit: signing key is not set")
}
pool, err := ants.NewPool(ProcessorPoolSize, ants.WithNonblocking(true))
@ -124,6 +129,7 @@ func New(p *Params) (*Processor, error) {
morphClient: p.MorphClient,
irList: p.IRList,
clientCache: p.ClientCache,
key: p.Key,
searchTimeout: p.RPCSearchTimeout,
containerClient: containerClient,
netmapClient: netmapClient,

View file

@ -47,7 +47,9 @@ func newClientCache(p *clientCacheParams) *ClientCache {
}
func (c *ClientCache) Get(address string, opts ...client.Option) (*client.Client, error) {
return c.cache.Get(c.key, address, opts...)
// Because cache is used by `ClientCache` exclusively,
// client will always have valid key.
return c.cache.Get(address, opts...)
}
// GetSG polls the container from audit task to get the object by id.
@ -89,7 +91,7 @@ func (c *ClientCache) getSG(ctx context.Context, addr *object.Address, nm *netma
}
cctx, cancel := context.WithTimeout(ctx, c.sgTimeout)
obj, err := cli.GetObject(cctx, getParams)
obj, err := cli.GetObject(cctx, getParams, client.WithKey(c.key))
cancel()
@ -143,7 +145,9 @@ func (c *ClientCache) GetHeader(task *audit.Task, node *netmap.Node, id *object.
}
cctx, cancel := context.WithTimeout(task.AuditContext(), c.headTimeout)
head, err := cli.GetObjectHeader(cctx, headParams, client.WithTTL(ttl))
head, err := cli.GetObjectHeader(cctx, headParams,
client.WithTTL(ttl),
client.WithKey(c.key))
cancel()
@ -177,7 +181,9 @@ func (c *ClientCache) GetRangeHash(task *audit.Task, node *netmap.Node, id *obje
}
cctx, cancel := context.WithTimeout(task.AuditContext(), c.rangeTimeout)
result, err := cli.ObjectPayloadRangeTZ(cctx, rangeParams, client.WithTTL(1))
result, err := cli.ObjectPayloadRangeTZ(cctx, rangeParams,
client.WithTTL(1),
client.WithKey(c.key))
cancel()