forked from TrueCloudLab/frostfs-node
[#645] *: Construct clients from client.NodeInfo in API client cache
There is a need to have the ability to expand the data needed for client construction. Replace `network.AddressGroup` parameter of client cache interfaces with `client.NodeInfo`. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
91cc33bdb9
commit
7b228b7603
25 changed files with 114 additions and 72 deletions
|
@ -3,6 +3,7 @@ package searchsvc
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -76,7 +77,11 @@ func (exec *execCtx) processCurrentEpoch() bool {
|
|||
}
|
||||
|
||||
// TODO: consider parallel execution
|
||||
exec.processNode(ctx, addrs[i].Addresses())
|
||||
var info client.NodeInfo
|
||||
|
||||
info.SetAddressGroup(addrs[i].Addresses())
|
||||
|
||||
exec.processNode(ctx, info)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
|
||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
"go.uber.org/zap"
|
||||
|
@ -117,8 +117,8 @@ func (exec *execCtx) generateTraverser(cid *cid.ID) (*placement.Traverser, bool)
|
|||
}
|
||||
}
|
||||
|
||||
func (exec execCtx) remoteClient(node network.AddressGroup) (searchClient, bool) {
|
||||
c, err := exec.svc.clientConstructor.get(node)
|
||||
func (exec execCtx) remoteClient(info client.NodeInfo) (searchClient, bool) {
|
||||
c, err := exec.svc.clientConstructor.get(info)
|
||||
switch {
|
||||
default:
|
||||
exec.status = statusUndefined
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||
)
|
||||
|
||||
|
@ -27,7 +26,7 @@ type IDListWriter interface {
|
|||
|
||||
// RequestForwarder is a callback for forwarding of the
|
||||
// original Search requests.
|
||||
type RequestForwarder func(network.AddressGroup, coreclient.Client) ([]*objectSDK.ID, error)
|
||||
type RequestForwarder func(coreclient.NodeInfo, coreclient.Client) ([]*objectSDK.ID, error)
|
||||
|
||||
// SetCommonParameters sets common parameters of the operation.
|
||||
func (p *Prm) SetCommonParameters(common *util.CommonPrm) {
|
||||
|
|
|
@ -3,19 +3,19 @@ package searchsvc
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (exec *execCtx) processNode(ctx context.Context, addr network.AddressGroup) {
|
||||
func (exec *execCtx) processNode(ctx context.Context, info client.NodeInfo) {
|
||||
exec.log.Debug("processing node...")
|
||||
|
||||
client, ok := exec.remoteClient(addr)
|
||||
client, ok := exec.remoteClient(info)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
ids, err := client.searchObjects(exec, addr)
|
||||
ids, err := client.searchObjects(exec, info)
|
||||
|
||||
if err != nil {
|
||||
exec.log.Debug("local operation failed",
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
||||
|
@ -84,8 +85,8 @@ func (p *testPlacementBuilder) BuildPlacement(addr *objectSDK.Address, _ *netmap
|
|||
return res, nil
|
||||
}
|
||||
|
||||
func (c *testClientCache) get(mAddr network.AddressGroup) (searchClient, error) {
|
||||
v, ok := c.clients[network.StringifyGroup(mAddr)]
|
||||
func (c *testClientCache) get(info clientcore.NodeInfo) (searchClient, error) {
|
||||
v, ok := c.clients[network.StringifyGroup(info.AddressGroup())]
|
||||
if !ok {
|
||||
return nil, errors.New("could not construct client")
|
||||
}
|
||||
|
@ -102,7 +103,7 @@ func (s *testStorage) search(exec *execCtx) ([]*objectSDK.ID, error) {
|
|||
return v.ids, v.err
|
||||
}
|
||||
|
||||
func (c *testStorage) searchObjects(exec *execCtx, _ network.AddressGroup) ([]*objectSDK.ID, error) {
|
||||
func (c *testStorage) searchObjects(exec *execCtx, _ clientcore.NodeInfo) ([]*objectSDK.ID, error) {
|
||||
v, ok := c.items[exec.containerID().String()]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
|
@ -23,11 +22,11 @@ type Service struct {
|
|||
type Option func(*cfg)
|
||||
|
||||
type searchClient interface {
|
||||
searchObjects(*execCtx, network.AddressGroup) ([]*object.ID, error)
|
||||
searchObjects(*execCtx, client.NodeInfo) ([]*object.ID, error)
|
||||
}
|
||||
|
||||
type ClientConstructor interface {
|
||||
Get(network.AddressGroup) (client.Client, error)
|
||||
Get(client.NodeInfo) (client.Client, error)
|
||||
}
|
||||
|
||||
type cfg struct {
|
||||
|
@ -38,7 +37,7 @@ type cfg struct {
|
|||
}
|
||||
|
||||
clientConstructor interface {
|
||||
get(network.AddressGroup) (searchClient, error)
|
||||
get(client.NodeInfo) (searchClient, error)
|
||||
}
|
||||
|
||||
traverserGenerator interface {
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
||||
)
|
||||
|
@ -68,17 +67,20 @@ func (w *uniqueIDWriter) WriteIDs(list []*objectSDK.ID) error {
|
|||
return w.writer.WriteIDs(list)
|
||||
}
|
||||
|
||||
func (c *clientConstructorWrapper) get(addr network.AddressGroup) (searchClient, error) {
|
||||
clt, err := c.constructor.Get(addr)
|
||||
func (c *clientConstructorWrapper) get(info client.NodeInfo) (searchClient, error) {
|
||||
clt, err := c.constructor.Get(info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &clientWrapper{
|
||||
client: clt,
|
||||
}, err
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *clientWrapper) searchObjects(exec *execCtx, addr network.AddressGroup) ([]*objectSDK.ID, error) {
|
||||
func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]*objectSDK.ID, error) {
|
||||
if exec.prm.forwarder != nil {
|
||||
return exec.prm.forwarder(addr, c.client)
|
||||
return exec.prm.forwarder(info, c.client)
|
||||
}
|
||||
|
||||
return c.client.SearchObject(exec.context(),
|
||||
|
|
|
@ -112,13 +112,13 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre
|
|||
}
|
||||
|
||||
func groupAddressRequestForwarder(f func(network.Address, client.Client) ([]*objectSDK.ID, error)) searchsvc.RequestForwarder {
|
||||
return func(addrGroup network.AddressGroup, c client.Client) ([]*objectSDK.ID, error) {
|
||||
return func(info client.NodeInfo, c client.Client) ([]*objectSDK.ID, error) {
|
||||
var (
|
||||
firstErr error
|
||||
res []*objectSDK.ID
|
||||
)
|
||||
|
||||
addrGroup.IterateAddresses(func(addr network.Address) (stop bool) {
|
||||
info.AddressGroup().IterateAddresses(func(addr network.Address) (stop bool) {
|
||||
var err error
|
||||
|
||||
defer func() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue