2020-12-01 08:34:38 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2022-12-23 17:35:35 +00:00
|
|
|
meta "github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
objectSDK "github.com/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
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.
|
2022-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) Head(prm HeadPrm) (HeadRes, error) {
|
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
|
|
|
|
res, err = s.Get(getPrm)
|
|
|
|
obj = res.Object()
|
|
|
|
} else {
|
|
|
|
var headParams meta.GetPrm
|
|
|
|
headParams.SetAddress(prm.addr)
|
|
|
|
headParams.SetRaw(prm.raw)
|
|
|
|
|
|
|
|
var res meta.GetRes
|
|
|
|
res, err = s.metaBase.Get(headParams)
|
|
|
|
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
|
|
|
}
|