From 7b228b7603d6a54caf6a4c5c1e63698f54cd893c Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 28 Sep 2021 07:46:10 +0300 Subject: [PATCH] [#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 --- cmd/neofs-node/container.go | 9 +++++++-- cmd/neofs-node/object.go | 12 +++++++----- cmd/neofs-node/reputation/common/remote.go | 9 +++++++-- pkg/innerring/rpc.go | 14 ++++++++------ pkg/network/cache/client.go | 5 ++++- pkg/services/object/get/container.go | 7 ++++++- pkg/services/object/get/exec.go | 6 +++--- pkg/services/object/get/get_test.go | 7 ++++--- pkg/services/object/get/prm.go | 3 +-- pkg/services/object/get/remote.go | 8 ++++---- pkg/services/object/get/service.go | 7 +++---- pkg/services/object/get/util.go | 14 ++++++++------ pkg/services/object/get/v2/util.go | 4 ++-- pkg/services/object/head/remote.go | 9 +++++++-- pkg/services/object/put/remote.go | 7 ++++++- pkg/services/object/put/service.go | 3 +-- pkg/services/object/put/streamer.go | 6 +++++- pkg/services/object/search/container.go | 7 ++++++- pkg/services/object/search/exec.go | 6 +++--- pkg/services/object/search/prm.go | 3 +-- pkg/services/object/search/remote.go | 8 ++++---- pkg/services/object/search/search_test.go | 7 ++++--- pkg/services/object/search/service.go | 7 +++---- pkg/services/object/search/util.go | 14 ++++++++------ pkg/services/object/search/v2/util.go | 4 ++-- 25 files changed, 114 insertions(+), 72 deletions(-) diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index d5c2057df..0114af533 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -16,6 +16,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/owner" containerV2 "github.com/nspcc-dev/neofs-api-go/v2/container" containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container/grpc" + "github.com/nspcc-dev/neofs-node/pkg/core/client" containerCore "github.com/nspcc-dev/neofs-node/pkg/core/container" netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" @@ -244,7 +245,7 @@ type remoteLoadAnnounceProvider struct { netmapKeys netmapCore.AnnouncedKeys clientCache interface { - Get(network.AddressGroup) (apiClient.Client, error) + Get(client.NodeInfo) (apiClient.Client, error) } deadEndProvider loadcontroller.WriterProvider @@ -267,7 +268,11 @@ func (r *remoteLoadAnnounceProvider) InitRemote(srv loadroute.ServerInfo) (loadc return nil, fmt.Errorf("could not convert address to IP format: %w", err) } - c, err := r.clientCache.Get(netAddr) + var info client.NodeInfo + + info.SetAddressGroup(netAddr) + + c, err := r.clientCache.Get(info) if err != nil { return nil, fmt.Errorf("could not initialize API client: %w", err) } diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 8c5b272ea..9ddd66a96 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -166,8 +166,8 @@ func (f *innerRingFetcherWithoutNotary) InnerRingKeys() ([][]byte, error) { type coreClientConstructor reputationClientConstructor -func (x *coreClientConstructor) Get(addrGroup network.AddressGroup) (coreclient.Client, error) { - c, err := (*reputationClientConstructor)(x).Get(addrGroup) +func (x *coreClientConstructor) Get(info coreclient.NodeInfo) (coreclient.Client, error) { + c, err := (*reputationClientConstructor)(x).Get(info) if err != nil { return nil, err } @@ -442,7 +442,7 @@ type reputationClientConstructor struct { trustStorage *truststorage.Storage basicConstructor interface { - Get(network.AddressGroup) (client.Client, error) + Get(coreclient.NodeInfo) (client.Client, error) } } @@ -526,14 +526,16 @@ func (c *reputationClient) SearchObject(ctx context.Context, prm *client.SearchO return ids, err } -func (c *reputationClientConstructor) Get(addr network.AddressGroup) (client.Client, error) { - cl, err := c.basicConstructor.Get(addr) +func (c *reputationClientConstructor) Get(info coreclient.NodeInfo) (client.Client, error) { + cl, err := c.basicConstructor.Get(info) if err != nil { return nil, err } nm, err := netmap.GetLatestNetworkMap(c.nmSrc) if err == nil { + addr := info.AddressGroup() + for i := range nm.Nodes { var netAddr network.AddressGroup diff --git a/cmd/neofs-node/reputation/common/remote.go b/cmd/neofs-node/reputation/common/remote.go index ecd2aaaaf..b1ddd49ac 100644 --- a/cmd/neofs-node/reputation/common/remote.go +++ b/cmd/neofs-node/reputation/common/remote.go @@ -4,6 +4,7 @@ import ( "fmt" apiClient "github.com/nspcc-dev/neofs-api-go/pkg/client" + "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/network" reputationcommon "github.com/nspcc-dev/neofs-node/pkg/services/reputation/common" @@ -12,7 +13,7 @@ import ( ) type clientCache interface { - Get(network.AddressGroup) (apiClient.Client, error) + Get(client.NodeInfo) (apiClient.Client, error) } // clientKeyRemoteProvider must provide remote writer and take into account @@ -83,7 +84,11 @@ func (rtp *remoteTrustProvider) InitRemote(srv reputationcommon.ServerInfo) (rep return nil, fmt.Errorf("could not convert address to IP format: %w", err) } - c, err := rtp.clientCache.Get(netAddr) + var info client.NodeInfo + + info.SetAddressGroup(netAddr) + + c, err := rtp.clientCache.Get(info) if err != nil { return nil, fmt.Errorf("could not initialize API client: %w", err) } diff --git a/pkg/innerring/rpc.go b/pkg/innerring/rpc.go index e78c2b1e5..68f3742e0 100644 --- a/pkg/innerring/rpc.go +++ b/pkg/innerring/rpc.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/storagegroup" + clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client" coreObject "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" @@ -22,11 +23,8 @@ import ( type ( ClientCache struct { log *zap.Logger - cache interface { - Get(address network.AddressGroup) (client.Client, error) - CloseAll() - } - key *ecdsa.PrivateKey + cache *cache.ClientCache + key *ecdsa.PrivateKey sgTimeout, headTimeout, rangeTimeout time.Duration } @@ -51,9 +49,13 @@ func newClientCache(p *clientCacheParams) *ClientCache { } func (c *ClientCache) Get(address network.AddressGroup) (client.Client, error) { + var info clientcore.NodeInfo + + info.SetAddressGroup(address) + // Because cache is used by `ClientCache` exclusively, // client will always have valid key. - return c.cache.Get(address) + return c.cache.Get(info) } // GetSG polls the container from audit task to get the object by id. diff --git a/pkg/network/cache/client.go b/pkg/network/cache/client.go index 0ce87dac6..44f4c9ebf 100644 --- a/pkg/network/cache/client.go +++ b/pkg/network/cache/client.go @@ -4,6 +4,7 @@ import ( "sync" "github.com/nspcc-dev/neofs-api-go/pkg/client" + clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client" "github.com/nspcc-dev/neofs-node/pkg/network" ) @@ -28,7 +29,9 @@ func NewSDKClientCache(opts ...client.Option) *ClientCache { } // Get function returns existing client or creates a new one. -func (c *ClientCache) Get(netAddr network.AddressGroup) (client.Client, error) { +func (c *ClientCache) Get(info clientcore.NodeInfo) (client.Client, error) { + netAddr := info.AddressGroup() + // multiaddr is used as a key in client cache since // same host may have different connections(with tls or not), // therefore, host+port pair is not unique diff --git a/pkg/services/object/get/container.go b/pkg/services/object/get/container.go index c5de3dba2..6381bdb7c 100644 --- a/pkg/services/object/get/container.go +++ b/pkg/services/object/get/container.go @@ -3,6 +3,7 @@ package getsvc import ( "context" + "github.com/nspcc-dev/neofs-node/pkg/core/client" "go.uber.org/zap" ) @@ -78,7 +79,11 @@ func (exec *execCtx) processCurrentEpoch() bool { // TODO: consider parallel execution // TODO: consider optimization: if status == SPLIT we can continue until // we reach the best result - split info with linking object ID. - if exec.processNode(ctx, addrs[i].Addresses()) { + var info client.NodeInfo + + info.SetAddressGroup(addrs[i].Addresses()) + + if exec.processNode(ctx, info) { exec.log.Debug("completing the operation") return true } diff --git a/pkg/services/object/get/exec.go b/pkg/services/object/get/exec.go index ac08dc58d..f63fb906f 100644 --- a/pkg/services/object/get/exec.go +++ b/pkg/services/object/get/exec.go @@ -8,8 +8,8 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/client" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" 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/core/object" - "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" @@ -264,8 +264,8 @@ func (exec *execCtx) headChild(id *objectSDK.ID) (*object.Object, bool) { } } -func (exec execCtx) remoteClient(node network.AddressGroup) (getClient, bool) { - c, err := exec.svc.clientCache.get(node) +func (exec execCtx) remoteClient(info clientcore.NodeInfo) (getClient, bool) { + c, err := exec.svc.clientCache.get(info) switch { default: diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index 8708777e6..abfd16435 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -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" + "github.com/nspcc-dev/neofs-node/pkg/core/client" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" @@ -82,8 +83,8 @@ func (p *testPlacementBuilder) BuildPlacement(addr *objectSDK.Address, _ *netmap return vs, nil } -func (c *testClientCache) get(mAddr network.AddressGroup) (getClient, error) { - v, ok := c.clients[network.StringifyGroup(mAddr)] +func (c *testClientCache) get(info client.NodeInfo) (getClient, error) { + v, ok := c.clients[network.StringifyGroup(info.AddressGroup())] if !ok { return nil, errors.New("could not construct client") } @@ -100,7 +101,7 @@ func newTestClient() *testClient { } } -func (c *testClient) getObject(exec *execCtx, _ network.AddressGroup) (*objectSDK.Object, error) { +func (c *testClient) getObject(exec *execCtx, _ client.NodeInfo) (*objectSDK.Object, error) { v, ok := c.results[exec.address().String()] if !ok { return nil, object.ErrNotFound diff --git a/pkg/services/object/get/prm.go b/pkg/services/object/get/prm.go index 2caa48bf4..10c53d5c7 100644 --- a/pkg/services/object/get/prm.go +++ b/pkg/services/object/get/prm.go @@ -7,7 +7,6 @@ import ( 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/core/object" - "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" ) @@ -34,7 +33,7 @@ type RangeHashPrm struct { salt []byte } -type RequestForwarder func(network.AddressGroup, coreclient.Client) (*objectSDK.Object, error) +type RequestForwarder func(coreclient.NodeInfo, coreclient.Client) (*objectSDK.Object, error) // HeadPrm groups parameters of Head service call. type HeadPrm struct { diff --git a/pkg/services/object/get/remote.go b/pkg/services/object/get/remote.go index 269771059..458cbb5b2 100644 --- a/pkg/services/object/get/remote.go +++ b/pkg/services/object/get/remote.go @@ -5,20 +5,20 @@ import ( "errors" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/nspcc-dev/neofs-node/pkg/core/client" "github.com/nspcc-dev/neofs-node/pkg/core/object" - "github.com/nspcc-dev/neofs-node/pkg/network" "go.uber.org/zap" ) -func (exec *execCtx) processNode(ctx context.Context, addr network.AddressGroup) bool { +func (exec *execCtx) processNode(ctx context.Context, info client.NodeInfo) bool { exec.log.Debug("processing node...") - client, ok := exec.remoteClient(addr) + client, ok := exec.remoteClient(info) if !ok { return true } - obj, err := client.getObject(exec, addr) + obj, err := client.getObject(exec, info) var errSplitInfo *objectSDK.SplitInfoError diff --git a/pkg/services/object/get/service.go b/pkg/services/object/get/service.go index 8d23db48d..d17d60d41 100644 --- a/pkg/services/object/get/service.go +++ b/pkg/services/object/get/service.go @@ -6,7 +6,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/object" "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" @@ -22,7 +21,7 @@ type Service struct { type Option func(*cfg) type getClient interface { - getObject(*execCtx, network.AddressGroup) (*objectSDK.Object, error) + getObject(*execCtx, client.NodeInfo) (*objectSDK.Object, error) } type cfg struct { @@ -35,7 +34,7 @@ type cfg struct { } clientCache interface { - get(network.AddressGroup) (getClient, error) + get(client.NodeInfo) (getClient, error) } traverserGenerator interface { @@ -93,7 +92,7 @@ func WithLocalStorageEngine(e *engine.StorageEngine) Option { } type ClientConstructor interface { - Get(network.AddressGroup) (client.Client, error) + Get(client.NodeInfo) (client.Client, error) } // WithClientConstructor returns option to set constructor of remote node clients. diff --git a/pkg/services/object/get/util.go b/pkg/services/object/get/util.go index 97aac7f78..bb1ec14b1 100644 --- a/pkg/services/object/get/util.go +++ b/pkg/services/object/get/util.go @@ -9,7 +9,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" - "github.com/nspcc-dev/neofs-node/pkg/network" ) type SimpleObjectWriter struct { @@ -73,17 +72,20 @@ func (s *SimpleObjectWriter) Object() *object.Object { return s.obj.Object() } -func (c *clientCacheWrapper) get(addr network.AddressGroup) (getClient, error) { - clt, err := c.cache.Get(addr) +func (c *clientCacheWrapper) get(info coreclient.NodeInfo) (getClient, error) { + clt, err := c.cache.Get(info) + if err != nil { + return nil, err + } return &clientWrapper{ client: clt, - }, err + }, nil } -func (c *clientWrapper) getObject(exec *execCtx, addr network.AddressGroup) (*objectSDK.Object, error) { +func (c *clientWrapper) getObject(exec *execCtx, info coreclient.NodeInfo) (*objectSDK.Object, error) { if exec.isForwardingEnabled() { - return exec.prm.forwarder(addr, c.client) + return exec.prm.forwarder(info, c.client) } if exec.headOnly() { diff --git a/pkg/services/object/get/v2/util.go b/pkg/services/object/get/v2/util.go index 6ecfb1c08..6e15430e3 100644 --- a/pkg/services/object/get/v2/util.go +++ b/pkg/services/object/get/v2/util.go @@ -509,13 +509,13 @@ func toShortObjectHeader(hdr *object.Object) objectV2.GetHeaderPart { } func groupAddressRequestForwarder(f func(network.Address, client.Client) (*objectSDK.Object, error)) getsvc.RequestForwarder { - return func(addrGroup network.AddressGroup, c client.Client) (*objectSDK.Object, error) { + return func(info client.NodeInfo, c client.Client) (*objectSDK.Object, error) { var ( firstErr error res *objectSDK.Object ) - addrGroup.IterateAddresses(func(addr network.Address) (stop bool) { + info.AddressGroup().IterateAddresses(func(addr network.Address) (stop bool) { var err error defer func() { diff --git a/pkg/services/object/head/remote.go b/pkg/services/object/head/remote.go index 0bd2ab890..7f1db3331 100644 --- a/pkg/services/object/head/remote.go +++ b/pkg/services/object/head/remote.go @@ -7,13 +7,14 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/client" 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/core/object" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" ) type ClientConstructor interface { - Get(network.AddressGroup) (client.Client, error) + Get(clientcore.NodeInfo) (client.Client, error) } // RemoteHeader represents utility for getting @@ -66,7 +67,11 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob return nil, fmt.Errorf("(%T) could not receive private key: %w", h, err) } - c, err := h.clientCache.Get(prm.node) + var info clientcore.NodeInfo + + info.SetAddressGroup(prm.node) + + c, err := h.clientCache.Get(info) if err != nil { return nil, fmt.Errorf("(%T) could not create SDK client %s: %w", h, prm.node, err) } diff --git a/pkg/services/object/put/remote.go b/pkg/services/object/put/remote.go index 2339a39ef..6ba9e0d9b 100644 --- a/pkg/services/object/put/remote.go +++ b/pkg/services/object/put/remote.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/nspcc-dev/neofs-api-go/pkg/client" + clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/services/object/util" @@ -54,7 +55,11 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) { return nil, fmt.Errorf("(%T) could not receive private key: %w", t, err) } - c, err := t.clientConstructor.Get(t.addr) + var info clientcore.NodeInfo + + info.SetAddressGroup(t.addr) + + c, err := t.clientConstructor.Get(info) if err != nil { return nil, fmt.Errorf("(%T) could not create SDK client %s: %w", t, t.addr, err) } diff --git a/pkg/services/object/put/service.go b/pkg/services/object/put/service.go index 12e84ae39..9ef336614 100644 --- a/pkg/services/object/put/service.go +++ b/pkg/services/object/put/service.go @@ -8,7 +8,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" - "github.com/nspcc-dev/neofs-node/pkg/network" 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/logger" @@ -30,7 +29,7 @@ type Service struct { type Option func(*cfg) type ClientConstructor interface { - Get(network.AddressGroup) (client.Client, error) + Get(client.NodeInfo) (client.Client, error) } type cfg struct { diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index df52ba321..93fe270bd 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -150,7 +150,11 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget { relay = func(node nodeDesc) error { addr := node.info.Addresses() - c, err := p.clientConstructor.Get(addr) + var info client.NodeInfo + + info.SetAddressGroup(addr) + + c, err := p.clientConstructor.Get(info) if err != nil { return fmt.Errorf("could not create SDK client %s: %w", addr, err) } diff --git a/pkg/services/object/search/container.go b/pkg/services/object/search/container.go index d561f7c62..434ddcd23 100644 --- a/pkg/services/object/search/container.go +++ b/pkg/services/object/search/container.go @@ -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) } } diff --git a/pkg/services/object/search/exec.go b/pkg/services/object/search/exec.go index 784506b92..4697f7ec3 100644 --- a/pkg/services/object/search/exec.go +++ b/pkg/services/object/search/exec.go @@ -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 diff --git a/pkg/services/object/search/prm.go b/pkg/services/object/search/prm.go index 31719c5ec..55146c29d 100644 --- a/pkg/services/object/search/prm.go +++ b/pkg/services/object/search/prm.go @@ -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) { diff --git a/pkg/services/object/search/remote.go b/pkg/services/object/search/remote.go index 332a17eb2..5fb0bb8c9 100644 --- a/pkg/services/object/search/remote.go +++ b/pkg/services/object/search/remote.go @@ -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", diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index ec8b32c24..7dd04ae91 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -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 diff --git a/pkg/services/object/search/service.go b/pkg/services/object/search/service.go index cd5c28207..14d7342ef 100644 --- a/pkg/services/object/search/service.go +++ b/pkg/services/object/search/service.go @@ -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 { diff --git a/pkg/services/object/search/util.go b/pkg/services/object/search/util.go index bb26bc392..6d1813d9a 100644 --- a/pkg/services/object/search/util.go +++ b/pkg/services/object/search/util.go @@ -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(), diff --git a/pkg/services/object/search/v2/util.go b/pkg/services/object/search/v2/util.go index ce8b2bd1a..521aa71ec 100644 --- a/pkg/services/object/search/v2/util.go +++ b/pkg/services/object/search/v2/util.go @@ -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() {