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-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
|
|
|
}
|
|
|
|
|
|
|
|
// WithAddress is a Rng option to set the address of the requested object.
|
|
|
|
//
|
|
|
|
// Option is required.
|
2022-05-20 18:08:59 +00:00
|
|
|
func (p *RngPrm) WithAddress(addr oid.Address) {
|
2020-12-01 08:33:19 +00:00
|
|
|
if p != nil {
|
|
|
|
p.addr = addr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithRange is a GetRange option to set range of requested payload data.
|
2022-05-20 18:08:59 +00:00
|
|
|
func (p *RngPrm) WithRange(off uint64, ln uint64) {
|
2020-12-01 08:33:19 +00:00
|
|
|
if p != nil {
|
|
|
|
p.off, p.ln = off, ln
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-04 12:57:43 +00:00
|
|
|
// WithIgnoreMeta is a Get option try to fetch object from blobstor directly,
|
|
|
|
// without accessing metabase.
|
2022-05-20 18:08:59 +00:00
|
|
|
func (p *RngPrm) WithIgnoreMeta(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-05-20 18:08:59 +00:00
|
|
|
func (s *Shard) GetRange(prm RngPrm) (*RngRes, error) {
|
2020-12-01 08:33:19 +00:00
|
|
|
var big, small storFetcher
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
rng := object.NewRange()
|
2020-12-01 08:33:19 +00:00
|
|
|
rng.SetOffset(prm.off)
|
|
|
|
rng.SetLength(prm.ln)
|
|
|
|
|
|
|
|
big = func(stor *blobstor.BlobStor, _ *blobovnicza.ID) (*object.Object, error) {
|
2022-05-23 14:15:16 +00:00
|
|
|
var getRngBigPrm blobstor.GetRangeBigPrm
|
2020-12-01 08:33:19 +00:00
|
|
|
getRngBigPrm.SetAddress(prm.addr)
|
|
|
|
getRngBigPrm.SetRange(rng)
|
|
|
|
|
|
|
|
res, err := stor.GetRangeBig(getRngBigPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := object.New()
|
2020-12-01 08:33:19 +00:00
|
|
|
obj.SetPayload(res.RangeData())
|
|
|
|
|
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-05-23 14:15:16 +00:00
|
|
|
var getRngSmallPrm blobstor.GetRangeSmallPrm
|
2020-12-01 08:33:19 +00:00
|
|
|
getRngSmallPrm.SetAddress(prm.addr)
|
|
|
|
getRngSmallPrm.SetRange(rng)
|
|
|
|
getRngSmallPrm.SetBlobovniczaID(id)
|
|
|
|
|
|
|
|
res, err := stor.GetRangeSmall(getRngSmallPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := object.New()
|
2020-12-01 08:33:19 +00:00
|
|
|
obj.SetPayload(res.RangeData())
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
return obj, nil
|
2020-12-01 08:33:19 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 12:57:43 +00:00
|
|
|
obj, hasMeta, err := s.fetchObjectData(prm.addr, prm.skipMeta, big, small)
|
2020-12-01 08:33:19 +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
|
|
|
|
}
|