From b8d1144839dcc16117768d4526587c83a0fac2fd Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 17 Feb 2021 15:30:11 +0300 Subject: [PATCH] [#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 --- pkg/services/object/delete/exec.go | 8 ++++++++ pkg/services/object/delete/local.go | 16 ++++++++++++++++ pkg/services/object/delete/service.go | 19 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/pkg/services/object/delete/exec.go b/pkg/services/object/delete/exec.go index fa4afc9a9..42badef67 100644 --- a/pkg/services/object/delete/exec.go +++ b/pkg/services/object/delete/exec.go @@ -2,9 +2,11 @@ package deletesvc import ( "context" + "strconv" "github.com/nspcc-dev/neofs-api-go/pkg/container" 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/services/object/util" "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.SetPayload(payload) + a := objectSDK.NewAttribute() + a.SetKey(objectV2.SysAttributeExpEpoch) + a.SetValue(strconv.FormatUint(exec.tombstone.ExpirationEpoch(), 10)) + + exec.tombstoneObj.SetAttributes(a) + return true } diff --git a/pkg/services/object/delete/local.go b/pkg/services/object/delete/local.go index 26b0d9dde..cd446ca98 100644 --- a/pkg/services/object/delete/local.go +++ b/pkg/services/object/delete/local.go @@ -2,6 +2,7 @@ package deletesvc import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" + "go.uber.org/zap" ) func (exec *execCtx) executeLocal() { @@ -25,7 +26,22 @@ func (exec *execCtx) executeLocal() { } 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.SetExpirationEpoch( + exec.svc.netInfo.CurrentEpoch() + tsLifetime, + ) exec.addMembers([]*objectSDK.ID{exec.address().ObjectID()}) exec.log.Debug("forming split info...") diff --git a/pkg/services/object/delete/service.go b/pkg/services/object/delete/service.go index db02754a8..b6e249d45 100644 --- a/pkg/services/object/delete/service.go +++ b/pkg/services/object/delete/service.go @@ -2,6 +2,7 @@ package deletesvc import ( 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" putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" 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. 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 { log *logger.Logger @@ -37,6 +47,8 @@ type cfg struct { placer interface { put(*execCtx, bool) (*objectSDK.ID, error) } + + netInfo NetworkInfo } func defaultCfg() *cfg { @@ -87,3 +99,10 @@ func WithPutService(p *putsvc.Service) Option { c.placer = (*putSvcWrapper)(p) } } + +// WithNetworkInfo returns option to set network information source. +func WithNetworkInfo(netInfo NetworkInfo) Option { + return func(c *cfg) { + c.netInfo = netInfo + } +}