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
|
|
|
|
2022-07-05 14:07:40 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
2022-03-17 08:03:58 +00:00
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2020-11-24 14:15:58 +00:00
|
|
|
)
|
|
|
|
|
2022-07-06 12:39:35 +00:00
|
|
|
// GetRange reads object payload data from b.
|
|
|
|
// If the descriptor is present, only one sub-storage is tried,
|
|
|
|
// Otherwise, each sub-storage is tried in order.
|
|
|
|
func (b *BlobStor) GetRange(prm common.GetRangePrm) (common.GetRangeRes, error) {
|
2022-07-06 14:09:50 +00:00
|
|
|
if prm.StorageID == nil {
|
2022-07-06 12:39:35 +00:00
|
|
|
// Nothing specified, try everything.
|
|
|
|
res, err := b.getRangeBig(prm)
|
|
|
|
if err == nil || !errors.As(err, new(apistatus.ObjectNotFound)) {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
return b.getRangeSmall(prm)
|
|
|
|
}
|
2022-07-06 14:09:50 +00:00
|
|
|
if len(prm.StorageID) == 0 {
|
2022-07-06 12:39:35 +00:00
|
|
|
return b.getRangeBig(prm)
|
|
|
|
}
|
|
|
|
return b.getRangeSmall(prm)
|
|
|
|
}
|
|
|
|
|
|
|
|
// getRangeBig reads data of object payload range from shallow dir of BLOB storage.
|
2020-11-24 14:15:58 +00:00
|
|
|
//
|
|
|
|
// 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 12:39:35 +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-08 07:09:48 +00:00
|
|
|
res, err := b.fsTree.Get(common.GetPrm{Address: prm.Address})
|
2020-11-24 14:15:58 +00:00
|
|
|
if err != nil {
|
2022-07-08 07:09:48 +00:00
|
|
|
return common.GetRangeRes{}, err
|
2020-11-24 14:15:58 +00:00
|
|
|
}
|
|
|
|
|
2022-07-08 07:09:48 +00:00
|
|
|
payload := res.Object.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
|
|
|
|
2022-07-06 12:39:35 +00:00
|
|
|
// getRangeSmall reads data of object payload range from blobovnicza of BLOB storage.
|
2022-07-05 13:47:39 +00:00
|
|
|
//
|
|
|
|
// 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 12:39:35 +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)
|
|
|
|
}
|