2020-12-01 08:34:38 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
2021-08-31 11:04:58 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2022-03-17 08:03:58 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
2022-03-03 14:19:05 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-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-05-31 11:50:39 +00:00
|
|
|
func (s *Shard) Head(prm HeadPrm) (HeadRes, error) {
|
2021-08-31 11:04:58 +00:00
|
|
|
// object can be saved in write-cache (if enabled) or in metabase
|
|
|
|
|
|
|
|
if s.hasWriteCache() {
|
|
|
|
// try to read header from write-cache
|
|
|
|
header, err := s.writeCache.Head(prm.addr)
|
|
|
|
if err == nil {
|
2022-05-31 11:50:39 +00:00
|
|
|
return HeadRes{
|
2021-08-31 11:04:58 +00:00
|
|
|
obj: header,
|
|
|
|
}, nil
|
2022-03-17 08:03:58 +00:00
|
|
|
} else if !writecache.IsErrNotFound(err) {
|
2021-08-31 11:04:58 +00:00
|
|
|
// in this case we think that object is presented in write-cache, but corrupted
|
2022-05-31 11:50:39 +00:00
|
|
|
return HeadRes{}, fmt.Errorf("could not read header from write-cache: %w", err)
|
2021-08-31 11:04:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise object seems to be flushed to metabase
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|