From 0b38419fbf494b7577583034ea83e7d4ec2716a1 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Tue, 4 Apr 2023 12:54:21 +0300 Subject: [PATCH] [#208] searchsvc: Resolve context linters Resolve containedctx and contextcheck linters. Signed-off-by: Dmitrii Stepanov --- pkg/services/object/search/container.go | 10 +++++----- pkg/services/object/search/exec.go | 9 --------- pkg/services/object/search/search.go | 14 ++++++-------- pkg/services/object/search/search_test.go | 2 +- pkg/services/object/search/service.go | 4 +++- pkg/services/object/search/util.go | 5 +++-- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/pkg/services/object/search/container.go b/pkg/services/object/search/container.go index fffcba42a..b158bc23e 100644 --- a/pkg/services/object/search/container.go +++ b/pkg/services/object/search/container.go @@ -9,7 +9,7 @@ import ( "go.uber.org/zap" ) -func (exec *execCtx) executeOnContainer() { +func (exec *execCtx) executeOnContainer(ctx context.Context) { if exec.isLocal() { exec.log.Debug("return result directly") return @@ -28,7 +28,7 @@ func (exec *execCtx) executeOnContainer() { } for { - if exec.processCurrentEpoch() { + if exec.processCurrentEpoch(ctx) { break } @@ -47,7 +47,7 @@ func (exec *execCtx) executeOnContainer() { exec.err = nil } -func (exec *execCtx) processCurrentEpoch() bool { +func (exec *execCtx) processCurrentEpoch(ctx context.Context) bool { exec.log.Debug("process epoch", zap.Uint64("number", exec.curProcEpoch), ) @@ -57,7 +57,7 @@ func (exec *execCtx) processCurrentEpoch() bool { return true } - ctx, cancel := context.WithCancel(exec.context()) + ctx, cancel := context.WithCancel(ctx) defer cancel() for { @@ -99,7 +99,7 @@ func (exec *execCtx) processCurrentEpoch() bool { return } - ids, err := c.searchObjects(exec, info) + ids, err := c.searchObjects(ctx, exec, info) if err != nil { exec.log.Debug("remote operation failed", zap.String("error", err.Error())) diff --git a/pkg/services/object/search/exec.go b/pkg/services/object/search/exec.go index 8cc9a9a26..f815270d9 100644 --- a/pkg/services/object/search/exec.go +++ b/pkg/services/object/search/exec.go @@ -1,8 +1,6 @@ package searchsvc import ( - "context" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" @@ -16,12 +14,9 @@ type statusError struct { err error } -// nolint: containedctx type execCtx struct { svc *Service - ctx context.Context - prm Prm statusError @@ -52,10 +47,6 @@ func (exec *execCtx) setLogger(l *logger.Logger) { )} } -func (exec execCtx) context() context.Context { - return exec.ctx -} - func (exec execCtx) isLocal() bool { return exec.prm.common.LocalOnly() } diff --git a/pkg/services/object/search/search.go b/pkg/services/object/search/search.go index 5a6880922..325b42a54 100644 --- a/pkg/services/object/search/search.go +++ b/pkg/services/object/search/search.go @@ -10,7 +10,6 @@ import ( func (s *Service) Search(ctx context.Context, prm Prm) error { exec := &execCtx{ svc: s, - ctx: ctx, prm: prm, } @@ -18,22 +17,21 @@ func (s *Service) Search(ctx context.Context, prm Prm) error { exec.setLogger(s.log) - //nolint: contextcheck - exec.execute() + exec.execute(ctx) return exec.statusError.err } -func (exec *execCtx) execute() { +func (exec *execCtx) execute(ctx context.Context) { exec.log.Debug("serving request...") // perform local operation exec.executeLocal() - exec.analyzeStatus(true) + exec.analyzeStatus(ctx, true) } -func (exec *execCtx) analyzeStatus(execCnr bool) { +func (exec *execCtx) analyzeStatus(ctx context.Context, execCnr bool) { // analyze local result switch exec.status { default: @@ -45,7 +43,7 @@ func (exec *execCtx) analyzeStatus(execCnr bool) { } if execCnr { - exec.executeOnContainer() - exec.analyzeStatus(false) + exec.executeOnContainer(ctx) + exec.analyzeStatus(ctx, false) } } diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index 1d902e7aa..e95970955 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -116,7 +116,7 @@ func (s *testStorage) search(exec *execCtx) ([]oid.ID, error) { return v.ids, v.err } -func (c *testStorage) searchObjects(exec *execCtx, _ clientcore.NodeInfo) ([]oid.ID, error) { +func (c *testStorage) searchObjects(_ context.Context, exec *execCtx, _ clientcore.NodeInfo) ([]oid.ID, error) { v, ok := c.items[exec.containerID().EncodeToString()] if !ok { return nil, nil diff --git a/pkg/services/object/search/service.go b/pkg/services/object/search/service.go index aebcfca0f..b858e2219 100644 --- a/pkg/services/object/search/service.go +++ b/pkg/services/object/search/service.go @@ -1,6 +1,8 @@ package searchsvc import ( + "context" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine" @@ -24,7 +26,7 @@ type Option func(*cfg) type searchClient interface { // searchObjects searches objects on the specified node. // MUST NOT modify execCtx as it can be accessed concurrently. - searchObjects(*execCtx, client.NodeInfo) ([]oid.ID, error) + searchObjects(context.Context, *execCtx, client.NodeInfo) ([]oid.ID, error) } type ClientConstructor interface { diff --git a/pkg/services/object/search/util.go b/pkg/services/object/search/util.go index 741a224af..610dd77ff 100644 --- a/pkg/services/object/search/util.go +++ b/pkg/services/object/search/util.go @@ -1,6 +1,7 @@ package searchsvc import ( + "context" "sync" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client" @@ -77,7 +78,7 @@ func (c *clientConstructorWrapper) get(info client.NodeInfo) (searchClient, erro }, nil } -func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]oid.ID, error) { +func (c *clientWrapper) searchObjects(ctx context.Context, exec *execCtx, info client.NodeInfo) ([]oid.ID, error) { if exec.prm.forwarder != nil { return exec.prm.forwarder(info, c.client) } @@ -98,7 +99,7 @@ func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]oi var prm internalclient.SearchObjectsPrm - prm.SetContext(exec.context()) + prm.SetContext(ctx) prm.SetClient(c.client) prm.SetPrivateKey(key) prm.SetSessionToken(exec.prm.common.SessionToken())