From 4afb928ab61e5992a2f495b352899351c9c6fa54 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 5 Sep 2022 08:48:42 +0300 Subject: [PATCH] [#1674] *: Expire entities after the expiration epoch Signed-off-by: Pavel Karpy --- pkg/core/object/fmt.go | 2 +- pkg/innerring/processors/audit/process.go | 2 +- pkg/local_object_storage/metabase/db_test.go | 4 ++-- pkg/local_object_storage/metabase/exists.go | 6 +++--- pkg/local_object_storage/metabase/iterators.go | 4 ++-- pkg/services/object_manager/tombstone/checker.go | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index de6f120b3..ac4e089e5 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -266,7 +266,7 @@ func (v *FormatValidator) ValidateContent(o *object.Object) error { return fmt.Errorf("lock object expiration epoch: %w", err) } - if currEpoch := v.netState.CurrentEpoch(); lockExp <= currEpoch { + if currEpoch := v.netState.CurrentEpoch(); lockExp < currEpoch { return fmt.Errorf("lock object expiration: %d; current: %d", lockExp, currEpoch) } diff --git a/pkg/innerring/processors/audit/process.go b/pkg/innerring/processors/audit/process.go index 091299300..e64d56354 100644 --- a/pkg/innerring/processors/audit/process.go +++ b/pkg/innerring/processors/audit/process.go @@ -201,7 +201,7 @@ func (ap *Processor) filterExpiredSG(cid cid.ID, sgIDs []oid.ID, } // filter expired epochs - if sg.ExpirationEpoch() > ap.epochSrc.EpochCounter() { + if sg.ExpirationEpoch() >= ap.epochSrc.EpochCounter() { coreSG.SetID(sgID) coreSG.SetStorageGroup(*sg) diff --git a/pkg/local_object_storage/metabase/db_test.go b/pkg/local_object_storage/metabase/db_test.go index 435a1b2db..5ce74d5f2 100644 --- a/pkg/local_object_storage/metabase/db_test.go +++ b/pkg/local_object_storage/metabase/db_test.go @@ -107,12 +107,12 @@ func addAttribute(obj *object.Object, key, val string) { func checkExpiredObjects(t *testing.T, db *meta.DB, f func(exp, nonExp *objectSDK.Object)) { expObj := generateObject(t) - setExpiration(expObj, currEpoch) + setExpiration(expObj, currEpoch-1) require.NoError(t, metaPut(db, expObj, nil)) nonExpObj := generateObject(t) - setExpiration(nonExpObj, currEpoch+1) + setExpiration(nonExpObj, currEpoch) require.NoError(t, metaPut(db, nonExpObj, nil)) diff --git a/pkg/local_object_storage/metabase/exists.go b/pkg/local_object_storage/metabase/exists.go index 45fdf128e..00965d758 100644 --- a/pkg/local_object_storage/metabase/exists.go +++ b/pkg/local_object_storage/metabase/exists.go @@ -112,9 +112,9 @@ func objectStatus(tx *bbolt.Tx, addr oid.Address, currEpoch uint64) uint8 { expirationBucket := tx.Bucket(attributeBucketName(addr.Container(), objectV2.SysAttributeExpEpoch)) if expirationBucket != nil { // bucket that contains objects that expire in the current epoch - currEpochBkt := expirationBucket.Bucket([]byte(strconv.FormatUint(currEpoch, 10))) - if currEpochBkt != nil { - if currEpochBkt.Get(rawOID) != nil { + prevEpochBkt := expirationBucket.Bucket([]byte(strconv.FormatUint(currEpoch-1, 10))) + if prevEpochBkt != nil { + if prevEpochBkt.Get(rawOID) != nil { expired = true } } diff --git a/pkg/local_object_storage/metabase/iterators.go b/pkg/local_object_storage/metabase/iterators.go index 0ec3cf898..85ed49f23 100644 --- a/pkg/local_object_storage/metabase/iterators.go +++ b/pkg/local_object_storage/metabase/iterators.go @@ -61,10 +61,10 @@ func (db *DB) iterateExpired(tx *bbolt.Tx, epoch uint64, h ExpiredObjectHandler) return nil } - expiresAt, err := strconv.ParseUint(string(expKey), 10, 64) + expiresAfter, err := strconv.ParseUint(string(expKey), 10, 64) if err != nil { return fmt.Errorf("could not parse expiration epoch: %w", err) - } else if expiresAt >= epoch { + } else if expiresAfter >= epoch { return nil } diff --git a/pkg/services/object_manager/tombstone/checker.go b/pkg/services/object_manager/tombstone/checker.go index 8cf944e91..3046b3c2e 100644 --- a/pkg/services/object_manager/tombstone/checker.go +++ b/pkg/services/object_manager/tombstone/checker.go @@ -84,7 +84,7 @@ func (g *ExpirationChecker) handleTS(addr string, ts *object.Object, reqEpoch ui } g.cache.Add(addr, epoch) - return epoch > reqEpoch + return epoch >= reqEpoch } }