2020-09-30 10:52:14 +00:00
|
|
|
package deletesvc
|
|
|
|
|
|
|
|
import (
|
2021-02-17 12:30:11 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
2020-12-11 08:04:04 +00:00
|
|
|
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
|
2020-09-30 10:52:14 +00:00
|
|
|
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
|
2020-12-11 08:04:04 +00:00
|
|
|
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
|
2020-11-23 11:19:49 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-01-26 12:11:13 +00:00
|
|
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
2020-11-23 11:19:49 +00:00
|
|
|
"go.uber.org/zap"
|
2020-09-30 10:52:14 +00:00
|
|
|
)
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
// Service utility serving requests of Object.Get service.
|
2020-09-30 10:52:14 +00:00
|
|
|
type Service struct {
|
|
|
|
*cfg
|
|
|
|
}
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
// Option is a Service's constructor option.
|
2020-09-30 10:52:14 +00:00
|
|
|
type Option func(*cfg)
|
|
|
|
|
2021-02-17 12:30:11 +00:00
|
|
|
// NetworkInfo wraps network state and configurations.
|
|
|
|
type NetworkInfo interface {
|
|
|
|
netmap.State
|
|
|
|
|
|
|
|
// Must return the lifespan of the tombstones
|
|
|
|
// in the NeoFS epochs.
|
|
|
|
TombstoneLifetime() (uint64, error)
|
2021-11-08 12:10:49 +00:00
|
|
|
|
|
|
|
// Returns user ID of the local storage node. Result must not be nil.
|
|
|
|
// New tombstone objects will have the result as an owner ID if removal is executed w/o a session.
|
|
|
|
LocalNodeID() *owner.ID
|
2021-02-17 12:30:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 10:52:14 +00:00
|
|
|
type cfg struct {
|
2020-12-11 08:04:04 +00:00
|
|
|
log *logger.Logger
|
2020-09-30 10:52:14 +00:00
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
header interface {
|
|
|
|
// must return (nil, nil) for PHY objects
|
2022-03-03 14:19:05 +00:00
|
|
|
splitInfo(*execCtx) (*object.SplitInfo, error)
|
2020-09-30 10:52:14 +00:00
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
children(*execCtx) ([]*oidSDK.ID, error)
|
2020-09-30 10:52:14 +00:00
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
// must return (nil, nil) for 1st object in chain
|
2022-01-26 12:11:13 +00:00
|
|
|
previous(*execCtx, *oidSDK.ID) (*oidSDK.ID, error)
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|
2020-10-01 10:54:18 +00:00
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
searcher interface {
|
2022-01-26 12:11:13 +00:00
|
|
|
splitMembers(*execCtx) ([]*oidSDK.ID, error)
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|
2020-11-23 11:19:49 +00:00
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
placer interface {
|
2022-01-26 12:11:13 +00:00
|
|
|
put(*execCtx, bool) (*oidSDK.ID, error)
|
2020-12-11 08:04:04 +00:00
|
|
|
}
|
2021-02-17 12:30:11 +00:00
|
|
|
|
|
|
|
netInfo NetworkInfo
|
2020-09-30 10:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
2020-11-23 11:19:49 +00:00
|
|
|
return &cfg{
|
|
|
|
log: zap.L(),
|
|
|
|
}
|
2020-09-30 10:52:14 +00:00
|
|
|
}
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
// New creates, initializes and returns utility serving
|
|
|
|
// Object.Get service requests.
|
|
|
|
func New(opts ...Option) *Service {
|
2020-09-30 10:52:14 +00:00
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Service{
|
|
|
|
cfg: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
// WithLogger returns option to specify Delete service's logger.
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
2020-09-30 10:52:14 +00:00
|
|
|
return func(c *cfg) {
|
2020-12-11 08:04:04 +00:00
|
|
|
c.log = l.With(zap.String("component", "Object.Delete service"))
|
2020-09-30 10:52:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
// WithHeadService returns option to set Head service
|
|
|
|
// to work with object headers.
|
|
|
|
func WithHeadService(h *getsvc.Service) Option {
|
2020-09-30 10:52:14 +00:00
|
|
|
return func(c *cfg) {
|
2020-12-11 08:04:04 +00:00
|
|
|
c.header = (*headSvcWrapper)(h)
|
2020-09-30 10:52:14 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-01 10:54:18 +00:00
|
|
|
|
2021-06-23 13:29:46 +00:00
|
|
|
// WithSearchService returns option to set search service.
|
2020-12-11 08:04:04 +00:00
|
|
|
func WithSearchService(s *searchsvc.Service) Option {
|
2020-10-01 10:54:18 +00:00
|
|
|
return func(c *cfg) {
|
2020-12-11 08:04:04 +00:00
|
|
|
c.searcher = (*searchSvcWrapper)(s)
|
2020-10-01 10:54:18 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 11:19:49 +00:00
|
|
|
|
2021-06-23 13:29:46 +00:00
|
|
|
// WithPutService returns option to specify put service.
|
2020-12-11 08:04:04 +00:00
|
|
|
func WithPutService(p *putsvc.Service) Option {
|
2020-11-23 11:19:49 +00:00
|
|
|
return func(c *cfg) {
|
2020-12-11 08:04:04 +00:00
|
|
|
c.placer = (*putSvcWrapper)(p)
|
2020-11-23 11:19:49 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-17 12:30:11 +00:00
|
|
|
|
|
|
|
// WithNetworkInfo returns option to set network information source.
|
|
|
|
func WithNetworkInfo(netInfo NetworkInfo) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.netInfo = netInfo
|
|
|
|
}
|
|
|
|
}
|