[#208] deletesvc: Resolve containedctx linter

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-04-04 12:45:59 +03:00
parent 4941926c9d
commit 5f2a1531fe
5 changed files with 46 additions and 49 deletions

View file

@ -23,22 +23,21 @@ func (s *Service) Delete(ctx context.Context, prm Prm) error {
exec := &execCtx{
svc: s,
ctx: ctx,
prm: prm,
}
exec.setLogger(s.log)
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.executeLocal(ctx)
exec.analyzeStatus(true)
}

View file

@ -18,12 +18,9 @@ type statusError struct {
err error
}
// nolint: containedctx
type execCtx struct {
svc *Service
ctx context.Context
prm Prm
statusError
@ -52,10 +49,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()
}
@ -80,10 +73,10 @@ func (exec *execCtx) newAddress(id oid.ID) oid.Address {
return a
}
func (exec *execCtx) formSplitInfo() bool {
func (exec *execCtx) formSplitInfo(ctx context.Context) bool {
var err error
exec.splitInfo, err = exec.svc.header.splitInfo(exec)
exec.splitInfo, err = exec.svc.header.splitInfo(ctx, exec)
switch {
default:
@ -101,29 +94,29 @@ func (exec *execCtx) formSplitInfo() bool {
return err == nil
}
func (exec *execCtx) collectMembers() (ok bool) {
func (exec *execCtx) collectMembers(ctx context.Context) (ok bool) {
if exec.splitInfo == nil {
exec.log.Debug("no split info, object is PHY")
return true
}
if _, withLink := exec.splitInfo.Link(); withLink {
ok = exec.collectChildren()
ok = exec.collectChildren(ctx)
}
if !ok {
if _, withLast := exec.splitInfo.LastPart(); withLast {
ok = exec.collectChain()
ok = exec.collectChain(ctx)
if !ok {
return
}
}
} // may be fail if neither right nor linking ID is set?
return exec.supplementBySplitID()
return exec.supplementBySplitID(ctx)
}
func (exec *execCtx) collectChain() bool {
func (exec *execCtx) collectChain(ctx context.Context) bool {
var chain []oid.ID
exec.log.Debug("assembling chain...")
@ -131,7 +124,7 @@ func (exec *execCtx) collectChain() bool {
for prev, withPrev := exec.splitInfo.LastPart(); withPrev; {
chain = append(chain, prev)
p, err := exec.svc.header.previous(exec, prev)
p, err := exec.svc.header.previous(ctx, exec, prev)
switch {
default:
@ -160,10 +153,10 @@ func (exec *execCtx) collectChain() bool {
return true
}
func (exec *execCtx) collectChildren() bool {
func (exec *execCtx) collectChildren(ctx context.Context) bool {
exec.log.Debug("collecting children...")
children, err := exec.svc.header.children(exec)
children, err := exec.svc.header.children(ctx, exec)
switch {
default:
@ -187,10 +180,10 @@ func (exec *execCtx) collectChildren() bool {
}
}
func (exec *execCtx) supplementBySplitID() bool {
func (exec *execCtx) supplementBySplitID(ctx context.Context) bool {
exec.log.Debug("supplement by split ID")
chain, err := exec.svc.searcher.splitMembers(exec)
chain, err := exec.svc.searcher.splitMembers(ctx, exec)
switch {
default:
@ -264,8 +257,8 @@ func (exec *execCtx) initTombstoneObject() bool {
return true
}
func (exec *execCtx) saveTombstone() bool {
id, err := exec.svc.placer.put(exec)
func (exec *execCtx) saveTombstone(ctx context.Context) bool {
id, err := exec.svc.placer.put(ctx, exec)
switch {
default:

View file

@ -1,25 +1,27 @@
package deletesvc
import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
"go.uber.org/zap"
)
func (exec *execCtx) executeLocal() {
func (exec *execCtx) executeLocal(ctx context.Context) {
exec.log.Debug("forming tombstone structure...")
ok := exec.formTombstone()
ok := exec.formTombstone(ctx)
if !ok {
return
}
exec.log.Debug("tombstone structure successfully formed, saving...")
exec.saveTombstone()
exec.saveTombstone(ctx)
}
func (exec *execCtx) formTombstone() (ok bool) {
func (exec *execCtx) formTombstone(ctx context.Context) (ok bool) {
tsLifetime, err := exec.svc.netInfo.TombstoneLifetime()
if err != nil {
exec.status = statusUndefined
@ -40,7 +42,7 @@ func (exec *execCtx) formTombstone() (ok bool) {
exec.log.Debug("forming split info...")
ok = exec.formSplitInfo()
ok = exec.formSplitInfo(ctx)
if !ok {
return
}
@ -49,7 +51,7 @@ func (exec *execCtx) formTombstone() (ok bool) {
exec.tombstone.SetSplitID(exec.splitInfo.SplitID())
ok = exec.collectMembers()
ok = exec.collectMembers(ctx)
if !ok {
return
}

View file

@ -1,6 +1,8 @@
package deletesvc
import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
putsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/put"
@ -39,20 +41,20 @@ type cfg struct {
header interface {
// must return (nil, nil) for PHY objects
splitInfo(*execCtx) (*object.SplitInfo, error)
splitInfo(context.Context, *execCtx) (*object.SplitInfo, error)
children(*execCtx) ([]oid.ID, error)
children(context.Context, *execCtx) ([]oid.ID, error)
// must return (nil, nil) for 1st object in chain
previous(*execCtx, oid.ID) (*oid.ID, error)
previous(context.Context, *execCtx, oid.ID) (*oid.ID, error)
}
searcher interface {
splitMembers(*execCtx) ([]oid.ID, error)
splitMembers(context.Context, *execCtx) ([]oid.ID, error)
}
placer interface {
put(*execCtx) (*oid.ID, error)
put(context.Context, *execCtx) (*oid.ID, error)
}
netInfo NetworkInfo

View file

@ -1,6 +1,7 @@
package deletesvc
import (
"context"
"errors"
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
@ -20,7 +21,7 @@ type simpleIDWriter struct {
ids []oid.ID
}
func (w *headSvcWrapper) headAddress(exec *execCtx, addr oid.Address) (*object.Object, error) {
func (w *headSvcWrapper) headAddress(ctx context.Context, exec *execCtx, addr oid.Address) (*object.Object, error) {
wr := getsvc.NewSimpleObjectWriter()
p := getsvc.HeadPrm{}
@ -29,7 +30,7 @@ func (w *headSvcWrapper) headAddress(exec *execCtx, addr oid.Address) (*object.O
p.WithRawFlag(true)
p.WithAddress(addr)
err := (*getsvc.Service)(w).Head(exec.context(), p)
err := (*getsvc.Service)(w).Head(ctx, p)
if err != nil {
return nil, err
}
@ -37,8 +38,8 @@ func (w *headSvcWrapper) headAddress(exec *execCtx, addr oid.Address) (*object.O
return wr.Object(), nil
}
func (w *headSvcWrapper) splitInfo(exec *execCtx) (*object.SplitInfo, error) {
_, err := w.headAddress(exec, exec.address())
func (w *headSvcWrapper) splitInfo(ctx context.Context, exec *execCtx) (*object.SplitInfo, error) {
_, err := w.headAddress(ctx, exec, exec.address())
var errSplitInfo *object.SplitInfoError
@ -52,12 +53,12 @@ func (w *headSvcWrapper) splitInfo(exec *execCtx) (*object.SplitInfo, error) {
}
}
func (w *headSvcWrapper) children(exec *execCtx) ([]oid.ID, error) {
func (w *headSvcWrapper) children(ctx context.Context, exec *execCtx) ([]oid.ID, error) {
link, _ := exec.splitInfo.Link()
a := exec.newAddress(link)
linking, err := w.headAddress(exec, a)
linking, err := w.headAddress(ctx, exec, a)
if err != nil {
return nil, err
}
@ -65,10 +66,10 @@ func (w *headSvcWrapper) children(exec *execCtx) ([]oid.ID, error) {
return linking.Children(), nil
}
func (w *headSvcWrapper) previous(exec *execCtx, id oid.ID) (*oid.ID, error) {
func (w *headSvcWrapper) previous(ctx context.Context, exec *execCtx, id oid.ID) (*oid.ID, error) {
a := exec.newAddress(id)
h, err := w.headAddress(exec, a)
h, err := w.headAddress(ctx, exec, a)
if err != nil {
return nil, err
}
@ -81,7 +82,7 @@ func (w *headSvcWrapper) previous(exec *execCtx, id oid.ID) (*oid.ID, error) {
return nil, nil
}
func (w *searchSvcWrapper) splitMembers(exec *execCtx) ([]oid.ID, error) {
func (w *searchSvcWrapper) splitMembers(ctx context.Context, exec *execCtx) ([]oid.ID, error) {
fs := object.SearchFilters{}
fs.AddSplitIDFilter(object.MatchStringEqual, exec.splitInfo.SplitID())
@ -93,7 +94,7 @@ func (w *searchSvcWrapper) splitMembers(exec *execCtx) ([]oid.ID, error) {
p.WithContainerID(exec.containerID())
p.WithSearchFilters(fs)
err := (*searchsvc.Service)(w).Search(exec.context(), p)
err := (*searchsvc.Service)(w).Search(ctx, p)
if err != nil {
return nil, err
}
@ -107,7 +108,7 @@ func (s *simpleIDWriter) WriteIDs(ids []oid.ID) error {
return nil
}
func (w *putSvcWrapper) put(exec *execCtx) (*oid.ID, error) {
func (w *putSvcWrapper) put(ctx context.Context, exec *execCtx) (*oid.ID, error) {
streamer, err := (*putsvc.Service)(w).Put()
if err != nil {
return nil, err
@ -124,12 +125,12 @@ func (w *putSvcWrapper) put(exec *execCtx) (*oid.ID, error) {
return nil, err
}
err = streamer.SendChunk(exec.context(), new(putsvc.PutChunkPrm).WithChunk(payload))
err = streamer.SendChunk(ctx, new(putsvc.PutChunkPrm).WithChunk(payload))
if err != nil {
return nil, err
}
r, err := streamer.Close(exec.context())
r, err := streamer.Close(ctx)
if err != nil {
return nil, err
}