[#208] searchsvc: Resolve context linters

Resolve containedctx and contextcheck linters.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-04-04 12:54:21 +03:00
parent 5f2a1531fe
commit 0b38419fbf
6 changed files with 18 additions and 26 deletions

View file

@ -9,7 +9,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
func (exec *execCtx) executeOnContainer() { func (exec *execCtx) executeOnContainer(ctx context.Context) {
if exec.isLocal() { if exec.isLocal() {
exec.log.Debug("return result directly") exec.log.Debug("return result directly")
return return
@ -28,7 +28,7 @@ func (exec *execCtx) executeOnContainer() {
} }
for { for {
if exec.processCurrentEpoch() { if exec.processCurrentEpoch(ctx) {
break break
} }
@ -47,7 +47,7 @@ func (exec *execCtx) executeOnContainer() {
exec.err = nil exec.err = nil
} }
func (exec *execCtx) processCurrentEpoch() bool { func (exec *execCtx) processCurrentEpoch(ctx context.Context) bool {
exec.log.Debug("process epoch", exec.log.Debug("process epoch",
zap.Uint64("number", exec.curProcEpoch), zap.Uint64("number", exec.curProcEpoch),
) )
@ -57,7 +57,7 @@ func (exec *execCtx) processCurrentEpoch() bool {
return true return true
} }
ctx, cancel := context.WithCancel(exec.context()) ctx, cancel := context.WithCancel(ctx)
defer cancel() defer cancel()
for { for {
@ -99,7 +99,7 @@ func (exec *execCtx) processCurrentEpoch() bool {
return return
} }
ids, err := c.searchObjects(exec, info) ids, err := c.searchObjects(ctx, exec, info)
if err != nil { if err != nil {
exec.log.Debug("remote operation failed", exec.log.Debug("remote operation failed",
zap.String("error", err.Error())) zap.String("error", err.Error()))

View file

@ -1,8 +1,6 @@
package searchsvc package searchsvc
import ( import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
@ -16,12 +14,9 @@ type statusError struct {
err error err error
} }
// nolint: containedctx
type execCtx struct { type execCtx struct {
svc *Service svc *Service
ctx context.Context
prm Prm prm Prm
statusError 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 { func (exec execCtx) isLocal() bool {
return exec.prm.common.LocalOnly() return exec.prm.common.LocalOnly()
} }

View file

@ -10,7 +10,6 @@ import (
func (s *Service) Search(ctx context.Context, prm Prm) error { func (s *Service) Search(ctx context.Context, prm Prm) error {
exec := &execCtx{ exec := &execCtx{
svc: s, svc: s,
ctx: ctx,
prm: prm, prm: prm,
} }
@ -18,22 +17,21 @@ func (s *Service) Search(ctx context.Context, prm Prm) error {
exec.setLogger(s.log) exec.setLogger(s.log)
//nolint: contextcheck exec.execute(ctx)
exec.execute()
return exec.statusError.err return exec.statusError.err
} }
func (exec *execCtx) execute() { func (exec *execCtx) execute(ctx context.Context) {
exec.log.Debug("serving request...") exec.log.Debug("serving request...")
// perform local operation // perform local operation
exec.executeLocal() 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 // analyze local result
switch exec.status { switch exec.status {
default: default:
@ -45,7 +43,7 @@ func (exec *execCtx) analyzeStatus(execCnr bool) {
} }
if execCnr { if execCnr {
exec.executeOnContainer() exec.executeOnContainer(ctx)
exec.analyzeStatus(false) exec.analyzeStatus(ctx, false)
} }
} }

View file

@ -116,7 +116,7 @@ func (s *testStorage) search(exec *execCtx) ([]oid.ID, error) {
return v.ids, v.err 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()] v, ok := c.items[exec.containerID().EncodeToString()]
if !ok { if !ok {
return nil, nil return nil, nil

View file

@ -1,6 +1,8 @@
package searchsvc package searchsvc
import ( import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client" "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/core/netmap"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
@ -24,7 +26,7 @@ type Option func(*cfg)
type searchClient interface { type searchClient interface {
// searchObjects searches objects on the specified node. // searchObjects searches objects on the specified node.
// MUST NOT modify execCtx as it can be accessed concurrently. // 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 { type ClientConstructor interface {

View file

@ -1,6 +1,7 @@
package searchsvc package searchsvc
import ( import (
"context"
"sync" "sync"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
@ -77,7 +78,7 @@ func (c *clientConstructorWrapper) get(info client.NodeInfo) (searchClient, erro
}, nil }, 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 { if exec.prm.forwarder != nil {
return exec.prm.forwarder(info, c.client) 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 var prm internalclient.SearchObjectsPrm
prm.SetContext(exec.context()) prm.SetContext(ctx)
prm.SetClient(c.client) prm.SetClient(c.client)
prm.SetPrivateKey(key) prm.SetPrivateKey(key)
prm.SetSessionToken(exec.prm.common.SessionToken()) prm.SetSessionToken(exec.prm.common.SessionToken())