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-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2020-12-01 08:33:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// RngPrm groups the parameters of GetRange operation.
|
|
|
|
type RngPrm struct {
|
|
|
|
ln uint64
|
|
|
|
|
|
|
|
off uint64
|
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
addr *addressSDK.Address
|
2022-03-04 12:57:43 +00:00
|
|
|
|
|
|
|
skipMeta bool
|
2020-12-01 08:33:19 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 13:29:46 +00:00
|
|
|
// RngRes groups 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-01-26 12:11:13 +00:00
|
|
|
func (p *RngPrm) WithAddress(addr *addressSDK.Address) *RngPrm {
|
2020-12-01 08:33:19 +00:00
|
|
|
if p != nil {
|
|
|
|
p.addr = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithRange is a GetRange option to set range of requested payload data.
|
|
|
|
func (p *RngPrm) WithRange(off uint64, ln uint64) *RngPrm {
|
|
|
|
if p != nil {
|
|
|
|
p.off, p.ln = off, ln
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2022-03-04 12:57:43 +00:00
|
|
|
// WithIgnoreMeta is a Get option try to fetch object from blobstor directly,
|
|
|
|
// without accessing metabase.
|
|
|
|
func (p *RngPrm) WithIgnoreMeta(ignore bool) *RngPrm {
|
|
|
|
p.skipMeta = ignore
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-12-01 08:33:19 +00:00
|
|
|
// Object returns the requested object part.
|
|
|
|
//
|
|
|
|
// Instance payload contains the requested range of the original object.
|
|
|
|
func (r *RngRes) Object() *object.Object {
|
|
|
|
return r.obj
|
|
|
|
}
|
|
|
|
|
2022-03-04 12:57:43 +00:00
|
|
|
// HasMeta returns true if info about the object was found in the metabase.
|
|
|
|
func (r *RngRes) HasMeta() bool {
|
|
|
|
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
|
|
|
//
|
|
|
|
// Returns ErrRangeOutOfBounds if requested object range is out of bounds.
|
2020-12-01 08:33:19 +00:00
|
|
|
func (s *Shard) GetRange(prm *RngPrm) (*RngRes, error) {
|
|
|
|
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) {
|
|
|
|
getRngBigPrm := new(blobstor.GetRangeBigPrm)
|
|
|
|
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) {
|
|
|
|
getRngSmallPrm := new(blobstor.GetRangeSmallPrm)
|
|
|
|
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
|
|
|
|
}
|