forked from TrueCloudLab/frostfs-node
[#607] client: Overload Client interface
There is a need to generalize single-address client to group-address client. To do this, we can re-implement `Client` interface from NeoFS API Go library and still use it in the application code. There is a problem with method `Raw` which must return single-address raw client. So as not to make changes to API library we need to overload Client interface in order to support `Raw` method in group-address client implementation. Define `Client` interface in new `pkg/core/client` package. Completely inherit API `Client` interface. Add `RawForAddress` method to build raw client for the single node address. Adopt the application code that used Raw method to work with new `Client`. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
5e4208648a
commit
3805b0f638
18 changed files with 91 additions and 40 deletions
|
@ -100,7 +100,7 @@ func newTestClient() *testClient {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *testClient) getObject(exec *execCtx) (*objectSDK.Object, error) {
|
||||
func (c *testClient) getObject(exec *execCtx, _ network.Address) (*objectSDK.Object, error) {
|
||||
v, ok := c.results[exec.address().String()]
|
||||
if !ok {
|
||||
return nil, object.ErrNotFound
|
||||
|
|
|
@ -5,7 +5,9 @@ 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/core/object"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||
)
|
||||
|
||||
|
@ -32,7 +34,7 @@ type RangeHashPrm struct {
|
|||
salt []byte
|
||||
}
|
||||
|
||||
type RequestForwarder func(client.Client) (*objectSDK.Object, error)
|
||||
type RequestForwarder func(network.Address, coreclient.Client) (*objectSDK.Object, error)
|
||||
|
||||
// HeadPrm groups parameters of Head service call.
|
||||
type HeadPrm struct {
|
||||
|
|
|
@ -20,7 +20,7 @@ func (exec *execCtx) processNode(ctx context.Context, addr network.Address) bool
|
|||
return true
|
||||
}
|
||||
|
||||
obj, err := client.getObject(exec)
|
||||
obj, err := client.getObject(exec, addr)
|
||||
|
||||
var errSplitInfo *objectSDK.SplitInfoError
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package getsvc
|
||||
|
||||
import (
|
||||
"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/client"
|
||||
"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"
|
||||
|
@ -22,7 +22,7 @@ type Service struct {
|
|||
type Option func(*cfg)
|
||||
|
||||
type getClient interface {
|
||||
getObject(*execCtx) (*objectSDK.Object, error)
|
||||
getObject(*execCtx, network.Address) (*objectSDK.Object, error)
|
||||
}
|
||||
|
||||
type cfg struct {
|
||||
|
|
|
@ -5,6 +5,7 @@ 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/core/netmap"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
||||
|
@ -22,7 +23,7 @@ type clientCacheWrapper struct {
|
|||
}
|
||||
|
||||
type clientWrapper struct {
|
||||
client client.Client
|
||||
client coreclient.Client
|
||||
}
|
||||
|
||||
type storageEngineWrapper struct {
|
||||
|
@ -80,9 +81,9 @@ func (c *clientCacheWrapper) get(addr network.Address) (getClient, error) {
|
|||
}, err
|
||||
}
|
||||
|
||||
func (c *clientWrapper) getObject(exec *execCtx) (*objectSDK.Object, error) {
|
||||
func (c *clientWrapper) getObject(exec *execCtx, addr network.Address) (*objectSDK.Object, error) {
|
||||
if !exec.assembling && exec.prm.forwarder != nil {
|
||||
return exec.prm.forwarder(c.client)
|
||||
return exec.prm.forwarder(addr, c.client)
|
||||
}
|
||||
|
||||
if exec.headOnly() {
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"io"
|
||||
"sync"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
sessionsdk "github.com/nspcc-dev/neofs-api-go/pkg/session"
|
||||
rpcclient "github.com/nspcc-dev/neofs-api-go/rpc/client"
|
||||
|
@ -19,7 +18,9 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/v2/rpc"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/signature"
|
||||
"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"
|
||||
objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
||||
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||
|
@ -54,7 +55,7 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre
|
|||
if !commonPrm.LocalOnly() {
|
||||
var onceResign sync.Once
|
||||
|
||||
p.SetRequestForwarder(func(c client.Client) (*objectSDK.Object, error) {
|
||||
p.SetRequestForwarder(func(addr network.Address, c client.Client) (*objectSDK.Object, error) {
|
||||
var err error
|
||||
|
||||
// once compose and resign forwarding request
|
||||
|
@ -78,7 +79,7 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre
|
|||
// perhaps it is worth highlighting the utility function in neofs-api-go
|
||||
|
||||
// open stream
|
||||
stream, err := rpc.GetObject(c.Raw(), req, rpcclient.WithContext(stream.Context()))
|
||||
stream, err := rpc.GetObject(c.RawForAddress(addr), req, rpcclient.WithContext(stream.Context()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("stream opening failed: %w", err)
|
||||
}
|
||||
|
@ -176,7 +177,7 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
|
|||
if !commonPrm.LocalOnly() {
|
||||
var onceResign sync.Once
|
||||
|
||||
p.SetRequestForwarder(func(c client.Client) (*objectSDK.Object, error) {
|
||||
p.SetRequestForwarder(func(addr network.Address, c client.Client) (*objectSDK.Object, error) {
|
||||
var err error
|
||||
|
||||
// once compose and resign forwarding request
|
||||
|
@ -200,7 +201,7 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
|
|||
// perhaps it is worth highlighting the utility function in neofs-api-go
|
||||
|
||||
// open stream
|
||||
stream, err := rpc.GetObjectRange(c.Raw(), req, rpcclient.WithContext(stream.Context()))
|
||||
stream, err := rpc.GetObjectRange(c.RawForAddress(addr), req, rpcclient.WithContext(stream.Context()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create Get payload range stream: %w", err)
|
||||
}
|
||||
|
@ -339,7 +340,7 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp
|
|||
if !commonPrm.LocalOnly() {
|
||||
var onceResign sync.Once
|
||||
|
||||
p.SetRequestForwarder(func(c client.Client) (*objectSDK.Object, error) {
|
||||
p.SetRequestForwarder(func(addr network.Address, c client.Client) (*objectSDK.Object, error) {
|
||||
var err error
|
||||
|
||||
// once compose and resign forwarding request
|
||||
|
@ -363,7 +364,7 @@ func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp
|
|||
// perhaps it is worth highlighting the utility function in neofs-api-go
|
||||
|
||||
// send Head request
|
||||
resp, err := rpc.HeadObject(c.Raw(), req, rpcclient.WithContext(ctx))
|
||||
resp, err := rpc.HeadObject(c.RawForAddress(addr), req, rpcclient.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sending the request failed: %w", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue