From ae86cda58c35d01092c895b9d053877ac0c02938 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 6 Apr 2023 13:41:45 +0300 Subject: [PATCH] [#223] sg: Refactor storage group parameters Resolve containedctx linter for SearchSGPrm and GetSGPrm structs. Signed-off-by: Dmitrii Stepanov --- pkg/core/storagegroup/storagegroup.go | 10 ++-------- pkg/innerring/processors/audit/process.go | 6 ++---- pkg/innerring/rpc.go | 8 ++++---- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/pkg/core/storagegroup/storagegroup.go b/pkg/core/storagegroup/storagegroup.go index f4e584134b..b16e5c61a9 100644 --- a/pkg/core/storagegroup/storagegroup.go +++ b/pkg/core/storagegroup/storagegroup.go @@ -11,10 +11,7 @@ import ( ) // SearchSGPrm groups the parameters which are formed by Processor to search the storage group objects. -// nolint: containedctx type SearchSGPrm struct { - Context context.Context - Container cid.ID NodeInfo client.NodeInfo @@ -26,10 +23,7 @@ type SearchSGDst struct { } // GetSGPrm groups parameter of GetSG operation. -// nolint: containedctx type GetSGPrm struct { - Context context.Context - OID oid.ID CID cid.ID @@ -42,11 +36,11 @@ type SGSource interface { // ListSG must list storage group objects in the container. Formed list must be written to destination. // // Must return any error encountered which did not allow to form the list. - ListSG(*SearchSGDst, SearchSGPrm) error + ListSG(context.Context, *SearchSGDst, SearchSGPrm) error // GetSG must return storage group object for the provided CID, OID, // container and netmap state. - GetSG(GetSGPrm) (*storagegroup.StorageGroup, error) + GetSG(context.Context, GetSGPrm) (*storagegroup.StorageGroup, error) } // StorageGroup combines storage group object ID and its structure. diff --git a/pkg/innerring/processors/audit/process.go b/pkg/innerring/processors/audit/process.go index ecfc407bea..656927816e 100644 --- a/pkg/innerring/processors/audit/process.go +++ b/pkg/innerring/processors/audit/process.go @@ -153,12 +153,11 @@ func (ap *Processor) findStorageGroups(cnr cid.ID, shuffled netmapcore.Nodes) [] ctx, cancel := context.WithTimeout(context.Background(), ap.searchTimeout) - prm.Context = ctx prm.NodeInfo = info var dst storagegroup.SearchSGDst - err = ap.sgSrc.ListSG(&dst, prm) + err = ap.sgSrc.ListSG(ctx, &dst, prm) cancel() @@ -189,9 +188,8 @@ func (ap *Processor) filterExpiredSG(cid cid.ID, sgIDs []oid.ID, ctx, cancel := context.WithTimeout(context.Background(), ap.searchTimeout) getSGPrm.OID = sgID - getSGPrm.Context = ctx - sg, err := ap.sgSrc.GetSG(getSGPrm) + sg, err := ap.sgSrc.GetSG(ctx, getSGPrm) cancel() diff --git a/pkg/innerring/rpc.go b/pkg/innerring/rpc.go index c58e0ddc4e..8e96deb7b1 100644 --- a/pkg/innerring/rpc.go +++ b/pkg/innerring/rpc.go @@ -65,12 +65,12 @@ func (c *ClientCache) Get(info clientcore.NodeInfo) (clientcore.Client, error) { // Returns storage groups structure from received object. // // Returns an error of type apistatus.ObjectNotFound if storage group is missing. -func (c *ClientCache) GetSG(prm storagegroup2.GetSGPrm) (*storagegroup.StorageGroup, error) { +func (c *ClientCache) GetSG(ctx context.Context, prm storagegroup2.GetSGPrm) (*storagegroup.StorageGroup, error) { var sgAddress oid.Address sgAddress.SetContainer(prm.CID) sgAddress.SetObject(prm.OID) - return c.getSG(prm.Context, sgAddress, &prm.NetMap, prm.Container) + return c.getSG(ctx, sgAddress, &prm.NetMap, prm.Container) } func (c *ClientCache) getSG(ctx context.Context, addr oid.Address, nm *netmap.NetMap, cn [][]netmap.NodeInfo) (*storagegroup.StorageGroup, error) { @@ -214,7 +214,7 @@ func (c *ClientCache) getWrappedClient(info clientcore.NodeInfo) (frostfsapiclie return cInternal, nil } -func (c ClientCache) ListSG(dst *storagegroup2.SearchSGDst, prm storagegroup2.SearchSGPrm) error { +func (c ClientCache) ListSG(ctx context.Context, dst *storagegroup2.SearchSGDst, prm storagegroup2.SearchSGPrm) error { cli, err := c.getWrappedClient(prm.NodeInfo) if err != nil { return fmt.Errorf("could not get API client from cache") @@ -224,7 +224,7 @@ func (c ClientCache) ListSG(dst *storagegroup2.SearchSGDst, prm storagegroup2.Se cliPrm.SetContainerID(prm.Container) - res, err := cli.SearchSG(prm.Context, cliPrm) + res, err := cli.SearchSG(ctx, cliPrm) if err != nil { return err }