From a153e040cbee1a1574cb32bd56e27ea6afb2cdac Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 1 Jul 2022 21:45:18 +0300 Subject: [PATCH] [#1402] ir: Do not use map for combining SG ID and SG object Also, add corresponding structure for that. Signed-off-by: Pavel Karpy --- pkg/core/storagegroup/storagegroup.go | 30 +++++++++++++++++++++-- pkg/innerring/processors/audit/process.go | 11 ++++++--- pkg/services/audit/auditor/por.go | 4 +-- pkg/services/audit/task.go | 9 +++---- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/pkg/core/storagegroup/storagegroup.go b/pkg/core/storagegroup/storagegroup.go index 06ab6ad3f..73c9e90d1 100644 --- a/pkg/core/storagegroup/storagegroup.go +++ b/pkg/core/storagegroup/storagegroup.go @@ -4,9 +4,9 @@ import ( "context" "github.com/nspcc-dev/neofs-node/pkg/core/client" - "github.com/nspcc-dev/neofs-sdk-go/container/id" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/netmap" - "github.com/nspcc-dev/neofs-sdk-go/object/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/storagegroup" ) @@ -46,3 +46,29 @@ type SGSource interface { // container and netmap state. GetSG(GetSGPrm) (*storagegroup.StorageGroup, error) } + +// StorageGroup combines storage group object ID and its structure. +type StorageGroup struct { + id oid.ID + sg storagegroup.StorageGroup +} + +// ID returns object ID of the storage group. +func (s StorageGroup) ID() oid.ID { + return s.id +} + +// SetID sets an object ID of the storage group. +func (s *StorageGroup) SetID(id oid.ID) { + s.id = id +} + +// StorageGroup returns the storage group descriptor. +func (s StorageGroup) StorageGroup() storagegroup.StorageGroup { + return s.sg +} + +// SetStorageGroup sets a storage group descriptor. +func (s *StorageGroup) SetStorageGroup(sg storagegroup.StorageGroup) { + s.sg = sg +} diff --git a/pkg/innerring/processors/audit/process.go b/pkg/innerring/processors/audit/process.go index 29596de52..091299300 100644 --- a/pkg/innerring/processors/audit/process.go +++ b/pkg/innerring/processors/audit/process.go @@ -15,7 +15,6 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/netmap" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" - storagegroupSDK "github.com/nspcc-dev/neofs-sdk-go/storagegroup" "go.uber.org/zap" ) @@ -172,8 +171,9 @@ func (ap *Processor) findStorageGroups(cnr cid.ID, shuffled netmapcore.Nodes) [] } func (ap *Processor) filterExpiredSG(cid cid.ID, sgIDs []oid.ID, - cnr [][]netmap.NodeInfo, nm netmap.NetMap) map[oid.ID]storagegroupSDK.StorageGroup { - sgs := make(map[oid.ID]storagegroupSDK.StorageGroup, len(sgIDs)) + cnr [][]netmap.NodeInfo, nm netmap.NetMap) []storagegroup.StorageGroup { + sgs := make([]storagegroup.StorageGroup, 0, len(sgIDs)) + var coreSG storagegroup.StorageGroup var getSGPrm storagegroup.GetSGPrm getSGPrm.CID = cid @@ -202,7 +202,10 @@ func (ap *Processor) filterExpiredSG(cid cid.ID, sgIDs []oid.ID, // filter expired epochs if sg.ExpirationEpoch() > ap.epochSrc.EpochCounter() { - sgs[sgID] = *sg + coreSG.SetID(sgID) + coreSG.SetStorageGroup(*sg) + + sgs = append(sgs, coreSG) } } diff --git a/pkg/services/audit/auditor/por.go b/pkg/services/audit/auditor/por.go index e5f0a2d54..d07fd0aef 100644 --- a/pkg/services/audit/auditor/por.go +++ b/pkg/services/audit/auditor/por.go @@ -17,11 +17,11 @@ func (c *Context) executePoR() { wg := new(sync.WaitGroup) sgs := c.task.StorageGroupList() - for id, sg := range sgs { + for _, sg := range sgs { wg.Add(1) if err := c.porWorkerPool.Submit(func() { - c.checkStorageGroupPoR(id, sg) + c.checkStorageGroupPoR(sg.ID(), sg.StorageGroup()) wg.Done() }); err != nil { wg.Done() diff --git a/pkg/services/audit/task.go b/pkg/services/audit/task.go index d5832947f..b45c09441 100644 --- a/pkg/services/audit/task.go +++ b/pkg/services/audit/task.go @@ -3,11 +3,10 @@ package audit import ( "context" + "github.com/nspcc-dev/neofs-node/pkg/core/storagegroup" "github.com/nspcc-dev/neofs-sdk-go/container" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/netmap" - oid "github.com/nspcc-dev/neofs-sdk-go/object/id" - storagegroupSDK "github.com/nspcc-dev/neofs-sdk-go/storagegroup" ) // Task groups groups the container audit parameters. @@ -24,7 +23,7 @@ type Task struct { cnrNodes [][]netmap.NodeInfo - sgList map[oid.ID]storagegroupSDK.StorageGroup + sgList []storagegroup.StorageGroup } // WithReporter sets audit report writer. @@ -112,7 +111,7 @@ func (t *Task) ContainerNodes() [][]netmap.NodeInfo { } // WithStorageGroupList sets a list of storage groups from container under audit. -func (t *Task) WithStorageGroupList(sgList map[oid.ID]storagegroupSDK.StorageGroup) *Task { +func (t *Task) WithStorageGroupList(sgList []storagegroup.StorageGroup) *Task { if t != nil { t.sgList = sgList } @@ -121,6 +120,6 @@ func (t *Task) WithStorageGroupList(sgList map[oid.ID]storagegroupSDK.StorageGro } // StorageGroupList returns list of storage groups from container under audit. -func (t *Task) StorageGroupList() map[oid.ID]storagegroupSDK.StorageGroup { +func (t *Task) StorageGroupList() []storagegroup.StorageGroup { return t.sgList }