[#1247] container: Return ContainerNotFound status error

Replace `core/container.ErrNotFound` error returned by `Source.Get`
interface method with `apistatus.ContainerNotFound` status error. This
error is returned by storage node's server as NeoFS API statuses.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-03-17 11:17:45 +03:00 committed by Alex Vanin
parent 70ffdf3478
commit 967650f2ed
5 changed files with 17 additions and 10 deletions

View file

@ -3,6 +3,7 @@ package container
import ( import (
"errors" "errors"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
"github.com/nspcc-dev/neofs-sdk-go/container" "github.com/nspcc-dev/neofs-sdk-go/container"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
) )
@ -14,15 +15,18 @@ type Source interface {
// It returns the pointer to requested container and any error encountered. // It returns the pointer to requested container and any error encountered.
// //
// Get must return exactly one non-nil value. // Get must return exactly one non-nil value.
// Get must return ErrNotFound if the container is not in storage. // Get must return apistatus.ContainerNotFound if the container is not in storage.
// //
// Implementations must not retain the container pointer and modify // Implementations must not retain the container pointer and modify
// the container through it. // the container through it.
Get(*cid.ID) (*container.Container, error) Get(*cid.ID) (*container.Container, error)
} }
// ErrNotFound is the error returned when container was not found in storage. // IsErrNotFound checks if error returned by Source.Get corresponds
var ErrNotFound = errors.New("container not found") // to missing container.
func IsErrNotFound(err error) bool {
return errors.As(err, new(apistatus.ContainerNotFound))
}
// ErrEACLNotFound is returned by eACL storage implementations when // ErrEACLNotFound is returned by eACL storage implementations when
// requested eACL table is not in storage. // requested eACL table is not in storage.

View file

@ -7,6 +7,7 @@ import (
containerContract "github.com/nspcc-dev/neofs-contract/container" containerContract "github.com/nspcc-dev/neofs-contract/container"
core "github.com/nspcc-dev/neofs-node/pkg/core/container" core "github.com/nspcc-dev/neofs-node/pkg/core/container"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
"github.com/nspcc-dev/neofs-sdk-go/container" "github.com/nspcc-dev/neofs-sdk-go/container"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/session"
@ -45,7 +46,9 @@ func (c *Client) Get(cid []byte) (*container.Container, error) {
res, err := c.client.TestInvoke(prm) res, err := c.client.TestInvoke(prm)
if err != nil { if err != nil {
if strings.Contains(err.Error(), containerContract.NotFoundError) { if strings.Contains(err.Error(), containerContract.NotFoundError) {
return nil, core.ErrNotFound var errNotFound apistatus.ContainerNotFound
return nil, errNotFound
} }
return nil, fmt.Errorf("could not perform test invocation (%s): %w", getMethod, err) return nil, fmt.Errorf("could not perform test invocation (%s): %w", getMethod, err)
} else if ln := len(res); ln != 1 { } else if ln := len(res); ln != 1 {

View file

@ -11,8 +11,6 @@ var (
ErrMalformedRequest = errors.New("malformed request") ErrMalformedRequest = errors.New("malformed request")
// ErrUnknownRole is returned when role of the sender is unknown. // ErrUnknownRole is returned when role of the sender is unknown.
ErrUnknownRole = errors.New("can't classify request sender") ErrUnknownRole = errors.New("can't classify request sender")
// ErrUnknownContainer is returned when container fetching errors appeared.
ErrUnknownContainer = errors.New("can't fetch container info")
// ErrInvalidVerb is returned when session token verb doesn't include necessary operation. // ErrInvalidVerb is returned when session token verb doesn't include necessary operation.
ErrInvalidVerb = errors.New("session token verb is invalid") ErrInvalidVerb = errors.New("session token verb is invalid")
) )

View file

@ -2,6 +2,7 @@ package v2
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
@ -410,8 +411,10 @@ func (b Service) findRequestInfo(
cid *cidSDK.ID, cid *cidSDK.ID,
op eaclSDK.Operation) (info RequestInfo, err error) { op eaclSDK.Operation) (info RequestInfo, err error) {
cnr, err := b.containers.Get(cid) // fetch actual container cnr, err := b.containers.Get(cid) // fetch actual container
if err != nil || cnr.OwnerID() == nil { if err != nil {
return info, ErrUnknownContainer return info, err
} else if cnr.OwnerID() == nil {
return info, errors.New("missing owner in container descriptor")
} }
// find request role and key // find request role and key

View file

@ -2,7 +2,6 @@ package policer
import ( import (
"context" "context"
"errors"
"strings" "strings"
"github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/container"
@ -21,7 +20,7 @@ func (p *Policer) processObject(ctx context.Context, addr *addressSDK.Address) {
zap.Stringer("cid", addr.ContainerID()), zap.Stringer("cid", addr.ContainerID()),
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
if errors.Is(err, container.ErrNotFound) { if container.IsErrNotFound(err) {
prm := new(engine.InhumePrm) prm := new(engine.InhumePrm)
prm.MarkAsGarbage(addr) prm.MarkAsGarbage(addr)
_, err := p.jobQueue.localStorage.Inhume(prm) _, err := p.jobQueue.localStorage.Inhume(prm)