2020-12-01 08:33:19 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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-10-26 12:23:12 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/util/logicerr"
|
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) {
|
2022-07-06 14:09:50 +00:00
|
|
|
cb := func(stor *blobstor.BlobStor, id []byte) (*object.Object, error) {
|
2022-07-06 12:39:35 +00:00
|
|
|
var getRngPrm common.GetRangePrm
|
|
|
|
getRngPrm.Address = prm.addr
|
|
|
|
getRngPrm.Range.SetOffset(prm.off)
|
|
|
|
getRngPrm.Range.SetLength(prm.ln)
|
2022-07-06 14:09:50 +00:00
|
|
|
getRngPrm.StorageID = id
|
2022-07-06 12:39:35 +00:00
|
|
|
|
|
|
|
res, err := stor.GetRange(getRngPrm)
|
2020-12-01 08:33:19 +00:00
|
|
|
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-10-26 12:23:12 +00:00
|
|
|
return nil, logicerr.Wrap(apistatus.ObjectOutOfRange{})
|
2022-07-29 07:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-06 12:39:35 +00:00
|
|
|
obj, hasMeta, err := s.fetchObjectData(prm.addr, skipMeta, cb, 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
|
|
|
|
}
|