2020-09-30 10:52:14 +00:00
|
|
|
package deletesvc
|
|
|
|
|
|
|
|
import (
|
2023-04-04 09:45:59 +00:00
|
|
|
"context"
|
2020-12-11 08:04:04 +00:00
|
|
|
"errors"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
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"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-09-30 10:52:14 +00:00
|
|
|
)
|
|
|
|
|
2023-07-10 09:18:56 +00:00
|
|
|
type headSvcWrapper struct {
|
|
|
|
s *getsvc.Service
|
|
|
|
}
|
2020-12-11 08:04:04 +00:00
|
|
|
|
2023-07-10 09:18:56 +00:00
|
|
|
type searchSvcWrapper struct {
|
|
|
|
s *searchsvc.Service
|
|
|
|
}
|
2020-12-11 08:04:04 +00:00
|
|
|
|
2023-07-10 09:18:56 +00:00
|
|
|
type putSvcWrapper struct {
|
|
|
|
s *putsvc.Service
|
|
|
|
}
|
2020-12-11 08:04:04 +00:00
|
|
|
|
|
|
|
type simpleIDWriter struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
ids []oid.ID
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (w *headSvcWrapper) headAddress(ctx context.Context, exec *execCtx, addr oid.Address) (*objectSDK.Object, error) {
|
2020-12-11 08:04:04 +00:00
|
|
|
wr := getsvc.NewSimpleObjectWriter()
|
|
|
|
|
|
|
|
p := getsvc.HeadPrm{}
|
|
|
|
p.SetCommonParameters(exec.commonParameters())
|
|
|
|
p.SetHeaderWriter(wr)
|
|
|
|
p.WithRawFlag(true)
|
|
|
|
p.WithAddress(addr)
|
|
|
|
|
2023-07-10 09:18:56 +00:00
|
|
|
err := w.s.Head(ctx, p)
|
2020-12-11 08:04:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return wr.Object(), nil
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (w *headSvcWrapper) splitInfo(ctx context.Context, exec *execCtx) (*objectSDK.SplitInfo, error) {
|
2023-04-04 09:45:59 +00:00
|
|
|
_, err := w.headAddress(ctx, exec, exec.address())
|
2020-12-11 08:04:04 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
var errSplitInfo *objectSDK.SplitInfoError
|
2020-12-11 08:04:04 +00:00
|
|
|
|
|
|
|
switch {
|
|
|
|
case err == nil:
|
|
|
|
return nil, nil
|
|
|
|
case errors.As(err, &errSplitInfo):
|
|
|
|
return errSplitInfo.SplitInfo(), nil
|
|
|
|
default:
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:45:59 +00:00
|
|
|
func (w *headSvcWrapper) children(ctx context.Context, exec *execCtx) ([]oid.ID, error) {
|
2022-05-12 16:37:46 +00:00
|
|
|
link, _ := exec.splitInfo.Link()
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
a := exec.newAddress(link)
|
2020-12-11 08:04:04 +00:00
|
|
|
|
2023-04-04 09:45:59 +00:00
|
|
|
linking, err := w.headAddress(ctx, exec, a)
|
2020-12-11 08:04:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return linking.Children(), nil
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:45:59 +00:00
|
|
|
func (w *headSvcWrapper) previous(ctx context.Context, exec *execCtx, id oid.ID) (*oid.ID, error) {
|
2020-12-11 08:04:04 +00:00
|
|
|
a := exec.newAddress(id)
|
|
|
|
|
2023-04-04 09:45:59 +00:00
|
|
|
h, err := w.headAddress(ctx, exec, a)
|
2020-12-11 08:04:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
prev, ok := h.PreviousID()
|
|
|
|
if ok {
|
|
|
|
return &prev, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 09:45:59 +00:00
|
|
|
func (w *searchSvcWrapper) splitMembers(ctx context.Context, exec *execCtx) ([]oid.ID, error) {
|
2023-07-06 12:36:41 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddSplitIDFilter(objectSDK.MatchStringEqual, exec.splitInfo.SplitID())
|
2020-12-11 08:04:04 +00:00
|
|
|
|
|
|
|
wr := new(simpleIDWriter)
|
|
|
|
|
|
|
|
p := searchsvc.Prm{}
|
|
|
|
p.SetWriter(wr)
|
|
|
|
p.SetCommonParameters(exec.commonParameters())
|
|
|
|
p.WithContainerID(exec.containerID())
|
|
|
|
p.WithSearchFilters(fs)
|
|
|
|
|
2023-07-10 09:18:56 +00:00
|
|
|
err := w.s.Search(ctx, p)
|
2020-12-11 08:04:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return wr.ids, nil
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (s *simpleIDWriter) WriteIDs(ids []oid.ID) error {
|
2020-12-11 08:04:04 +00:00
|
|
|
s.ids = append(s.ids, ids...)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:45:59 +00:00
|
|
|
func (w *putSvcWrapper) put(ctx context.Context, exec *execCtx) (*oid.ID, error) {
|
2023-07-10 09:18:56 +00:00
|
|
|
streamer, err := w.s.Put()
|
2020-12-11 08:04:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
payload := exec.tombstoneObj.Payload()
|
|
|
|
|
|
|
|
initPrm := new(putsvc.PutInitPrm).
|
|
|
|
WithCommonPrm(exec.commonParameters()).
|
|
|
|
WithObject(exec.tombstoneObj.CutPayload())
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
err = streamer.Init(ctx, initPrm)
|
2020-12-11 08:04:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:45:59 +00:00
|
|
|
err = streamer.SendChunk(ctx, new(putsvc.PutChunkPrm).WithChunk(payload))
|
2020-12-11 08:04:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:45:59 +00:00
|
|
|
r, err := streamer.Close(ctx)
|
2020-12-11 08:04:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-30 10:52:14 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
id := r.ObjectID()
|
|
|
|
|
|
|
|
return &id, nil
|
2020-09-30 10:52:14 +00:00
|
|
|
}
|