2020-12-01 08:34:38 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/pkg/tracing"
|
2023-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
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 {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2020-12-08 11:42:44 +00:00
|
|
|
raw 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
|
|
|
|
if s.GetMode().NoMetabase() {
|
|
|
|
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 {
|
|
|
|
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
|
|
|
}
|