From 9dd83bdf0d90b1791ffbf17108eaf6def700845d Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 8 Dec 2020 19:53:01 +0300 Subject: [PATCH] [#235] blobstor: Return object.ErrRangeOutOfBounds from shallow dir Signed-off-by: Leonard Lyubich --- .../blobstor/blobovnicza.go | 30 ++++++++++++------- .../blobstor/get_range_big.go | 5 ++-- .../blobstor/get_range_small.go | 2 ++ pkg/local_object_storage/shard/range.go | 2 ++ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/pkg/local_object_storage/blobstor/blobovnicza.go b/pkg/local_object_storage/blobstor/blobovnicza.go index ebc21489..781ee3f4 100644 --- a/pkg/local_object_storage/blobstor/blobovnicza.go +++ b/pkg/local_object_storage/blobstor/blobovnicza.go @@ -473,12 +473,17 @@ func (b *blobovniczas) getRangeFromLevel(prm *GetRangeSmallPrm, blzPath string, // try to read from blobovnicza if it is opened v, ok := b.opened.Get(blzPath) if ok { - if res, err := b.getObjectRange(v.(*blobovnicza.Blobovnicza), prm); err == nil { + res, err := b.getObjectRange(v.(*blobovnicza.Blobovnicza), prm) + switch { + case err == nil, + errors.Is(err, object.ErrRangeOutOfBounds): return res, err - } else if !errors.Is(err, object.ErrNotFound) { - log.Debug("could not read payload range from opened blobovnicza", - zap.String("error", err.Error()), - ) + default: + if !errors.Is(err, object.ErrNotFound) { + log.Debug("could not read payload range from opened blobovnicza", + zap.String("error", err.Error()), + ) + } } } @@ -492,12 +497,17 @@ func (b *blobovniczas) getRangeFromLevel(prm *GetRangeSmallPrm, blzPath string, b.activeMtx.RUnlock() if ok && tryActive { - if res, err := b.getObjectRange(active.blz, prm); err == nil { + res, err := b.getObjectRange(active.blz, prm) + switch { + case err == nil, + errors.Is(err, object.ErrRangeOutOfBounds): return res, err - } else if !errors.Is(err, object.ErrNotFound) { - log.Debug("could not read payload range from active blobovnicza", - zap.String("error", err.Error()), - ) + default: + if !errors.Is(err, object.ErrNotFound) { + log.Debug("could not read payload range from active blobovnicza", + zap.String("error", err.Error()), + ) + } } } diff --git a/pkg/local_object_storage/blobstor/get_range_big.go b/pkg/local_object_storage/blobstor/get_range_big.go index c781df1d..4bb45336 100644 --- a/pkg/local_object_storage/blobstor/get_range_big.go +++ b/pkg/local_object_storage/blobstor/get_range_big.go @@ -20,6 +20,8 @@ type GetRangeBigRes struct { // // Returns any error encountered that // did not allow to completely read the object payload range. +// +// Returns ErrRangeOutOfBounds if requested object range is out of bounds. func (b *BlobStor) GetRangeBig(prm *GetRangeBigPrm) (*GetRangeBigRes, error) { // get compressed object data data, err := b.fsTree.get(prm.addr) @@ -42,8 +44,7 @@ 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 nil, errors.Errorf("range is out-of-bounds (payload %d, off %d, ln %d)", - pLen, off, ln) + return nil, object.ErrRangeOutOfBounds } return &GetRangeBigRes{ diff --git a/pkg/local_object_storage/blobstor/get_range_small.go b/pkg/local_object_storage/blobstor/get_range_small.go index c6795a76..7fe4c0da 100644 --- a/pkg/local_object_storage/blobstor/get_range_small.go +++ b/pkg/local_object_storage/blobstor/get_range_small.go @@ -19,6 +19,8 @@ type GetRangeSmallRes struct { // // Returns any error encountered that // did not allow to completely read the object payload range. +// +// Returns ErrRangeOutOfBounds if requested object range is out of bounds. func (b *BlobStor) GetRangeSmall(prm *GetRangeSmallPrm) (*GetRangeSmallRes, error) { return b.blobovniczas.getRange(prm) } diff --git a/pkg/local_object_storage/shard/range.go b/pkg/local_object_storage/shard/range.go index 8bb3fa2f..26d043e0 100644 --- a/pkg/local_object_storage/shard/range.go +++ b/pkg/local_object_storage/shard/range.go @@ -52,6 +52,8 @@ func (r *RngRes) Object() *object.Object { // // Returns any error encountered that // did not allow to completely read the object part. +// +// Returns ErrRangeOutOfBounds if requested object range is out of bounds. func (s *Shard) GetRange(prm *RngPrm) (*RngRes, error) { var big, small storFetcher