From 4f133aebd18110b05e01cebd1b5f3b548d17a4ff Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 25 Aug 2023 12:29:16 +0300 Subject: [PATCH] meta: Move lock check in `objectStatus` It makes logic more reliable if a single function is responsible for the removed/expired/locked statuses. Signed-off-by: Pavel Karpy --- pkg/local_object_storage/metabase/exists.go | 18 +++++++++++++++--- pkg/local_object_storage/metabase/select.go | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/local_object_storage/metabase/exists.go b/pkg/local_object_storage/metabase/exists.go index a2c10fab5ac..4ff9505b0f8 100644 --- a/pkg/local_object_storage/metabase/exists.go +++ b/pkg/local_object_storage/metabase/exists.go @@ -106,15 +106,17 @@ func objectStatus(tx *bbolt.Tx, addr oid.Address, currEpoch uint64) uint8 { // expired previously for less than the one epoch duration var expired bool + oID := addr.Object() + cID := addr.Container() // bucket with objects that have expiration attr attrKey := make([]byte, bucketKeySize+len(objectV2.SysAttributeExpEpoch)) - expirationBucket := tx.Bucket(attributeBucketName(addr.Container(), objectV2.SysAttributeExpEpoch, attrKey)) + expirationBucket := tx.Bucket(attributeBucketName(cID, objectV2.SysAttributeExpEpoch, attrKey)) if expirationBucket != nil { // bucket that contains objects that expire in the current epoch prevEpochBkt := expirationBucket.Bucket([]byte(strconv.FormatUint(currEpoch-1, 10))) if prevEpochBkt != nil { - rawOID := objectKey(addr.Object(), make([]byte, objectKeySize)) + rawOID := objectKey(oID, make([]byte, objectKeySize)) if prevEpochBkt.Get(rawOID) != nil { expired = true } @@ -122,13 +124,23 @@ func objectStatus(tx *bbolt.Tx, addr oid.Address, currEpoch uint64) uint8 { } if expired { + if objectLocked(tx, cID, oID) { + return 0 + } + return 3 } graveyardBkt := tx.Bucket(graveyardBucketName) garbageBkt := tx.Bucket(garbageBucketName) addrKey := addressKey(addr, make([]byte, addressKeySize)) - return inGraveyardWithKey(addrKey, graveyardBkt, garbageBkt) + + removedStatus := inGraveyardWithKey(addrKey, graveyardBkt, garbageBkt) + if removedStatus != 0 && objectLocked(tx, cID, oID) { + return 0 + } + + return removedStatus } func inGraveyardWithKey(addrKey []byte, graveyard, garbageBCK *bbolt.Bucket) uint8 { diff --git a/pkg/local_object_storage/metabase/select.go b/pkg/local_object_storage/metabase/select.go index b54863384a7..0b5492f9027 100644 --- a/pkg/local_object_storage/metabase/select.go +++ b/pkg/local_object_storage/metabase/select.go @@ -121,7 +121,7 @@ func (db *DB) selectObjects(tx *bbolt.Tx, cnr cid.ID, fs object.SearchFilters, c addr.SetContainer(cnr) addr.SetObject(id) - if objectStatus(tx, addr, currEpoch) > 0 && !objectLocked(tx, cnr, id) { + if objectStatus(tx, addr, currEpoch) > 0 { continue // ignore removed objects }