[#1523] local_object_storage: Unify parameters for the GetRange
operation
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
d9a2f280c9
commit
36c88f0dc8
6 changed files with 69 additions and 86 deletions
|
@ -4,24 +4,12 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/blobovniczatree"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
||||
"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"
|
||||
)
|
||||
|
||||
// GetRangeBigPrm groups the parameters of GetRangeBig operation.
|
||||
type GetRangeBigPrm struct {
|
||||
address
|
||||
rwRange
|
||||
}
|
||||
|
||||
// GetRangeBigRes groups the resulting values of GetRangeBig operation.
|
||||
type GetRangeBigRes struct {
|
||||
rangeData
|
||||
}
|
||||
|
||||
// GetRangeBig reads data of object payload range from shallow dir of BLOB storage.
|
||||
//
|
||||
// Returns any error encountered that
|
||||
|
@ -29,43 +17,41 @@ type GetRangeBigRes struct {
|
|||
//
|
||||
// Returns ErrRangeOutOfBounds if the requested object range is out of bounds.
|
||||
// Returns an error of type apistatus.ObjectNotFound if object is missing.
|
||||
func (b *BlobStor) GetRangeBig(prm GetRangeBigPrm) (GetRangeBigRes, error) {
|
||||
func (b *BlobStor) GetRangeBig(prm common.GetRangePrm) (common.GetRangeRes, error) {
|
||||
// get compressed object data
|
||||
data, err := b.fsTree.Get(common.GetPrm{Address: prm.addr})
|
||||
data, err := b.fsTree.Get(common.GetPrm{Address: prm.Address})
|
||||
if err != nil {
|
||||
if errors.Is(err, fstree.ErrFileNotFound) {
|
||||
var errNotFound apistatus.ObjectNotFound
|
||||
|
||||
return GetRangeBigRes{}, errNotFound
|
||||
return common.GetRangeRes{}, errNotFound
|
||||
}
|
||||
|
||||
return GetRangeBigRes{}, fmt.Errorf("could not read object from fs tree: %w", err)
|
||||
return common.GetRangeRes{}, fmt.Errorf("could not read object from fs tree: %w", err)
|
||||
}
|
||||
|
||||
data, err = b.Decompress(data)
|
||||
if err != nil {
|
||||
return GetRangeBigRes{}, fmt.Errorf("could not decompress object data: %w", err)
|
||||
return common.GetRangeRes{}, fmt.Errorf("could not decompress object data: %w", err)
|
||||
}
|
||||
|
||||
// unmarshal the object
|
||||
obj := objectSDK.New()
|
||||
if err := obj.Unmarshal(data); err != nil {
|
||||
return GetRangeBigRes{}, fmt.Errorf("could not unmarshal the object: %w", err)
|
||||
return common.GetRangeRes{}, fmt.Errorf("could not unmarshal the object: %w", err)
|
||||
}
|
||||
|
||||
payload := obj.Payload()
|
||||
ln, off := prm.rng.GetLength(), prm.rng.GetOffset()
|
||||
ln, off := prm.Range.GetLength(), prm.Range.GetOffset()
|
||||
|
||||
if pLen := uint64(len(payload)); ln+off < off || pLen < off || pLen < ln+off {
|
||||
var errOutOfRange apistatus.ObjectOutOfRange
|
||||
|
||||
return GetRangeBigRes{}, errOutOfRange
|
||||
return common.GetRangeRes{}, errOutOfRange
|
||||
}
|
||||
|
||||
return GetRangeBigRes{
|
||||
rangeData: rangeData{
|
||||
data: payload[off : off+ln],
|
||||
},
|
||||
return common.GetRangeRes{
|
||||
Data: payload[off : off+ln],
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -79,6 +65,6 @@ func (b *BlobStor) GetRangeBig(prm GetRangeBigPrm) (GetRangeBigRes, error) {
|
|||
//
|
||||
// Returns ErrRangeOutOfBounds if the requested object range is out of bounds.
|
||||
// Returns an error of type apistatus.ObjectNotFound if the requested object is missing in blobovnicza(s).
|
||||
func (b *BlobStor) GetRangeSmall(prm blobovniczatree.GetRangeSmallPrm) (blobovniczatree.GetRangeSmallRes, error) {
|
||||
func (b *BlobStor) GetRangeSmall(prm common.GetRangePrm) (common.GetRangeRes, error) {
|
||||
return b.blobovniczas.GetRange(prm)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue