2020-12-01 08:33:19 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/pkg/tracing"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2023-03-13 11:37:35 +00:00
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
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.
|
2023-03-13 11:37:35 +00:00
|
|
|
func (s *Shard) GetRange(ctx context.Context, prm RngPrm) (RngRes, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.GetRange",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("address", prm.addr.EncodeToString()),
|
|
|
|
attribute.Bool("skip_meta", prm.skipMeta),
|
|
|
|
attribute.String("offset", strconv.FormatUint(prm.off, 10)),
|
|
|
|
attribute.String("length", strconv.FormatUint(prm.ln, 10)),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2022-12-07 17:42:35 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
|
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
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err := stor.GetRange(ctx, 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) {
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err := c.Get(ctx, prm.addr)
|
2022-07-29 07:54:49 +00:00
|
|
|
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-12-07 17:42:35 +00:00
|
|
|
skipMeta := prm.skipMeta || s.info.Mode.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
|
|
|
|
}
|