2020-12-11 08:04:04 +00:00
|
|
|
package deletesvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-02-17 12:30:11 +00:00
|
|
|
"strconv"
|
2020-12-11 08:04:04 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-12-11 08:04:04 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type statusError struct {
|
|
|
|
status int
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:39:44 +00:00
|
|
|
// nolint: containedctx
|
2020-12-11 08:04:04 +00:00
|
|
|
type execCtx struct {
|
|
|
|
svc *Service
|
|
|
|
|
|
|
|
ctx context.Context
|
|
|
|
|
|
|
|
prm Prm
|
|
|
|
|
|
|
|
statusError
|
|
|
|
|
|
|
|
log *logger.Logger
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
tombstone *object.Tombstone
|
2020-12-11 08:04:04 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
splitInfo *object.SplitInfo
|
2020-12-11 08:04:04 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
tombstoneObj *object.Object
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
statusUndefined int = iota
|
|
|
|
statusOK
|
|
|
|
)
|
|
|
|
|
|
|
|
func (exec *execCtx) setLogger(l *logger.Logger) {
|
2022-09-28 07:41:01 +00:00
|
|
|
exec.log = &logger.Logger{Logger: l.With(
|
2020-12-11 08:04:04 +00:00
|
|
|
zap.String("request", "DELETE"),
|
2022-12-30 11:00:01 +00:00
|
|
|
zap.Stringer("address", exec.prm.addr),
|
|
|
|
zap.Bool("local", exec.prm.common.LocalOnly()),
|
2020-12-11 08:04:04 +00:00
|
|
|
zap.Bool("with session", exec.prm.common.SessionToken() != nil),
|
|
|
|
zap.Bool("with bearer", exec.prm.common.BearerToken() != nil),
|
2022-09-28 07:41:01 +00:00
|
|
|
)}
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (exec *execCtx) newAddress(id oid.ID) oid.Address {
|
|
|
|
var a oid.Address
|
|
|
|
a.SetObject(id)
|
2022-12-30 11:00:01 +00:00
|
|
|
a.SetContainer(exec.prm.addr.Container())
|
2020-12-11 08:04:04 +00:00
|
|
|
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) formSplitInfo() bool {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
exec.splitInfo, err = exec.svc.header.splitInfo(exec)
|
|
|
|
|
|
|
|
switch {
|
|
|
|
default:
|
|
|
|
exec.status = statusUndefined
|
|
|
|
exec.err = err
|
|
|
|
|
|
|
|
exec.log.Debug("could not compose split info",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
case err == nil:
|
|
|
|
exec.status = statusOK
|
|
|
|
exec.err = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return err == nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) collectMembers() (ok bool) {
|
|
|
|
if exec.splitInfo == nil {
|
|
|
|
exec.log.Debug("no split info, object is PHY")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
if _, withLink := exec.splitInfo.Link(); withLink {
|
2020-12-11 08:04:04 +00:00
|
|
|
ok = exec.collectChildren()
|
|
|
|
}
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
if !ok {
|
|
|
|
if _, withLast := exec.splitInfo.LastPart(); withLast {
|
|
|
|
ok = exec.collectChain()
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|
|
|
|
} // may be fail if neither right nor linking ID is set?
|
|
|
|
|
|
|
|
return exec.supplementBySplitID()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) collectChain() bool {
|
2022-05-31 17:00:41 +00:00
|
|
|
var chain []oid.ID
|
2020-12-11 08:04:04 +00:00
|
|
|
|
|
|
|
exec.log.Debug("assembling chain...")
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
for prev, withPrev := exec.splitInfo.LastPart(); withPrev; {
|
|
|
|
chain = append(chain, prev)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
p, err := exec.svc.header.previous(exec, prev)
|
2020-12-11 08:04:04 +00:00
|
|
|
|
|
|
|
switch {
|
|
|
|
default:
|
|
|
|
exec.status = statusUndefined
|
|
|
|
exec.err = err
|
|
|
|
|
|
|
|
exec.log.Debug("could not get previous split element",
|
|
|
|
zap.Stringer("id", prev),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return false
|
|
|
|
case err == nil:
|
|
|
|
exec.status = statusOK
|
|
|
|
exec.err = nil
|
2022-05-12 16:37:46 +00:00
|
|
|
|
2022-05-30 06:41:26 +00:00
|
|
|
withPrev = p != nil
|
|
|
|
if withPrev {
|
|
|
|
prev = *p
|
|
|
|
}
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exec.addMembers(chain)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) collectChildren() bool {
|
|
|
|
exec.log.Debug("collecting children...")
|
|
|
|
|
|
|
|
children, err := exec.svc.header.children(exec)
|
|
|
|
|
|
|
|
switch {
|
|
|
|
default:
|
|
|
|
exec.status = statusUndefined
|
|
|
|
exec.err = err
|
|
|
|
|
|
|
|
exec.log.Debug("could not collect object children",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return false
|
|
|
|
case err == nil:
|
|
|
|
exec.status = statusOK
|
|
|
|
exec.err = nil
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
link, _ := exec.splitInfo.Link()
|
|
|
|
|
|
|
|
exec.addMembers(append(children, link))
|
2020-12-11 08:04:04 +00:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) supplementBySplitID() bool {
|
|
|
|
exec.log.Debug("supplement by split ID")
|
|
|
|
|
|
|
|
chain, err := exec.svc.searcher.splitMembers(exec)
|
|
|
|
|
|
|
|
switch {
|
|
|
|
default:
|
|
|
|
exec.status = statusUndefined
|
|
|
|
exec.err = err
|
|
|
|
|
|
|
|
exec.log.Debug("could not search for split chain members",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return false
|
|
|
|
case err == nil:
|
|
|
|
exec.status = statusOK
|
|
|
|
exec.err = nil
|
|
|
|
|
|
|
|
exec.addMembers(chain)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (exec *execCtx) addMembers(incoming []oid.ID) {
|
2020-12-11 08:04:04 +00:00
|
|
|
members := exec.tombstone.Members()
|
|
|
|
|
|
|
|
for i := range members {
|
|
|
|
for j := 0; j < len(incoming); j++ { // don't use range, slice mutates in body
|
2022-05-12 16:37:46 +00:00
|
|
|
if members[i].Equals(incoming[j]) {
|
2020-12-11 08:04:04 +00:00
|
|
|
incoming = append(incoming[:j], incoming[j+1:]...)
|
|
|
|
j--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exec.tombstone.SetMembers(append(members, incoming...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) initTombstoneObject() bool {
|
|
|
|
payload, err := exec.tombstone.Marshal()
|
|
|
|
if err != nil {
|
|
|
|
exec.status = statusUndefined
|
|
|
|
exec.err = err
|
|
|
|
|
|
|
|
exec.log.Debug("could not marshal tombstone structure",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
exec.tombstoneObj = object.New()
|
2022-12-30 11:00:01 +00:00
|
|
|
exec.tombstoneObj.SetContainerID(exec.prm.addr.Container())
|
2022-03-03 14:19:05 +00:00
|
|
|
exec.tombstoneObj.SetType(object.TypeTombstone)
|
2020-12-11 08:04:04 +00:00
|
|
|
exec.tombstoneObj.SetPayload(payload)
|
|
|
|
|
2022-12-30 11:00:01 +00:00
|
|
|
tokenSession := exec.prm.common.SessionToken()
|
2022-05-25 16:09:12 +00:00
|
|
|
if tokenSession != nil {
|
|
|
|
issuer := tokenSession.Issuer()
|
|
|
|
exec.tombstoneObj.SetOwnerID(&issuer)
|
|
|
|
} else {
|
|
|
|
// make local node a tombstone object owner
|
2022-05-31 17:00:41 +00:00
|
|
|
localUser := exec.svc.netInfo.LocalNodeID()
|
|
|
|
exec.tombstoneObj.SetOwnerID(&localUser)
|
2022-05-25 16:09:12 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 12:11:35 +00:00
|
|
|
var a object.Attribute
|
2021-02-17 12:30:11 +00:00
|
|
|
a.SetKey(objectV2.SysAttributeExpEpoch)
|
|
|
|
a.SetValue(strconv.FormatUint(exec.tombstone.ExpirationEpoch(), 10))
|
|
|
|
|
|
|
|
exec.tombstoneObj.SetAttributes(a)
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (exec *execCtx) saveTombstone() bool {
|
2022-03-05 10:43:13 +00:00
|
|
|
id, err := exec.svc.placer.put(exec)
|
2020-12-11 08:04:04 +00:00
|
|
|
|
|
|
|
switch {
|
|
|
|
default:
|
|
|
|
exec.status = statusUndefined
|
|
|
|
exec.err = err
|
|
|
|
|
|
|
|
exec.log.Debug("could not save the tombstone",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return false
|
|
|
|
case err == nil:
|
|
|
|
exec.status = statusOK
|
|
|
|
exec.err = nil
|
|
|
|
|
2021-11-01 08:35:33 +00:00
|
|
|
exec.prm.tombAddrWriter.
|
2022-05-31 17:00:41 +00:00
|
|
|
SetAddress(exec.newAddress(*id))
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|