From e2f13d03d7c25b7399e817642a9532eff0bd8be2 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 6 Apr 2023 12:18:58 +0300 Subject: [PATCH] [#222] auditsvc: Refactor PoR audit Resolve funlen linter for Context.checkStorageGroupPoR method. Signed-off-by: Dmitrii Stepanov --- pkg/services/audit/auditor/por.go | 43 +++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/pkg/services/audit/auditor/por.go b/pkg/services/audit/auditor/por.go index 6011217f..aebc25c6 100644 --- a/pkg/services/audit/auditor/por.go +++ b/pkg/services/audit/auditor/por.go @@ -36,7 +36,6 @@ func (c *Context) executePoR(ctx context.Context) { c.report.SetPoRCounters(c.porRequests.Load(), c.porRetries.Load()) } -// nolint: funlen func (c *Context) checkStorageGroupPoR(ctx context.Context, sgID oid.ID, sg storagegroupSDK.StorageGroup) { members := sg.Members() c.updateSGInfo(sgID, members) @@ -55,22 +54,11 @@ func (c *Context) checkStorageGroupPoR(ctx context.Context, sgID oid.ID, sg stor homomorphicHashingEnabled := !containerSDK.IsHomomorphicHashingDisabled(c.task.ContainerStructure()) for i := range members { - objectPlacement, err := c.buildPlacement(members[i]) - if err != nil { - c.log.Info("can't build placement for storage group member", - zap.Stringer("sg", sgID), - zap.String("member_id", members[i].String()), - ) - + flat, ok := c.getShuffledNodes(members[i], sgID) + if !ok { continue } - flat := placement.FlattenNodes(objectPlacement) - - rand.Shuffle(len(flat), func(i, j int) { - flat[i], flat[j] = flat[j], flat[i] - }) - getHeaderPrm.OID = members[i] for j := range flat { @@ -126,8 +114,12 @@ func (c *Context) checkStorageGroupPoR(ctx context.Context, sgID oid.ID, sg stor cs, _ := sg.ValidationDataHash() tzCheck := !homomorphicHashingEnabled || bytes.Equal(tzHash, cs.Value()) + c.writeCheckReport(sizeCheck, tzCheck, sgID, sg, totalSize) +} + +func (c *Context) writeCheckReport(sizeCheck, tzCheck bool, sgID oid.ID, sg storagegroupSDK.StorageGroup, totalSize uint64) { if sizeCheck && tzCheck { - c.report.PassedPoR(sgID) // write report + c.report.PassedPoR(sgID) } else { if !sizeCheck { c.log.Debug("storage group size check failed", @@ -139,6 +131,25 @@ func (c *Context) checkStorageGroupPoR(ctx context.Context, sgID oid.ID, sg stor c.log.Debug("storage group tz hash check failed") } - c.report.FailedPoR(sgID) // write report + c.report.FailedPoR(sgID) } } + +func (c *Context) getShuffledNodes(member oid.ID, sgID oid.ID) ([]netmap.NodeInfo, bool) { + objectPlacement, err := c.buildPlacement(member) + if err != nil { + c.log.Info("can't build placement for storage group member", + zap.Stringer("sg", sgID), + zap.String("member_id", member.String()), + ) + + return nil, false + } + + flat := placement.FlattenNodes(objectPlacement) + + rand.Shuffle(len(flat), func(i, j int) { + flat[i], flat[j] = flat[j], flat[i] + }) + return flat, true +}