[#208] deletesvc: Resolve containedctx linter
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
4941926c9d
commit
5f2a1531fe
5 changed files with 46 additions and 49 deletions
|
@ -23,22 +23,21 @@ func (s *Service) Delete(ctx context.Context, prm Prm) error {
|
||||||
|
|
||||||
exec := &execCtx{
|
exec := &execCtx{
|
||||||
svc: s,
|
svc: s,
|
||||||
ctx: ctx,
|
|
||||||
prm: prm,
|
prm: prm,
|
||||||
}
|
}
|
||||||
|
|
||||||
exec.setLogger(s.log)
|
exec.setLogger(s.log)
|
||||||
|
|
||||||
exec.execute()
|
exec.execute(ctx)
|
||||||
|
|
||||||
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(ctx)
|
||||||
|
|
||||||
exec.analyzeStatus(true)
|
exec.analyzeStatus(true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,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 +49,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()
|
||||||
}
|
}
|
||||||
|
@ -80,10 +73,10 @@ func (exec *execCtx) newAddress(id oid.ID) oid.Address {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec *execCtx) formSplitInfo() bool {
|
func (exec *execCtx) formSplitInfo(ctx context.Context) bool {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
exec.splitInfo, err = exec.svc.header.splitInfo(exec)
|
exec.splitInfo, err = exec.svc.header.splitInfo(ctx, exec)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
default:
|
default:
|
||||||
|
@ -101,29 +94,29 @@ func (exec *execCtx) formSplitInfo() bool {
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec *execCtx) collectMembers() (ok bool) {
|
func (exec *execCtx) collectMembers(ctx context.Context) (ok bool) {
|
||||||
if exec.splitInfo == nil {
|
if exec.splitInfo == nil {
|
||||||
exec.log.Debug("no split info, object is PHY")
|
exec.log.Debug("no split info, object is PHY")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, withLink := exec.splitInfo.Link(); withLink {
|
if _, withLink := exec.splitInfo.Link(); withLink {
|
||||||
ok = exec.collectChildren()
|
ok = exec.collectChildren(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
if _, withLast := exec.splitInfo.LastPart(); withLast {
|
if _, withLast := exec.splitInfo.LastPart(); withLast {
|
||||||
ok = exec.collectChain()
|
ok = exec.collectChain(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // may be fail if neither right nor linking ID is set?
|
} // 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
|
var chain []oid.ID
|
||||||
|
|
||||||
exec.log.Debug("assembling chain...")
|
exec.log.Debug("assembling chain...")
|
||||||
|
@ -131,7 +124,7 @@ func (exec *execCtx) collectChain() bool {
|
||||||
for prev, withPrev := exec.splitInfo.LastPart(); withPrev; {
|
for prev, withPrev := exec.splitInfo.LastPart(); withPrev; {
|
||||||
chain = append(chain, prev)
|
chain = append(chain, prev)
|
||||||
|
|
||||||
p, err := exec.svc.header.previous(exec, prev)
|
p, err := exec.svc.header.previous(ctx, exec, prev)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
default:
|
default:
|
||||||
|
@ -160,10 +153,10 @@ func (exec *execCtx) collectChain() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec *execCtx) collectChildren() bool {
|
func (exec *execCtx) collectChildren(ctx context.Context) bool {
|
||||||
exec.log.Debug("collecting children...")
|
exec.log.Debug("collecting children...")
|
||||||
|
|
||||||
children, err := exec.svc.header.children(exec)
|
children, err := exec.svc.header.children(ctx, exec)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
default:
|
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")
|
exec.log.Debug("supplement by split ID")
|
||||||
|
|
||||||
chain, err := exec.svc.searcher.splitMembers(exec)
|
chain, err := exec.svc.searcher.splitMembers(ctx, exec)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
default:
|
default:
|
||||||
|
@ -264,8 +257,8 @@ func (exec *execCtx) initTombstoneObject() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (exec *execCtx) saveTombstone() bool {
|
func (exec *execCtx) saveTombstone(ctx context.Context) bool {
|
||||||
id, err := exec.svc.placer.put(exec)
|
id, err := exec.svc.placer.put(ctx, exec)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
package deletesvc
|
package deletesvc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (exec *execCtx) executeLocal() {
|
func (exec *execCtx) executeLocal(ctx context.Context) {
|
||||||
exec.log.Debug("forming tombstone structure...")
|
exec.log.Debug("forming tombstone structure...")
|
||||||
|
|
||||||
ok := exec.formTombstone()
|
ok := exec.formTombstone(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
exec.log.Debug("tombstone structure successfully formed, saving...")
|
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()
|
tsLifetime, err := exec.svc.netInfo.TombstoneLifetime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exec.status = statusUndefined
|
exec.status = statusUndefined
|
||||||
|
@ -40,7 +42,7 @@ func (exec *execCtx) formTombstone() (ok bool) {
|
||||||
|
|
||||||
exec.log.Debug("forming split info...")
|
exec.log.Debug("forming split info...")
|
||||||
|
|
||||||
ok = exec.formSplitInfo()
|
ok = exec.formSplitInfo(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -49,7 +51,7 @@ func (exec *execCtx) formTombstone() (ok bool) {
|
||||||
|
|
||||||
exec.tombstone.SetSplitID(exec.splitInfo.SplitID())
|
exec.tombstone.SetSplitID(exec.splitInfo.SplitID())
|
||||||
|
|
||||||
ok = exec.collectMembers()
|
ok = exec.collectMembers(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package deletesvc
|
package deletesvc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
||||||
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
|
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
|
||||||
putsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/put"
|
putsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/put"
|
||||||
|
@ -39,20 +41,20 @@ type cfg struct {
|
||||||
|
|
||||||
header interface {
|
header interface {
|
||||||
// must return (nil, nil) for PHY objects
|
// 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
|
// 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 {
|
searcher interface {
|
||||||
splitMembers(*execCtx) ([]oid.ID, error)
|
splitMembers(context.Context, *execCtx) ([]oid.ID, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
placer interface {
|
placer interface {
|
||||||
put(*execCtx) (*oid.ID, error)
|
put(context.Context, *execCtx) (*oid.ID, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
netInfo NetworkInfo
|
netInfo NetworkInfo
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package deletesvc
|
package deletesvc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
|
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
|
||||||
|
@ -20,7 +21,7 @@ type simpleIDWriter struct {
|
||||||
ids []oid.ID
|
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()
|
wr := getsvc.NewSimpleObjectWriter()
|
||||||
|
|
||||||
p := getsvc.HeadPrm{}
|
p := getsvc.HeadPrm{}
|
||||||
|
@ -29,7 +30,7 @@ func (w *headSvcWrapper) headAddress(exec *execCtx, addr oid.Address) (*object.O
|
||||||
p.WithRawFlag(true)
|
p.WithRawFlag(true)
|
||||||
p.WithAddress(addr)
|
p.WithAddress(addr)
|
||||||
|
|
||||||
err := (*getsvc.Service)(w).Head(exec.context(), p)
|
err := (*getsvc.Service)(w).Head(ctx, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -37,8 +38,8 @@ func (w *headSvcWrapper) headAddress(exec *execCtx, addr oid.Address) (*object.O
|
||||||
return wr.Object(), nil
|
return wr.Object(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *headSvcWrapper) splitInfo(exec *execCtx) (*object.SplitInfo, error) {
|
func (w *headSvcWrapper) splitInfo(ctx context.Context, exec *execCtx) (*object.SplitInfo, error) {
|
||||||
_, err := w.headAddress(exec, exec.address())
|
_, err := w.headAddress(ctx, exec, exec.address())
|
||||||
|
|
||||||
var errSplitInfo *object.SplitInfoError
|
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()
|
link, _ := exec.splitInfo.Link()
|
||||||
|
|
||||||
a := exec.newAddress(link)
|
a := exec.newAddress(link)
|
||||||
|
|
||||||
linking, err := w.headAddress(exec, a)
|
linking, err := w.headAddress(ctx, exec, a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -65,10 +66,10 @@ func (w *headSvcWrapper) children(exec *execCtx) ([]oid.ID, error) {
|
||||||
return linking.Children(), nil
|
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)
|
a := exec.newAddress(id)
|
||||||
|
|
||||||
h, err := w.headAddress(exec, a)
|
h, err := w.headAddress(ctx, exec, a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -81,7 +82,7 @@ func (w *headSvcWrapper) previous(exec *execCtx, id oid.ID) (*oid.ID, error) {
|
||||||
return nil, nil
|
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 := object.SearchFilters{}
|
||||||
fs.AddSplitIDFilter(object.MatchStringEqual, exec.splitInfo.SplitID())
|
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.WithContainerID(exec.containerID())
|
||||||
p.WithSearchFilters(fs)
|
p.WithSearchFilters(fs)
|
||||||
|
|
||||||
err := (*searchsvc.Service)(w).Search(exec.context(), p)
|
err := (*searchsvc.Service)(w).Search(ctx, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -107,7 +108,7 @@ func (s *simpleIDWriter) WriteIDs(ids []oid.ID) error {
|
||||||
return nil
|
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()
|
streamer, err := (*putsvc.Service)(w).Put()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -124,12 +125,12 @@ func (w *putSvcWrapper) put(exec *execCtx) (*oid.ID, error) {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := streamer.Close(exec.context())
|
r, err := streamer.Close(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue