Skip to content

Commit

Permalink
node/search: be ready to get status response code in forwarded request
Browse files Browse the repository at this point in the history
Also, do not lose errors after operation forwarding.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell committed Nov 13, 2024
1 parent d0dd35e commit 9230fa4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/services/object/search/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func (exec *execCtx) executeOnContainer() {
lg.Debug("remote operation failed",
zap.String("error", err.Error()))

mtx.Lock()
exec.status = statusUndefined
exec.err = err
mtx.Unlock()

return
}

Expand All @@ -99,11 +104,13 @@ func (exec *execCtx) executeOnContainer() {
}()
})
wg.Wait()
if err != nil {
exec.status = statusUndefined
} else {
if err == nil && exec.err == nil {
exec.status = statusOK
} else {
exec.status = statusUndefined
}

exec.err = err
if exec.err == nil {
exec.err = err
}
}
14 changes: 14 additions & 0 deletions pkg/services/object/search/v2/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
rpcclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-api-go/v2/session"
"github.com/nspcc-dev/neofs-api-go/v2/signature"
"github.com/nspcc-dev/neofs-api-go/v2/status"
"github.com/nspcc-dev/neofs-node/pkg/core/client"
"github.com/nspcc-dev/neofs-node/pkg/network"
objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object"
"github.com/nspcc-dev/neofs-node/pkg/services/object/internal"
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
Expand Down Expand Up @@ -116,6 +118,10 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre
return nil, fmt.Errorf("could not verify %T: %w", resp, err)
}

if err := checkStatus(resp.GetMetaHeader().GetStatus()); err != nil {
return nil, fmt.Errorf("remote node response: %w", err)
}

chunk := resp.GetBody().GetIDList()
var id oid.ID

Expand All @@ -139,6 +145,14 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre
return p, nil
}

func checkStatus(stV2 *status.Status) error {
if !status.IsSuccess(stV2.Code()) {
return apistatus.ErrorFromV2(stV2)
}

return nil
}

func groupAddressRequestForwarder(f func(network.Address, client.MultiAddressClient, []byte) ([]oid.ID, error)) searchsvc.RequestForwarder {
return func(info client.NodeInfo, c client.MultiAddressClient) ([]oid.ID, error) {
var (
Expand Down

0 comments on commit 9230fa4

Please sign in to comment.