From 9f7a22e2aa4751a214acecee38b3e258f9e13987 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 29 Jun 2022 20:33:48 +0300 Subject: [PATCH] [#1561] object: Return `OUT_OF_RANGE` status Replace `ErrRangeOutOfBounds` error from `pkg/core/object` package with `ObjectOutOfRange` from `apistatus` package. That error is returned by storage node's server as NeoFS API statuses. Signed-off-by: Pavel Karpy --- pkg/core/object/errors.go | 7 ------- pkg/local_object_storage/blobstor/blobovnicza.go | 11 ++++++----- pkg/local_object_storage/blobstor/errors.go | 11 +++++++++++ pkg/local_object_storage/blobstor/get_range_big.go | 5 +++-- pkg/local_object_storage/engine/error_test.go | 3 ++- pkg/local_object_storage/engine/range.go | 9 +++++---- pkg/local_object_storage/shard/errors.go | 6 ++++++ pkg/local_object_storage/shard/get.go | 4 +--- pkg/services/object/get/assemble.go | 7 +++++-- pkg/services/object/get/local.go | 6 +++--- pkg/services/object/get/remote.go | 4 ++++ 11 files changed, 46 insertions(+), 27 deletions(-) delete mode 100644 pkg/core/object/errors.go create mode 100644 pkg/local_object_storage/blobstor/errors.go diff --git a/pkg/core/object/errors.go b/pkg/core/object/errors.go deleted file mode 100644 index d1a69e5c..00000000 --- a/pkg/core/object/errors.go +++ /dev/null @@ -1,7 +0,0 @@ -package object - -import "errors" - -// ErrRangeOutOfBounds is a basic error of violation of the boundaries of the -// payload of an object. -var ErrRangeOutOfBounds = errors.New("payload range is out of bounds") diff --git a/pkg/local_object_storage/blobstor/blobovnicza.go b/pkg/local_object_storage/blobstor/blobovnicza.go index f1155786..e63788fa 100644 --- a/pkg/local_object_storage/blobstor/blobovnicza.go +++ b/pkg/local_object_storage/blobstor/blobovnicza.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/golang-lru/simplelru" "github.com/nspcc-dev/hrw" - "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" storagelog "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/internal/log" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" @@ -331,7 +330,7 @@ func (b *blobovniczas) getRange(prm GetRangeSmallPrm) (res GetRangeSmallRes, err res, err = b.getRangeFromLevel(prm, p, !ok) if err != nil { - outOfBounds := errors.Is(err, object.ErrRangeOutOfBounds) + outOfBounds := isErrOutOfRange(err) if !blobovnicza.IsErrNotFound(err) && !outOfBounds { b.log.Debug("could not get object from level", zap.String("level", p), @@ -498,7 +497,7 @@ func (b *blobovniczas) getRangeFromLevel(prm GetRangeSmallPrm, blzPath string, t res, err := b.getObjectRange(v.(*blobovnicza.Blobovnicza), prm) switch { case err == nil, - errors.Is(err, object.ErrRangeOutOfBounds): + isErrOutOfRange(err): return res, err default: if !blobovnicza.IsErrNotFound(err) { @@ -523,7 +522,7 @@ func (b *blobovniczas) getRangeFromLevel(prm GetRangeSmallPrm, blzPath string, t res, err := b.getObjectRange(active.blz, prm) switch { case err == nil, - errors.Is(err, object.ErrRangeOutOfBounds): + isErrOutOfRange(err): return res, err default: if !blobovnicza.IsErrNotFound(err) { @@ -630,7 +629,9 @@ func (b *blobovniczas) getObjectRange(blz *blobovnicza.Blobovnicza, prm GetRange payload := obj.Payload() if uint64(len(payload)) < to { - return GetRangeSmallRes{}, object.ErrRangeOutOfBounds + var errOutOfRange apistatus.ObjectOutOfRange + + return GetRangeSmallRes{}, errOutOfRange } return GetRangeSmallRes{ diff --git a/pkg/local_object_storage/blobstor/errors.go b/pkg/local_object_storage/blobstor/errors.go new file mode 100644 index 00000000..e044b450 --- /dev/null +++ b/pkg/local_object_storage/blobstor/errors.go @@ -0,0 +1,11 @@ +package blobstor + +import ( + "errors" + + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" +) + +func isErrOutOfRange(err error) bool { + return errors.As(err, new(apistatus.ObjectOutOfRange)) +} diff --git a/pkg/local_object_storage/blobstor/get_range_big.go b/pkg/local_object_storage/blobstor/get_range_big.go index 9b1c3a42..65b6d010 100644 --- a/pkg/local_object_storage/blobstor/get_range_big.go +++ b/pkg/local_object_storage/blobstor/get_range_big.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" - "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" @@ -56,7 +55,9 @@ func (b *BlobStor) GetRangeBig(prm GetRangeBigPrm) (GetRangeBigRes, error) { ln, off := prm.rng.GetLength(), prm.rng.GetOffset() if pLen := uint64(len(payload)); pLen < ln+off { - return GetRangeBigRes{}, object.ErrRangeOutOfBounds + var errOutOfRange apistatus.ObjectOutOfRange + + return GetRangeBigRes{}, errOutOfRange } return GetRangeBigRes{ diff --git a/pkg/local_object_storage/engine/error_test.go b/pkg/local_object_storage/engine/error_test.go index 9655034a..0a30b0ac 100644 --- a/pkg/local_object_storage/engine/error_test.go +++ b/pkg/local_object_storage/engine/error_test.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" "github.com/stretchr/testify/require" @@ -184,7 +185,7 @@ func TestBlobstorFailback(t *testing.T) { require.Equal(t, objs[i].Payload()[1:11], rngRes.Object().Payload()) _, err = e.GetRange(RngPrm{addr: addr, off: errSmallSize + 10, ln: 1}) - require.ErrorIs(t, err, object.ErrRangeOutOfBounds) + require.ErrorAs(t, err, &apistatus.ObjectOutOfRange{}) } checkShardState(t, e, id[0], 4, shard.ModeDegraded) diff --git a/pkg/local_object_storage/engine/range.go b/pkg/local_object_storage/engine/range.go index 721ad713..2b5415fc 100644 --- a/pkg/local_object_storage/engine/range.go +++ b/pkg/local_object_storage/engine/range.go @@ -3,7 +3,6 @@ package engine import ( "errors" - "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" @@ -121,7 +120,7 @@ func (e *StorageEngine) getRange(prm RngPrm) (RngRes, error) { return false case shard.IsErrRemoved(err), - errors.Is(err, object.ErrRangeOutOfBounds): + shard.IsErrOutOfRange(err): outError = err return true // stop, return it back @@ -152,8 +151,10 @@ func (e *StorageEngine) getRange(prm RngPrm) (RngRes, error) { e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) { res, err := sh.GetRange(shPrm) - if errors.Is(err, object.ErrRangeOutOfBounds) { - outError = object.ErrRangeOutOfBounds + if shard.IsErrOutOfRange(err) { + var errOutOfRange apistatus.ObjectOutOfRange + + outError = errOutOfRange return true } obj = res.Object() diff --git a/pkg/local_object_storage/shard/errors.go b/pkg/local_object_storage/shard/errors.go index 18a29669..5ab3ecdf 100644 --- a/pkg/local_object_storage/shard/errors.go +++ b/pkg/local_object_storage/shard/errors.go @@ -17,3 +17,9 @@ func IsErrNotFound(err error) bool { func IsErrRemoved(err error) bool { return errors.As(err, new(apistatus.ObjectAlreadyRemoved)) } + +// IsErrOutOfRange checks if an error returned by Shard GetRange method +// corresponds to exceeding the object bounds. +func IsErrOutOfRange(err error) bool { + return errors.As(err, new(apistatus.ObjectOutOfRange)) +} diff --git a/pkg/local_object_storage/shard/get.go b/pkg/local_object_storage/shard/get.go index 6c28c7c0..cb2e1873 100644 --- a/pkg/local_object_storage/shard/get.go +++ b/pkg/local_object_storage/shard/get.go @@ -1,10 +1,8 @@ package shard import ( - "errors" "fmt" - "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" @@ -129,7 +127,7 @@ func (s *Shard) fetchObjectData(addr oid.Address, skipMeta bool, big, small stor if skipMeta || err != nil { res, err = small(s.blobStor, nil) - if err == nil || errors.Is(err, object.ErrRangeOutOfBounds) { + if err == nil || IsErrOutOfRange(err) { return res, false, err } res, err = big(s.blobStor, nil) diff --git a/pkg/services/object/get/assemble.go b/pkg/services/object/get/assemble.go index 0d14578d..08d8806c 100644 --- a/pkg/services/object/get/assemble.go +++ b/pkg/services/object/get/assemble.go @@ -1,7 +1,7 @@ package getsvc import ( - "github.com/nspcc-dev/neofs-node/pkg/core/object" + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "go.uber.org/zap" @@ -93,8 +93,11 @@ func (exec *execCtx) initFromChild(obj oid.ID) (prev *oid.ID, children []oid.ID) parSize := par.PayloadSize() if seekOff+seekLen > parSize { + var errOutOfRange apistatus.ObjectOutOfRange + + exec.err = errOutOfRange exec.status = statusOutOfRange - exec.err = object.ErrRangeOutOfBounds + return } diff --git a/pkg/services/object/get/local.go b/pkg/services/object/get/local.go index 5c127b71..05d33553 100644 --- a/pkg/services/object/get/local.go +++ b/pkg/services/object/get/local.go @@ -3,7 +3,6 @@ package getsvc import ( "errors" - "github.com/nspcc-dev/neofs-node/pkg/core/object" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" "go.uber.org/zap" @@ -16,6 +15,7 @@ func (exec *execCtx) executeLocal() { var errSplitInfo *objectSDK.SplitInfoError var errRemoved apistatus.ObjectAlreadyRemoved + var errOutOfRange apistatus.ObjectOutOfRange switch { default: @@ -36,8 +36,8 @@ func (exec *execCtx) executeLocal() { exec.status = statusVIRTUAL mergeSplitInfo(exec.splitInfo(), errSplitInfo.SplitInfo()) exec.err = objectSDK.NewSplitInfoError(exec.infoSplit) - case errors.Is(err, object.ErrRangeOutOfBounds): + case errors.As(err, &errOutOfRange): exec.status = statusOutOfRange - exec.err = object.ErrRangeOutOfBounds + exec.err = errOutOfRange } } diff --git a/pkg/services/object/get/remote.go b/pkg/services/object/get/remote.go index 93d70a5a..e6fdc1a5 100644 --- a/pkg/services/object/get/remote.go +++ b/pkg/services/object/get/remote.go @@ -22,6 +22,7 @@ func (exec *execCtx) processNode(ctx context.Context, info client.NodeInfo) bool var errSplitInfo *objectSDK.SplitInfoError var errRemoved *apistatus.ObjectAlreadyRemoved + var errOutOfRange *apistatus.ObjectOutOfRange switch { default: @@ -47,6 +48,9 @@ func (exec *execCtx) processNode(ctx context.Context, info client.NodeInfo) bool case errors.As(err, &errRemoved): exec.status = statusINHUMED exec.err = errRemoved + case errors.As(err, &errOutOfRange): + exec.status = statusOutOfRange + exec.err = errOutOfRange case errors.As(err, &errSplitInfo): exec.status = statusVIRTUAL mergeSplitInfo(exec.splitInfo(), errSplitInfo.SplitInfo())