forked from TrueCloudLab/frostfs-node
[#208] searchsvc: Resolve context linters
Resolve containedctx and contextcheck linters. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
5f2a1531fe
commit
0b38419fbf
6 changed files with 18 additions and 26 deletions
|
@ -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()))
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue