forked from TrueCloudLab/frostfs-node
[#58] object/delete: Process linking object in Delete service
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
16252ad09a
commit
f251645def
3 changed files with 81 additions and 2 deletions
|
@ -3,7 +3,9 @@ package deletesvc
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head"
|
headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head"
|
||||||
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
|
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
|
||||||
objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||||
|
@ -16,6 +18,10 @@ type Service struct {
|
||||||
|
|
||||||
type Option func(*cfg)
|
type Option func(*cfg)
|
||||||
|
|
||||||
|
type RelationHeader interface {
|
||||||
|
HeadRelation(context.Context, *objectSDK.Address) (*object.Object, error)
|
||||||
|
}
|
||||||
|
|
||||||
type cfg struct {
|
type cfg struct {
|
||||||
ownerID *owner.ID
|
ownerID *owner.ID
|
||||||
|
|
||||||
|
@ -24,6 +30,8 @@ type cfg struct {
|
||||||
putSvc *putsvc.Service
|
putSvc *putsvc.Service
|
||||||
|
|
||||||
headSvc *headsvc.Service
|
headSvc *headsvc.Service
|
||||||
|
|
||||||
|
hdrLinking RelationHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultCfg() *cfg {
|
func defaultCfg() *cfg {
|
||||||
|
@ -60,8 +68,24 @@ func (s *Service) Delete(ctx context.Context, prm *Prm) (*Response, error) {
|
||||||
commonPrm: prm.common,
|
commonPrm: prm.common,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.deleteAll(tool); err != nil {
|
if linking, err := s.hdrLinking.HeadRelation(ctx, prm.addr); err != nil {
|
||||||
return nil, errors.Wrapf(err, "(%T) could not delete all objcet relations", s)
|
if err := s.deleteAll(tool); err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "(%T) could not delete all object relations", s)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := tool.delete(prm.addr.GetObjectID()); err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "(%T) could not delete object", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, child := range linking.GetChildren() {
|
||||||
|
if err := tool.delete(child); err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "(%T) could not delete child object", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := tool.delete(linking.GetID()); err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "(%T) could not delete linking object", s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new(Response), nil
|
return new(Response), nil
|
||||||
|
@ -124,3 +148,9 @@ func WitHeadService(v *headsvc.Service) Option {
|
||||||
c.headSvc = v
|
c.headSvc = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithLinkingHeader(v RelationHeader) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.hdrLinking = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
40
pkg/services/object/head/relation.go
Normal file
40
pkg/services/object/head/relation.go
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package headsvc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RelationHeader struct {
|
||||||
|
srch RelationSearcher
|
||||||
|
|
||||||
|
svc *Service
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRelationHeader(srch RelationSearcher, svc *Service) *RelationHeader {
|
||||||
|
return &RelationHeader{
|
||||||
|
srch: srch,
|
||||||
|
svc: svc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *RelationHeader) HeadRelation(ctx context.Context, addr *objectSDK.Address) (*object.Object, error) {
|
||||||
|
id, err := h.srch.SearchRelation(ctx, addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "(%T) could not find relation", h)
|
||||||
|
}
|
||||||
|
|
||||||
|
a := objectSDK.NewAddress()
|
||||||
|
a.SetContainerID(addr.GetContainerID())
|
||||||
|
a.SetObjectID(id)
|
||||||
|
|
||||||
|
r, err := h.svc.Head(ctx, new(Prm).WithAddress(a))
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "(%T) could not receive relation header", h)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.Header(), nil
|
||||||
|
}
|
|
@ -62,3 +62,12 @@ func NewRightChildSearcher(svc *Service) *RelationSearcher {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewLinkingSearcher(svc *Service) *RelationSearcher {
|
||||||
|
return &RelationSearcher{
|
||||||
|
svc: svc,
|
||||||
|
queryGenerator: func(addr *object.Address) query.Query {
|
||||||
|
return queryV1.NewLinkingQuery(addr.GetObjectID())
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue