frostfs-node/pkg/local_object_storage/shard/range.go
Evgenii Stratonikov 69e1e6ca20 [#1186] engine: Read object directly from blobstor in case of conflicts
Metabase is expected to contain actual information about objects stored
in shard. If the object is present in metabase but is missing from
blobstor, peform an additional attempt to fetch it directly without
consulting metabase. Such a situation is unexpected, so error counter
is increased for the shard which has the object in the metabase. We
don't increase error counter for the shard which has the object in
blobstor, because some garbage can be expected there. In this
implementation there is no overhead for objects which are really
missing, i.e. are not present in any metabase.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-03-04 16:07:25 +03:00

103 lines
2.4 KiB
Go

package shard
import (
"github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
)
// RngPrm groups the parameters of GetRange operation.
type RngPrm struct {
ln uint64
off uint64
addr *addressSDK.Address
}
// RngRes groups resulting values of GetRange operation.
type RngRes struct {
obj *object.Object
}
// WithAddress is a Rng option to set the address of the requested object.
//
// Option is required.
func (p *RngPrm) WithAddress(addr *addressSDK.Address) *RngPrm {
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
}
// 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
}
// GetRange reads part of an object from shard.
//
// Returns any error encountered that
// did not allow to completely read the object part.
//
// Returns ErrRangeOutOfBounds if requested object range is out of bounds.
func (s *Shard) GetRange(prm *RngPrm) (*RngRes, error) {
var big, small storFetcher
rng := objectSDK.NewRange()
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
}
obj := object.NewRaw()
obj.SetPayload(res.RangeData())
return obj.Object(), nil
}
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
}
obj := object.NewRaw()
obj.SetPayload(res.RangeData())
return obj.Object(), nil
}
obj, _, err := s.fetchObjectData(prm.addr, false, big, small)
return &RngRes{
obj: obj,
}, err
}