forked from TrueCloudLab/frostfs-node
[#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,7 +67,6 @@ func (e *StorageEngine) Head(ctx context.Context, prm HeadPrm) (res HeadRes, err
|
||||||
func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error) {
|
func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error) {
|
||||||
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.head")
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.head")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
if e.metrics != nil {
|
if e.metrics != nil {
|
||||||
defer elapsed("Head", e.metrics.AddMethodDuration)()
|
defer elapsed("Head", e.metrics.AddMethodDuration)()
|
||||||
}
|
}
|
||||||
|
@ -76,11 +75,9 @@ func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error)
|
||||||
head *objectSDK.Object
|
head *objectSDK.Object
|
||||||
siErr *objectSDK.SplitInfoError
|
siErr *objectSDK.SplitInfoError
|
||||||
outSI *objectSDK.SplitInfo
|
outSI *objectSDK.SplitInfo
|
||||||
|
|
||||||
outError error = new(apistatus.ObjectNotFound)
|
outError error = new(apistatus.ObjectNotFound)
|
||||||
|
shPrm shard.HeadPrm
|
||||||
)
|
)
|
||||||
|
|
||||||
var shPrm shard.HeadPrm
|
|
||||||
shPrm.SetAddress(prm.addr)
|
shPrm.SetAddress(prm.addr)
|
||||||
shPrm.SetRaw(prm.raw)
|
shPrm.SetRaw(prm.raw)
|
||||||
|
|
||||||
|
@ -94,44 +91,34 @@ func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error)
|
||||||
if outSI == nil {
|
if outSI == nil {
|
||||||
outSI = objectSDK.NewSplitInfo()
|
outSI = objectSDK.NewSplitInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
util.MergeSplitInfo(siErr.SplitInfo(), outSI)
|
util.MergeSplitInfo(siErr.SplitInfo(), outSI)
|
||||||
|
|
||||||
_, withLink := outSI.Link()
|
_, withLink := outSI.Link()
|
||||||
_, withLast := outSI.LastPart()
|
_, withLast := outSI.LastPart()
|
||||||
|
|
||||||
// stop iterating over shards if SplitInfo structure is complete
|
// stop iterating over shards if SplitInfo structure is complete
|
||||||
if withLink && withLast {
|
if withLink && withLast {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
case client.IsErrObjectAlreadyRemoved(err):
|
case client.IsErrObjectAlreadyRemoved(err):
|
||||||
outError = err
|
outError = err
|
||||||
|
|
||||||
return true // stop, return it back
|
return true // stop, return it back
|
||||||
case shard.IsErrObjectExpired(err):
|
case shard.IsErrObjectExpired(err):
|
||||||
// object is found but should not
|
// object is found but should not
|
||||||
// be returned
|
// be returned
|
||||||
outError = new(apistatus.ObjectNotFound)
|
outError = new(apistatus.ObjectNotFound)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
e.reportShardError(sh, "could not head object from shard", err)
|
e.reportShardError(sh, "could not head object from shard", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
head = res.Object()
|
head = res.Object()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
if outSI != nil {
|
if outSI != nil {
|
||||||
return HeadRes{}, logicerr.Wrap(objectSDK.NewSplitInfoError(outSI))
|
return HeadRes{}, logicerr.Wrap(objectSDK.NewSplitInfoError(outSI))
|
||||||
}
|
} else if head == nil {
|
||||||
|
|
||||||
if head == nil {
|
|
||||||
return HeadRes{}, outError
|
return HeadRes{}, outError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue