[#1103] node: Reduce amount of lines for method StorageEngine.head
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
700e891b85
commit
167c52a1a9
1 changed files with 5 additions and 18 deletions
|
@ -67,20 +67,17 @@ func (e *StorageEngine) Head(ctx context.Context, prm HeadPrm) (res HeadRes, err
|
|||
func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error) {
|
||||
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.head")
|
||||
defer span.End()
|
||||
|
||||
if e.metrics != nil {
|
||||
defer elapsed("Head", e.metrics.AddMethodDuration)()
|
||||
}
|
||||
|
||||
var (
|
||||
head *objectSDK.Object
|
||||
siErr *objectSDK.SplitInfoError
|
||||
outSI *objectSDK.SplitInfo
|
||||
|
||||
head *objectSDK.Object
|
||||
siErr *objectSDK.SplitInfoError
|
||||
outSI *objectSDK.SplitInfo
|
||||
outError error = new(apistatus.ObjectNotFound)
|
||||
shPrm shard.HeadPrm
|
||||
)
|
||||
|
||||
var shPrm shard.HeadPrm
|
||||
shPrm.SetAddress(prm.addr)
|
||||
shPrm.SetRaw(prm.raw)
|
||||
|
||||
|
@ -94,44 +91,34 @@ func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error)
|
|||
if outSI == nil {
|
||||
outSI = objectSDK.NewSplitInfo()
|
||||
}
|
||||
|
||||
util.MergeSplitInfo(siErr.SplitInfo(), outSI)
|
||||
|
||||
_, withLink := outSI.Link()
|
||||
_, withLast := outSI.LastPart()
|
||||
|
||||
// stop iterating over shards if SplitInfo structure is complete
|
||||
if withLink && withLast {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
case client.IsErrObjectAlreadyRemoved(err):
|
||||
outError = err
|
||||
|
||||
return true // stop, return it back
|
||||
case shard.IsErrObjectExpired(err):
|
||||
// object is found but should not
|
||||
// be returned
|
||||
outError = new(apistatus.ObjectNotFound)
|
||||
|
||||
return true
|
||||
default:
|
||||
e.reportShardError(sh, "could not head object from shard", err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
head = res.Object()
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
if outSI != nil {
|
||||
return HeadRes{}, logicerr.Wrap(objectSDK.NewSplitInfoError(outSI))
|
||||
}
|
||||
|
||||
if head == nil {
|
||||
} else if head == nil {
|
||||
return HeadRes{}, outError
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue