Skip to content

Commit

Permalink
meta: Move lock check in objectStatus
Browse files Browse the repository at this point in the history
It makes logic more reliable if a single function is responsible for the
removed/expired/locked statuses.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell committed Aug 25, 2023
1 parent 040a522 commit 4f133ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions pkg/local_object_storage/metabase/exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,41 @@ 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
}
}
}

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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/local_object_storage/metabase/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4f133ae

Please sign in to comment.