2020-12-01 08:34:38 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2024-09-03 09:18:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2024-09-03 09:18:10 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2023-03-07 13:38:26 +00:00
|
|
|
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"
|
2020-12-01 08:34:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// HeadPrm groups the parameters of Head operation.
|
|
|
|
type HeadPrm struct {
|
2024-04-17 11:15:08 +00:00
|
|
|
addr oid.Address
|
|
|
|
raw bool
|
|
|
|
ShardLooksBad bool
|
2020-12-01 08:34:38 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// HeadRes groups the resulting values of Head operation.
|
2020-12-01 08:34:38 +00:00
|
|
|
type HeadRes struct {
|
2022-03-03 14:19:05 +00:00
|
|
|
obj *objectSDK.Object
|
2020-12-01 08:34:38 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetAddress is a Head option to set the address of the requested object.
|
2020-12-01 08:34:38 +00:00
|
|
|
//
|
|
|
|
// Option is required.
|
2022-07-13 12:43:04 +00:00
|
|
|
func (p *HeadPrm) SetAddress(addr oid.Address) {
|
|
|
|
p.addr = addr
|
2020-12-01 08:34:38 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
// SetRaw is a Head option to set raw flag value. If flag is unset, then Head
|
2020-12-08 11:42:44 +00:00
|
|
|
// returns header of virtual object, otherwise it returns SplitInfo of virtual
|
|
|
|
// object.
|
2022-07-13 12:43:04 +00:00
|
|
|
func (p *HeadPrm) SetRaw(raw bool) {
|
|
|
|
p.raw = raw
|
2020-12-08 11:42:44 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 08:34:38 +00:00
|
|
|
// Object returns the requested object header.
|
2022-05-31 11:50:39 +00:00
|
|
|
func (r HeadRes) Object() *objectSDK.Object {
|
2020-12-01 08:34:38 +00:00
|
|
|
return r.obj
|
|
|
|
}
|
|
|
|
|
|
|
|
// Head reads header of the object from the shard.
|
|
|
|
//
|
|
|
|
// Returns any error encountered.
|
2022-03-17 08:03:58 +00:00
|
|
|
//
|
2022-03-17 13:26:17 +00:00
|
|
|
// Returns an error of type apistatus.ObjectNotFound if object is missing in Shard.
|
2022-04-21 11:28:05 +00:00
|
|
|
// 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) Head(ctx context.Context, prm HeadPrm) (HeadRes, error) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "Shard.Head",
|
|
|
|
trace.WithAttributes(
|
|
|
|
attribute.String("shard_id", s.ID().String()),
|
|
|
|
attribute.String("address", prm.addr.EncodeToString()),
|
|
|
|
attribute.Bool("raw", prm.raw),
|
|
|
|
))
|
|
|
|
defer span.End()
|
|
|
|
|
2022-06-29 11:27:36 +00:00
|
|
|
var obj *objectSDK.Object
|
|
|
|
var err error
|
2024-04-17 11:15:08 +00:00
|
|
|
mode := s.GetMode()
|
|
|
|
if mode.NoMetabase() || (mode.ReadOnly() && prm.ShardLooksBad) {
|
2022-06-29 11:27:36 +00:00
|
|
|
var getPrm GetPrm
|
|
|
|
getPrm.SetAddress(prm.addr)
|
|
|
|
getPrm.SetIgnoreMeta(true)
|
2020-12-08 11:42:44 +00:00
|
|
|
|
2022-06-29 11:27:36 +00:00
|
|
|
var res GetRes
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err = s.Get(ctx, getPrm)
|
2022-06-29 11:27:36 +00:00
|
|
|
obj = res.Object()
|
|
|
|
} else {
|
2024-09-03 09:18:10 +00:00
|
|
|
s.m.RLock()
|
|
|
|
defer s.m.RUnlock()
|
|
|
|
if s.info.EvacuationInProgress {
|
|
|
|
return HeadRes{}, logicerr.Wrap(new(apistatus.ObjectNotFound))
|
|
|
|
}
|
2022-06-29 11:27:36 +00:00
|
|
|
var headParams meta.GetPrm
|
|
|
|
headParams.SetAddress(prm.addr)
|
|
|
|
headParams.SetRaw(prm.raw)
|
|
|
|
|
|
|
|
var res meta.GetRes
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err = s.metaBase.Get(ctx, headParams)
|
2022-06-29 11:27:36 +00:00
|
|
|
obj = res.Header()
|
2021-08-31 11:04:58 +00:00
|
|
|
}
|
2020-12-01 08:34:38 +00:00
|
|
|
|
2022-05-31 11:50:39 +00:00
|
|
|
return HeadRes{
|
2022-06-29 11:27:36 +00:00
|
|
|
obj: obj,
|
|
|
|
}, err
|
2020-12-01 08:34:38 +00:00
|
|
|
}
|