2020-09-30 10:52:14 +00:00
|
|
|
package deletesvc
|
|
|
|
|
|
|
|
import (
|
2020-12-11 08:04:04 +00:00
|
|
|
"errors"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
getsvc "github.com/TrueCloudLab/frostfs-node/pkg/services/object/get"
|
|
|
|
putsvc "github.com/TrueCloudLab/frostfs-node/pkg/services/object/put"
|
|
|
|
searchsvc "github.com/TrueCloudLab/frostfs-node/pkg/services/object/search"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-09-30 10:52:14 +00:00
|
|
|
)
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
type headSvcWrapper getsvc.Service
|
|
|
|
|
|
|
|
type searchSvcWrapper searchsvc.Service
|
|
|
|
|
|
|
|
type putSvcWrapper putsvc.Service
|
|
|
|
|
|
|
|
type simpleIDWriter struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
ids []oid.ID
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (w *headSvcWrapper) headAddress(exec *execCtx, addr oid.Address) (*object.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)
|
|
|
|
|
|
|
|
err := (*getsvc.Service)(w).Head(exec.context(), p)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return wr.Object(), nil
|
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
func (w *headSvcWrapper) splitInfo(exec *execCtx) (*object.SplitInfo, error) {
|
2020-12-11 08:04:04 +00:00
|
|
|
_, err := w.headAddress(exec, exec.address())
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
var errSplitInfo *object.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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (w *headSvcWrapper) children(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
|
|
|
|
|
|
|
linking, err := w.headAddress(exec, a)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return linking.Children(), nil
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (w *headSvcWrapper) previous(exec *execCtx, id oid.ID) (*oid.ID, error) {
|
2020-12-11 08:04:04 +00:00
|
|
|
a := exec.newAddress(id)
|
|
|
|
|
|
|
|
h, err := w.headAddress(exec, a)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (w *searchSvcWrapper) splitMembers(exec *execCtx) ([]oid.ID, error) {
|
2022-03-03 14:19:05 +00:00
|
|
|
fs := object.SearchFilters{}
|
|
|
|
fs.AddSplitIDFilter(object.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)
|
|
|
|
|
|
|
|
err := (*searchsvc.Service)(w).Search(exec.context(), p)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (w *putSvcWrapper) put(exec *execCtx) (*oid.ID, error) {
|
2020-12-11 08:04:04 +00:00
|
|
|
streamer, err := (*putsvc.Service)(w).Put(exec.context())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
payload := exec.tombstoneObj.Payload()
|
|
|
|
|
|
|
|
initPrm := new(putsvc.PutInitPrm).
|
|
|
|
WithCommonPrm(exec.commonParameters()).
|
|
|
|
WithObject(exec.tombstoneObj.CutPayload())
|
|
|
|
|
|
|
|
err = streamer.Init(initPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = streamer.SendChunk(new(putsvc.PutChunkPrm).WithChunk(payload))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := streamer.Close()
|
|
|
|
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
|
|
|
}
|