frostfs-node/pkg/services/object/delete/util.go
Dmitrii Stepanov e83d39e33f
All checks were successful
DCO action / DCO (pull_request) Successful in 3m29s
Vulncheck / Vulncheck (pull_request) Successful in 3m31s
Build / Build Components (1.21) (pull_request) Successful in 4m56s
Build / Build Components (1.22) (pull_request) Successful in 4m57s
Tests and linters / Staticcheck (pull_request) Successful in 5m14s
Tests and linters / gopls check (pull_request) Successful in 5m11s
Tests and linters / Lint (pull_request) Successful in 6m23s
Tests and linters / Tests (1.22) (pull_request) Successful in 12m42s
Tests and linters / Tests (1.21) (pull_request) Successful in 12m54s
Tests and linters / Tests with -race (pull_request) Successful in 16m31s
Pre-commit hooks / Pre-commit (pull_request) Successful in 21m57s
[#1253] deleteSvc: Use copy of common parameters
getSvc may change the values of some fields, so Head will affect Delete
or Put. In this case, the change is necessary so that the session token
is stored in the tombstone object (EC assemble calls `ForgetTokens`).

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2024-07-17 14:24:27 +03:00

140 lines
2.9 KiB
Go

package deletesvc
import (
"context"
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
putsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/put"
searchsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
)
type headSvcWrapper struct {
s *getsvc.Service
}
type searchSvcWrapper struct {
s *searchsvc.Service
}
type putSvcWrapper struct {
s *putsvc.Service
}
type simpleIDWriter struct {
ids []oid.ID
}
func (w *headSvcWrapper) headAddress(ctx context.Context, exec *execCtx, addr oid.Address) (*objectSDK.Object, error) {
wr := getsvc.NewSimpleObjectWriter()
p := getsvc.HeadPrm{}
if cp := exec.commonParameters(); cp != nil {
commonParameters := *cp
p.SetCommonParameters(&commonParameters)
}
p.SetHeaderWriter(wr)
p.WithRawFlag(true)
p.WithAddress(addr)
err := w.s.Head(ctx, p)
if err != nil {
return nil, err
}
return wr.Object(), nil
}
func (w *headSvcWrapper) head(ctx context.Context, exec *execCtx) (*objectSDK.Object, error) {
return w.headAddress(ctx, exec, exec.address())
}
func (w *headSvcWrapper) children(ctx context.Context, exec *execCtx) ([]oid.ID, error) {
link, _ := exec.splitInfo.Link()
a := exec.newAddress(link)
linking, err := w.headAddress(ctx, exec, a)
if err != nil {
return nil, err
}
return linking.Children(), nil
}
func (w *headSvcWrapper) previous(ctx context.Context, exec *execCtx, id oid.ID) (*oid.ID, error) {
a := exec.newAddress(id)
h, err := w.headAddress(ctx, exec, a)
if err != nil {
return nil, err
}
prev, ok := h.PreviousID()
if ok {
return &prev, nil
}
return nil, nil
}
func (w *searchSvcWrapper) splitMembers(ctx context.Context, exec *execCtx) ([]oid.ID, error) {
fs := objectSDK.SearchFilters{}
fs.AddSplitIDFilter(objectSDK.MatchStringEqual, exec.splitInfo.SplitID())
wr := new(simpleIDWriter)
p := searchsvc.Prm{}
p.SetWriter(wr)
p.SetCommonParameters(exec.commonParameters())
p.WithContainerID(exec.containerID())
p.WithSearchFilters(fs)
err := w.s.Search(ctx, p)
if err != nil {
return nil, err
}
return wr.ids, nil
}
func (s *simpleIDWriter) WriteIDs(ids []oid.ID) error {
s.ids = append(s.ids, ids...)
return nil
}
func (w *putSvcWrapper) put(ctx context.Context, exec *execCtx) (*oid.ID, error) {
streamer, err := w.s.Put()
if err != nil {
return nil, err
}
payload := exec.tombstoneObj.Payload()
initPrm := new(putsvc.PutInitPrm).
WithCommonPrm(exec.commonParameters()).
WithObject(exec.tombstoneObj.CutPayload())
err = streamer.Init(ctx, initPrm)
if err != nil {
return nil, err
}
err = streamer.SendChunk(ctx, new(putsvc.PutChunkPrm).WithChunk(payload))
if err != nil {
return nil, err
}
r, err := streamer.Close(ctx)
if err != nil {
return nil, err
}
id := r.ObjectID()
return &id, nil
}