[#211] blobstor: Rename GetRange to GetRangeBig

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-24 17:15:58 +03:00 committed by Alex Vanin
parent 2ba4ebc8c9
commit 0b130150ae
4 changed files with 95 additions and 87 deletions

View file

@ -0,0 +1,57 @@
package blobstor
import (
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/pkg/errors"
)
// GetRangeBigPrm groups the parameters of GetRangeBig operation.
type GetRangeBigPrm struct {
address
rwRange
}
// GetRangeBigRes groups resulting values of GetRangeBig operation.
type GetRangeBigRes struct {
rangeData
}
// 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.
func (b *BlobStor) GetRangeBig(prm *GetRangeBigPrm) (*GetRangeBigRes, error) {
b.mtx.RLock()
defer b.mtx.RUnlock()
// get compressed object data
data, err := b.fsTree.get(prm.addr)
if err != nil {
return nil, errors.Wrap(err, "could not read object from fs tree")
}
data, err = b.decompressor(data)
if err != nil {
return nil, errors.Wrap(err, "could not decompress object data")
}
// unmarshal the object
obj := object.New()
if err := obj.Unmarshal(data); err != nil {
return nil, errors.Wrap(err, "could not unmarshal the object")
}
payload := obj.Payload()
ln, off := prm.rng.GetLength(), prm.rng.GetOffset()
if pLen := uint64(len(payload)); pLen < ln+off {
return nil, errors.Errorf("range is out-of-bounds (payload %d, off %d, ln %d)",
pLen, off, ln)
}
return &GetRangeBigRes{
rangeData: rangeData{
data: payload[off : off+ln],
},
}, nil
}

View file

@ -1,82 +0,0 @@
package blobstor
import (
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/pkg/errors"
)
// GetRangePrm groups the parameters of GetRange operation.
type GetRangePrm struct {
off, ln uint64
addr *objectSDK.Address
}
// GetRangeRes groups resulting values of GetRange operation.
type GetRangeRes struct {
rngData []byte
}
// WithAddress is a GetRange option to set the address of the requested object.
//
// Option is required.
func (p *GetRangePrm) WithAddress(addr *objectSDK.Address) *GetRangePrm {
if p != nil {
p.addr = addr
}
return p
}
// WithPayloadRange is a GetRange option to set range of requested payload data.
//
// Option is required.
func (p *GetRangePrm) WithPayloadRange(off, ln uint64) *GetRangePrm {
if p != nil {
p.off, p.ln = off, ln
}
return p
}
// RangeData returns data of the requested payload range.
func (r *GetRangeRes) RangeData() []byte {
return r.rngData
}
// GetRange reads data of object payload range from BLOB storage.
//
// Returns any error encountered that
// did not allow to completely read the object payload range.
func (b *BlobStor) GetRange(prm *GetRangePrm) (*GetRangeRes, error) {
b.mtx.RLock()
defer b.mtx.RUnlock()
// get compressed object data
data, err := b.fsTree.get(prm.addr)
if err != nil {
return nil, errors.Wrap(err, "could not read object from fs tree")
}
data, err = b.decompressor(data)
if err != nil {
return nil, errors.Wrap(err, "could not decompress object data")
}
// unmarshal the object
obj := object.New()
if err := obj.Unmarshal(data); err != nil {
return nil, errors.Wrap(err, "could not unmarshal the object")
}
payload := obj.Payload()
if pLen := uint64(len(payload)); pLen < prm.ln+prm.off {
return nil, errors.Errorf("range is out-of-bounds (payload %d, off %d, ln %d)",
pLen, prm.off, prm.ln)
}
return &GetRangeRes{
rngData: payload[prm.off : prm.off+prm.ln],
}, nil
}

View file

@ -50,3 +50,30 @@ type rwBlobovniczaID struct {
func (v *rwBlobovniczaID) SetBlobovniczaID(id *blobovnicza.ID) {
v.blobovniczaID = id
}
type roRange struct {
rng *objectSDK.Range
}
// Range returns range of the object payload.
func (r roRange) Range() *objectSDK.Range {
return r.rng
}
type rwRange struct {
roRange
}
// SetRange sets range of the object payload.
func (r *rwRange) SetRange(rng *objectSDK.Range) {
r.rng = rng
}
type rangeData struct {
data []byte
}
// RangeData returns data of the requested payload range.
func (d rangeData) RangeData() []byte {
return d.data
}

View file

@ -108,11 +108,17 @@ func (s *Shard) Get(prm *GetPrm) (*GetRes, error) {
// try to read from WriteCache
// TODO: implement
res, err := s.blobStor.GetRange(
new(blobstor.GetRangePrm).
WithAddress(prm.addr).
WithPayloadRange(prm.off, uint64(prm.ln)),
)
// form GetRangeBig parameters
getRngBigPrm := new(blobstor.GetRangeBigPrm)
getRngBigPrm.SetAddress(prm.addr)
rng := objectSDK.NewRange()
rng.SetOffset(prm.off)
rng.SetLength(uint64(prm.ln))
getRngBigPrm.SetRange(rng)
res, err := s.blobStor.GetRangeBig(getRngBigPrm)
if err != nil {
if errors.Is(err, blobstor.ErrObjectNotFound) {
err = ErrObjectNotFound