[#378] object/delete: Set expiration epoch of the created tombstones

Make object delete service to use network information to calculate and set
expiration of the created tombstone.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-02-17 15:30:11 +03:00 committed by Alex Vanin
parent 717f2beb47
commit b8d1144839
3 changed files with 43 additions and 0 deletions

View file

@ -2,9 +2,11 @@ package deletesvc
import ( import (
"context" "context"
"strconv"
"github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/container"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
@ -236,6 +238,12 @@ func (exec *execCtx) initTombstoneObject() bool {
exec.tombstoneObj.SetType(objectSDK.TypeTombstone) exec.tombstoneObj.SetType(objectSDK.TypeTombstone)
exec.tombstoneObj.SetPayload(payload) exec.tombstoneObj.SetPayload(payload)
a := objectSDK.NewAttribute()
a.SetKey(objectV2.SysAttributeExpEpoch)
a.SetValue(strconv.FormatUint(exec.tombstone.ExpirationEpoch(), 10))
exec.tombstoneObj.SetAttributes(a)
return true return true
} }

View file

@ -2,6 +2,7 @@ package deletesvc
import ( import (
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"go.uber.org/zap"
) )
func (exec *execCtx) executeLocal() { func (exec *execCtx) executeLocal() {
@ -25,7 +26,22 @@ func (exec *execCtx) executeLocal() {
} }
func (exec *execCtx) formTombstone() (ok bool) { func (exec *execCtx) formTombstone() (ok bool) {
tsLifetime, err := exec.svc.netInfo.TombstoneLifetime()
if err != nil {
exec.status = statusUndefined
exec.err = err
exec.log.Debug("could not read tombstone lifetime config",
zap.String("error", err.Error()),
)
return false
}
exec.tombstone = objectSDK.NewTombstone() exec.tombstone = objectSDK.NewTombstone()
exec.tombstone.SetExpirationEpoch(
exec.svc.netInfo.CurrentEpoch() + tsLifetime,
)
exec.addMembers([]*objectSDK.ID{exec.address().ObjectID()}) exec.addMembers([]*objectSDK.ID{exec.address().ObjectID()})
exec.log.Debug("forming split info...") exec.log.Debug("forming split info...")

View file

@ -2,6 +2,7 @@ package deletesvc
import ( import (
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get" getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search" searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
@ -17,6 +18,15 @@ type Service struct {
// Option is a Service's constructor option. // Option is a Service's constructor option.
type Option func(*cfg) type Option func(*cfg)
// 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)
}
type cfg struct { type cfg struct {
log *logger.Logger log *logger.Logger
@ -37,6 +47,8 @@ type cfg struct {
placer interface { placer interface {
put(*execCtx, bool) (*objectSDK.ID, error) put(*execCtx, bool) (*objectSDK.ID, error)
} }
netInfo NetworkInfo
} }
func defaultCfg() *cfg { func defaultCfg() *cfg {
@ -87,3 +99,10 @@ func WithPutService(p *putsvc.Service) Option {
c.placer = (*putSvcWrapper)(p) c.placer = (*putSvcWrapper)(p)
} }
} }
// WithNetworkInfo returns option to set network information source.
func WithNetworkInfo(netInfo NetworkInfo) Option {
return func(c *cfg) {
c.netInfo = netInfo
}
}