2020-11-17 12:26:03 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
2020-11-17 12:26:03 +00:00
|
|
|
"errors"
|
|
|
|
|
2023-09-13 08:25:59 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
2023-09-27 08:02:06 +00:00
|
|
|
tracingPkg "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-08-04 11:14:07 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-03-07 13:38:26 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
objectSDK "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"
|
2022-02-22 07:20:33 +00:00
|
|
|
"go.uber.org/zap"
|
2020-11-17 12:26:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetPrm groups the parameters of Get operation.
|
|
|
|
type GetPrm struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// GetRes groups the resulting values of Get operation.
|
2020-11-17 12:26:03 +00:00
|
|
|
type GetRes struct {
|
2022-03-03 14:19:05 +00:00
|
|
|
obj *objectSDK.Object
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WithAddress is a Get option to set the address of the requested object.
|
|
|
|
//
|
|
|
|
// Option is required.
|
2022-05-23 13:12:32 +00:00
|
|
|
func (p *GetPrm) WithAddress(addr oid.Address) {
|
2022-09-14 14:36:37 +00:00
|
|
|
p.addr = addr
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 10:41:12 +00:00
|
|
|
// Object returns the requested object.
|
2022-05-23 13:12:32 +00:00
|
|
|
func (r GetRes) Object() *objectSDK.Object {
|
2020-11-17 12:26:03 +00:00
|
|
|
return r.obj
|
|
|
|
}
|
|
|
|
|
2020-12-01 10:41:12 +00:00
|
|
|
// Get reads an object from local storage.
|
2020-11-17 12:26:03 +00:00
|
|
|
//
|
|
|
|
// Returns any error encountered that
|
|
|
|
// did not allow to completely read the object part.
|
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns an error of type apistatus.ObjectNotFound if the requested object is missing in local storage.
|
|
|
|
// Returns an error of type apistatus.ObjectAlreadyRemoved if the object has been marked as removed.
|
2021-11-09 15:46:12 +00:00
|
|
|
//
|
|
|
|
// Returns an error if executions are blocked (see BlockExecution).
|
2023-03-13 11:37:35 +00:00
|
|
|
func (e *StorageEngine) Get(ctx context.Context, prm GetPrm) (res GetRes, err error) {
|
2023-04-12 14:01:29 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.Get",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("address", prm.addr.EncodeToString()),
|
|
|
|
))
|
|
|
|
defer span.End()
|
2024-11-11 09:46:55 +00:00
|
|
|
defer elapsed("Get", e.metrics.AddMethodDuration)()
|
2023-04-12 14:01:29 +00:00
|
|
|
|
2021-11-10 15:00:30 +00:00
|
|
|
err = e.execIfNotBlocked(func() error {
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err = e.get(ctx, prm)
|
2021-11-09 15:46:12 +00:00
|
|
|
return err
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
func (e *StorageEngine) get(ctx context.Context, prm GetPrm) (GetRes, error) {
|
2023-08-04 11:14:07 +00:00
|
|
|
errNotFound := new(apistatus.ObjectNotFound)
|
2020-12-01 10:41:12 +00:00
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
var shPrm shard.GetPrm
|
|
|
|
shPrm.SetAddress(prm.addr)
|
2022-03-17 08:03:58 +00:00
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
it := &getShardIterator{
|
|
|
|
OutError: errNotFound,
|
|
|
|
ShardPrm: shPrm,
|
|
|
|
Address: prm.addr,
|
|
|
|
Engine: e,
|
|
|
|
}
|
2022-02-22 07:20:33 +00:00
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
it.tryGetWithMeta(ctx)
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
if it.SplitInfo != nil {
|
|
|
|
return GetRes{}, logicerr.Wrap(objectSDK.NewSplitInfoError(it.SplitInfo))
|
|
|
|
}
|
2020-11-18 07:59:47 +00:00
|
|
|
|
2024-04-22 06:43:42 +00:00
|
|
|
if it.ECInfo != nil {
|
|
|
|
return GetRes{}, logicerr.Wrap(objectSDK.NewECInfoError(it.ECInfo))
|
|
|
|
}
|
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
if it.ObjectExpired {
|
|
|
|
return GetRes{}, errNotFound
|
|
|
|
}
|
2022-07-05 04:55:46 +00:00
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
if it.Object == nil {
|
2023-08-04 11:14:07 +00:00
|
|
|
if !it.HasDegraded && it.ShardWithMeta.Shard == nil || !client.IsErrObjectNotFound(it.OutError) {
|
2023-03-30 14:32:33 +00:00
|
|
|
return GetRes{}, it.OutError
|
|
|
|
}
|
2022-07-05 04:55:46 +00:00
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
it.tryGetFromBlobstore(ctx)
|
2022-07-05 04:55:46 +00:00
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
if it.Object == nil {
|
|
|
|
return GetRes{}, it.OutError
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
2023-09-13 08:25:59 +00:00
|
|
|
if it.ShardWithMeta.Shard != nil && it.MetaError != nil {
|
2024-10-21 07:22:54 +00:00
|
|
|
e.log.Warn(ctx, logs.ShardMetaInfoPresentButObjectNotFound,
|
2023-09-13 08:25:59 +00:00
|
|
|
zap.Stringer("shard_id", it.ShardWithMeta.ID()),
|
2024-12-13 08:44:56 +00:00
|
|
|
zap.Error(it.MetaError),
|
2023-09-27 08:02:06 +00:00
|
|
|
zap.Stringer("address", prm.addr),
|
|
|
|
zap.String("trace_id", tracingPkg.GetTraceID(ctx)))
|
2023-03-30 14:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
return GetRes{
|
|
|
|
obj: it.Object,
|
|
|
|
}, nil
|
|
|
|
}
|
2020-12-01 10:41:12 +00:00
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
type getShardIterator struct {
|
|
|
|
Object *objectSDK.Object
|
|
|
|
SplitInfo *objectSDK.SplitInfo
|
2024-04-22 06:43:42 +00:00
|
|
|
ECInfo *objectSDK.ECInfo
|
2023-03-30 14:32:33 +00:00
|
|
|
OutError error
|
|
|
|
ShardWithMeta hashedShard
|
|
|
|
MetaError error
|
|
|
|
HasDegraded bool
|
|
|
|
ObjectExpired bool
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
ShardPrm shard.GetPrm
|
|
|
|
Address oid.Address
|
|
|
|
Engine *StorageEngine
|
2021-04-14 09:05:20 +00:00
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
splitInfoErr *objectSDK.SplitInfoError
|
2024-04-22 06:43:42 +00:00
|
|
|
ecInfoErr *objectSDK.ECInfoError
|
2023-03-30 14:32:33 +00:00
|
|
|
}
|
2023-01-25 15:48:13 +00:00
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
func (i *getShardIterator) tryGetWithMeta(ctx context.Context) {
|
2023-03-30 14:32:33 +00:00
|
|
|
i.Engine.iterateOverSortedShards(i.Address, func(_ int, sh hashedShard) (stop bool) {
|
|
|
|
noMeta := sh.GetMode().NoMetabase()
|
|
|
|
i.ShardPrm.SetIgnoreMeta(noMeta)
|
|
|
|
|
|
|
|
i.HasDegraded = i.HasDegraded || noMeta
|
2022-02-22 07:20:33 +00:00
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err := sh.Get(ctx, i.ShardPrm)
|
2023-03-30 14:32:33 +00:00
|
|
|
if err == nil {
|
|
|
|
i.Object = res.Object()
|
|
|
|
return true
|
|
|
|
}
|
2022-02-22 07:20:33 +00:00
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
if res.HasMeta() {
|
|
|
|
i.ShardWithMeta = sh
|
|
|
|
i.MetaError = err
|
|
|
|
}
|
|
|
|
switch {
|
2023-08-04 11:14:07 +00:00
|
|
|
case client.IsErrObjectNotFound(err):
|
2023-03-30 14:32:33 +00:00
|
|
|
return false // ignore, go to next shard
|
|
|
|
case errors.As(err, &i.splitInfoErr):
|
|
|
|
if i.SplitInfo == nil {
|
|
|
|
i.SplitInfo = objectSDK.NewSplitInfo()
|
2022-07-05 04:55:46 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 14:32:33 +00:00
|
|
|
util.MergeSplitInfo(i.splitInfoErr.SplitInfo(), i.SplitInfo)
|
|
|
|
|
|
|
|
_, withLink := i.SplitInfo.Link()
|
|
|
|
_, withLast := i.SplitInfo.LastPart()
|
|
|
|
|
|
|
|
// stop iterating over shards if SplitInfo structure is complete
|
|
|
|
return withLink && withLast
|
2024-04-22 06:43:42 +00:00
|
|
|
case errors.As(err, &i.ecInfoErr):
|
|
|
|
if i.ECInfo == nil {
|
|
|
|
i.ECInfo = objectSDK.NewECInfo()
|
|
|
|
}
|
|
|
|
|
|
|
|
util.MergeECInfo(i.ecInfoErr.ECInfo(), i.ECInfo)
|
|
|
|
// stop iterating over shards if ECInfo structure is complete
|
|
|
|
return len(i.ECInfo.Chunks) == int(i.ECInfo.Chunks[0].Total)
|
2023-08-04 11:14:07 +00:00
|
|
|
case client.IsErrObjectAlreadyRemoved(err):
|
2023-03-30 14:32:33 +00:00
|
|
|
i.OutError = err
|
|
|
|
return true // stop, return it back
|
|
|
|
case shard.IsErrObjectExpired(err):
|
|
|
|
// object is found but should not be returned
|
|
|
|
i.ObjectExpired = true
|
|
|
|
return true
|
|
|
|
default:
|
2024-10-21 13:27:28 +00:00
|
|
|
i.Engine.reportShardError(ctx, sh, "could not get object from shard", err, zap.Stringer("address", i.Address))
|
2023-03-30 14:32:33 +00:00
|
|
|
return false
|
2022-02-22 07:20:33 +00:00
|
|
|
}
|
2023-03-30 14:32:33 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
func (i *getShardIterator) tryGetFromBlobstore(ctx context.Context) {
|
2023-03-30 14:32:33 +00:00
|
|
|
// If the object is not found but is present in metabase,
|
|
|
|
// try to fetch it from blobstor directly. If it is found in any
|
|
|
|
// blobstor, increase the error counter for the shard which contains the meta.
|
|
|
|
i.ShardPrm.SetIgnoreMeta(true)
|
|
|
|
|
|
|
|
i.Engine.iterateOverSortedShards(i.Address, func(_ int, sh hashedShard) (stop bool) {
|
|
|
|
if sh.GetMode().NoMetabase() {
|
|
|
|
// Already visited.
|
|
|
|
return false
|
2022-07-05 04:55:46 +00:00
|
|
|
}
|
2020-11-17 12:26:03 +00:00
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err := sh.Get(ctx, i.ShardPrm)
|
2023-03-30 14:32:33 +00:00
|
|
|
i.Object = res.Object()
|
|
|
|
return err == nil
|
|
|
|
})
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
2020-11-19 08:15:49 +00:00
|
|
|
|
|
|
|
// Get reads object from local storage by provided address.
|
2023-03-13 11:37:35 +00:00
|
|
|
func Get(ctx context.Context, storage *StorageEngine, addr oid.Address) (*objectSDK.Object, error) {
|
2022-05-23 13:12:32 +00:00
|
|
|
var getPrm GetPrm
|
|
|
|
getPrm.WithAddress(addr)
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err := storage.Get(ctx, getPrm)
|
2020-11-19 08:15:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.Object(), nil
|
|
|
|
}
|