2020-11-24 14:15:58 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2022-03-04 12:57:43 +00:00
|
|
|
"errors"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-07-05 14:07:40 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
2022-03-04 12:57:43 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
2022-03-17 08:03:58 +00:00
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2022-03-03 14:19:05 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2020-11-24 14:15:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetRangeBig reads data of object payload range from shallow dir of BLOB storage.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that
|
|
|
|
// did not allow to completely read the object payload range.
|
2020-12-08 16:53:01 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns ErrRangeOutOfBounds if the requested object range is out of bounds.
|
2022-03-17 13:26:17 +00:00
|
|
|
// Returns an error of type apistatus.ObjectNotFound if object is missing.
|
2022-07-06 11:54:23 +00:00
|
|
|
func (b *BlobStor) GetRangeBig(prm common.GetRangePrm) (common.GetRangeRes, error) {
|
2020-11-24 14:15:58 +00:00
|
|
|
// get compressed object data
|
2022-07-06 11:54:23 +00:00
|
|
|
data, err := b.fsTree.Get(common.GetPrm{Address: prm.Address})
|
2020-11-24 14:15:58 +00:00
|
|
|
if err != nil {
|
2022-03-04 12:56:29 +00:00
|
|
|
if errors.Is(err, fstree.ErrFileNotFound) {
|
2022-03-17 08:03:58 +00:00
|
|
|
var errNotFound apistatus.ObjectNotFound
|
|
|
|
|
2022-07-06 11:54:23 +00:00
|
|
|
return common.GetRangeRes{}, errNotFound
|
2022-03-04 12:56:29 +00:00
|
|
|
}
|
|
|
|
|
2022-07-06 11:54:23 +00:00
|
|
|
return common.GetRangeRes{}, fmt.Errorf("could not read object from fs tree: %w", err)
|
2020-11-24 14:15:58 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 13:47:39 +00:00
|
|
|
data, err = b.Decompress(data)
|
2020-11-24 14:15:58 +00:00
|
|
|
if err != nil {
|
2022-07-06 11:54:23 +00:00
|
|
|
return common.GetRangeRes{}, fmt.Errorf("could not decompress object data: %w", err)
|
2020-11-24 14:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// unmarshal the object
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := objectSDK.New()
|
2020-11-24 14:15:58 +00:00
|
|
|
if err := obj.Unmarshal(data); err != nil {
|
2022-07-06 11:54:23 +00:00
|
|
|
return common.GetRangeRes{}, fmt.Errorf("could not unmarshal the object: %w", err)
|
2020-11-24 14:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
payload := obj.Payload()
|
2022-07-06 11:54:23 +00:00
|
|
|
ln, off := prm.Range.GetLength(), prm.Range.GetOffset()
|
2020-11-24 14:15:58 +00:00
|
|
|
|
2022-07-29 08:11:55 +00:00
|
|
|
if pLen := uint64(len(payload)); ln+off < off || pLen < off || pLen < ln+off {
|
2022-06-29 17:33:48 +00:00
|
|
|
var errOutOfRange apistatus.ObjectOutOfRange
|
|
|
|
|
2022-07-06 11:54:23 +00:00
|
|
|
return common.GetRangeRes{}, errOutOfRange
|
2020-11-24 14:15:58 +00:00
|
|
|
}
|
|
|
|
|
2022-07-06 11:54:23 +00:00
|
|
|
return common.GetRangeRes{
|
|
|
|
Data: payload[off : off+ln],
|
2020-11-24 14:15:58 +00:00
|
|
|
}, nil
|
|
|
|
}
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
// GetRangeSmall reads data of object payload range from blobovnicza of BLOB storage.
|
|
|
|
//
|
|
|
|
// If blobovnicza ID is not set or set to nil, BlobStor tries to get payload range
|
|
|
|
// from any blobovnicza.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that
|
|
|
|
// did not allow to completely read the object payload range.
|
|
|
|
//
|
|
|
|
// 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).
|
2022-07-06 11:54:23 +00:00
|
|
|
func (b *BlobStor) GetRangeSmall(prm common.GetRangePrm) (common.GetRangeRes, error) {
|
2022-07-05 13:47:39 +00:00
|
|
|
return b.blobovniczas.GetRange(prm)
|
|
|
|
}
|