forked from TrueCloudLab/frostfs-node
[#238] engine: Support raw flag in Head method
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
da42ee3a26
commit
91d8e0a4de
1 changed files with 28 additions and 1 deletions
|
@ -11,6 +11,7 @@ import (
|
||||||
// HeadPrm groups the parameters of Head operation.
|
// HeadPrm groups the parameters of Head operation.
|
||||||
type HeadPrm struct {
|
type HeadPrm struct {
|
||||||
addr *objectSDK.Address
|
addr *objectSDK.Address
|
||||||
|
raw bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// HeadRes groups resulting values of Head operation.
|
// HeadRes groups resulting values of Head operation.
|
||||||
|
@ -29,6 +30,17 @@ func (p *HeadPrm) WithAddress(addr *objectSDK.Address) *HeadPrm {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithRaw is a Head option to set raw flag value. If flag is unset, then Head
|
||||||
|
// returns header of virtual object, otherwise it returns SplitInfo of virtual
|
||||||
|
// object.
|
||||||
|
func (p *HeadPrm) WithRaw(raw bool) *HeadPrm {
|
||||||
|
if p != nil {
|
||||||
|
p.raw = raw
|
||||||
|
}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
// Header returns the requested object header.
|
// Header returns the requested object header.
|
||||||
//
|
//
|
||||||
// Instance has empty payload.
|
// Instance has empty payload.
|
||||||
|
@ -51,7 +63,8 @@ func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) {
|
||||||
)
|
)
|
||||||
|
|
||||||
shPrm := new(shard.HeadPrm).
|
shPrm := new(shard.HeadPrm).
|
||||||
WithAddress(prm.addr)
|
WithAddress(prm.addr).
|
||||||
|
WithRaw(prm.raw)
|
||||||
|
|
||||||
e.iterateOverSortedShards(prm.addr, func(_ int, sh *shard.Shard) (stop bool) {
|
e.iterateOverSortedShards(prm.addr, func(_ int, sh *shard.Shard) (stop bool) {
|
||||||
res, err := sh.Head(shPrm)
|
res, err := sh.Head(shPrm)
|
||||||
|
@ -102,3 +115,17 @@ func Head(storage *StorageEngine, addr *objectSDK.Address) (*object.Object, erro
|
||||||
|
|
||||||
return res.Header(), nil
|
return res.Header(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HeadRaw reads object header from local storage by provided address and raw
|
||||||
|
// flag.
|
||||||
|
func HeadRaw(storage *StorageEngine, addr *objectSDK.Address, raw bool) (*object.Object, error) {
|
||||||
|
res, err := storage.Head(new(HeadPrm).
|
||||||
|
WithAddress(addr).
|
||||||
|
WithRaw(raw),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.Header(), nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue