2020-12-01 08:33:19 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
2022-07-06 11:54:23 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
2022-07-29 07:54:49 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2020-12-01 08:33:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// RngPrm groups the parameters of GetRange operation.
|
|
|
|
type RngPrm struct {
|
|
|
|
ln uint64
|
|
|
|
|
|
|
|
off uint64
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2022-03-04 12:57:43 +00:00
|
|
|
|
|
|
|
skipMeta bool
|
2020-12-01 08:33:19 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// RngRes groups the resulting values of GetRange operation.
|
2020-12-01 08:33:19 +00:00
|
|
|
type RngRes struct {
|
2022-03-04 12:57:43 +00:00
|
|
|
obj *object.Object
|
|
|
|
hasMeta bool
|
2020-12-01 08:33:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetAddress is a Rng option to set the address of the requested object.
|
2020-12-01 08:33:19 +00:00
|
|
|
//
|
|
|
|
// Option is required.
|
2022-07-13 12:43:04 +00:00
|
|
|
func (p *RngPrm) SetAddress(addr oid.Address) {
|
|
|
|
p.addr = addr
|
2020-12-01 08:33:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetRange is a GetRange option to set range of requested payload data.
|
|
|
|
func (p *RngPrm) SetRange(off uint64, ln uint64) {
|
|
|
|
p.off, p.ln = off, ln
|
2020-12-01 08:33:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetIgnoreMeta is a Get option try to fetch object from blobstor directly,
|
2022-03-04 12:57:43 +00:00
|
|
|
// without accessing metabase.
|
2022-07-13 12:43:04 +00:00
|
|
|
func (p *RngPrm) SetIgnoreMeta(ignore bool) {
|
2022-03-04 12:57:43 +00:00
|
|
|
p.skipMeta = ignore
|
|
|
|
}
|
|
|
|
|
2020-12-01 08:33:19 +00:00
|
|
|
// Object returns the requested object part.
|
|
|
|
//
|
|
|
|
// Instance payload contains the requested range of the original object.
|
2022-05-20 18:08:59 +00:00
|
|
|
func (r RngRes) Object() *object.Object {
|
2020-12-01 08:33:19 +00:00
|
|
|
return r.obj
|
|
|
|
}
|
|
|
|
|
2022-03-04 12:57:43 +00:00
|
|
|
// HasMeta returns true if info about the object was found in the metabase.
|
2022-05-20 18:08:59 +00:00
|
|
|
func (r RngRes) HasMeta() bool {
|
2022-03-04 12:57:43 +00:00
|
|
|
return r.hasMeta
|
|
|
|
}
|
|
|
|
|
2020-12-01 08:33:19 +00:00
|
|
|
// GetRange reads part of an object from shard.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that
|
|
|
|
// did not allow to completely read the object part.
|
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.
|
|
|
|
// Returns an error of type apistatus.ObjectNotFound if the requested object is missing.
|
|
|
|
// Returns an error of type apistatus.ObjectAlreadyRemoved if the requested object has been marked as removed in shard.
|
2022-07-27 18:38:28 +00:00
|
|
|
// Returns the object.ErrObjectIsExpired if the object is presented but already expired.
|
2022-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) GetRange(prm RngPrm) (RngRes, error) {
|
2020-12-01 08:33:19 +00:00
|
|
|
var big, small storFetcher
|
|
|
|
|
|
|
|
big = func(stor *blobstor.BlobStor, _ *blobovnicza.ID) (*object.Object, error) {
|
2022-07-06 11:54:23 +00:00
|
|
|
var getRngBigPrm common.GetRangePrm
|
|
|
|
getRngBigPrm.Address = prm.addr
|
|
|
|
getRngBigPrm.Range.SetOffset(prm.off)
|
|
|
|
getRngBigPrm.Range.SetLength(prm.ln)
|
2020-12-01 08:33:19 +00:00
|
|
|
|
|
|
|
res, err := stor.GetRangeBig(getRngBigPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := object.New()
|
2022-07-06 11:54:23 +00:00
|
|
|
obj.SetPayload(res.Data)
|
2020-12-01 08:33:19 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
return obj, nil
|
2020-12-01 08:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
small = func(stor *blobstor.BlobStor, id *blobovnicza.ID) (*object.Object, error) {
|
2022-07-06 11:54:23 +00:00
|
|
|
var getRngSmallPrm common.GetRangePrm
|
|
|
|
getRngSmallPrm.Address = prm.addr
|
|
|
|
getRngSmallPrm.Range.SetOffset(prm.off)
|
|
|
|
getRngSmallPrm.Range.SetLength(prm.ln)
|
|
|
|
getRngSmallPrm.BlobovniczaID = id
|
2020-12-01 08:33:19 +00:00
|
|
|
|
|
|
|
res, err := stor.GetRangeSmall(getRngSmallPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := object.New()
|
2022-07-06 11:54:23 +00:00
|
|
|
obj.SetPayload(res.Data)
|
2020-12-01 08:33:19 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
return obj, nil
|
2020-12-01 08:33:19 +00:00
|
|
|
}
|
|
|
|
|
2022-07-29 07:54:49 +00:00
|
|
|
wc := func(c writecache.Cache) (*object.Object, error) {
|
|
|
|
res, err := c.Get(prm.addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
payload := res.Payload()
|
2022-07-06 11:54:23 +00:00
|
|
|
from := prm.off
|
|
|
|
to := from + prm.ln
|
2022-07-29 08:11:55 +00:00
|
|
|
if pLen := uint64(len(payload)); to < from || pLen < from || pLen < to {
|
2022-07-29 07:54:49 +00:00
|
|
|
return nil, apistatus.ObjectOutOfRange{}
|
|
|
|
}
|
|
|
|
|
|
|
|
obj := object.New()
|
|
|
|
obj.SetPayload(payload[from:to])
|
|
|
|
return obj, nil
|
|
|
|
}
|
|
|
|
|
2022-06-29 11:27:36 +00:00
|
|
|
skipMeta := prm.skipMeta || s.GetMode().NoMetabase()
|
2022-07-29 07:54:49 +00:00
|
|
|
obj, hasMeta, err := s.fetchObjectData(prm.addr, skipMeta, big, small, wc)
|
2020-12-01 08:33:19 +00:00
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return RngRes{
|
2022-03-04 12:57:43 +00:00
|
|
|
obj: obj,
|
|
|
|
hasMeta: hasMeta,
|
2020-12-01 08:33:19 +00:00
|
|
|
}, err
|
|
|
|
}
|