[#1704] metabase: Do not ignore errors by Delete
All checks were successful
Vulncheck / Vulncheck (push) Successful in 1m12s
Pre-commit hooks / Pre-commit (push) Successful in 1m43s
Build / Build Components (push) Successful in 1m54s
Tests and linters / Run gofumpt (push) Successful in 3m31s
Tests and linters / Tests (push) Successful in 3m37s
Tests and linters / Lint (push) Successful in 3m44s
Tests and linters / Staticcheck (push) Successful in 3m49s
OCI image / Build container images (push) Successful in 4m39s
Tests and linters / gopls check (push) Successful in 4m32s
Tests and linters / Tests with -race (push) Successful in 7m16s

Change-Id: Ie7b89071a007f53f55879ff9e7e0c25d24ad5dbf
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2025-04-03 10:09:05 +03:00
parent 2a6cdbdb72
commit 634de97509
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0

View file

@ -376,11 +376,12 @@ func parentLength(tx *bbolt.Tx, addr oid.Address) int {
return len(lst) return len(lst)
} }
func delUniqueIndexItem(tx *bbolt.Tx, item namedBucketItem) { func delUniqueIndexItem(tx *bbolt.Tx, item namedBucketItem) error {
bkt := tx.Bucket(item.name) bkt := tx.Bucket(item.name)
if bkt != nil { if bkt != nil {
_ = bkt.Delete(item.key) // ignore error, best effort there return bkt.Delete(item.key)
} }
return nil
} }
func delListIndexItem(tx *bbolt.Tx, item namedBucketItem) error { func delListIndexItem(tx *bbolt.Tx, item namedBucketItem) error {
@ -405,19 +406,16 @@ func delListIndexItem(tx *bbolt.Tx, item namedBucketItem) error {
// if list empty, remove the key from <list> bucket // if list empty, remove the key from <list> bucket
if len(lst) == 0 { if len(lst) == 0 {
_ = bkt.Delete(item.key) // ignore error, best effort there return bkt.Delete(item.key)
return nil
} }
// if list is not empty, then update it // if list is not empty, then update it
encodedLst, err := encodeList(lst) encodedLst, err := encodeList(lst)
if err != nil { if err != nil {
return nil // ignore error, best effort there return err
} }
_ = bkt.Put(item.key, encodedLst) // ignore error, best effort there return bkt.Put(item.key, encodedLst)
return nil
} }
func delFKBTIndexItem(tx *bbolt.Tx, item namedBucketItem) error { func delFKBTIndexItem(tx *bbolt.Tx, item namedBucketItem) error {
@ -480,35 +478,47 @@ func delUniqueIndexes(tx *bbolt.Tx, obj *objectSDK.Object, isParent bool) error
return ErrUnknownObjectType return ErrUnknownObjectType
} }
delUniqueIndexItem(tx, namedBucketItem{ if err := delUniqueIndexItem(tx, namedBucketItem{
name: bucketName, name: bucketName,
key: objKey, key: objKey,
}) }); err != nil {
return err
}
} else { } else {
delUniqueIndexItem(tx, namedBucketItem{ if err := delUniqueIndexItem(tx, namedBucketItem{
name: parentBucketName(cnr, bucketName), name: parentBucketName(cnr, bucketName),
key: objKey, key: objKey,
}) }); err != nil {
return err
}
} }
delUniqueIndexItem(tx, namedBucketItem{ // remove from storage id index if err := delUniqueIndexItem(tx, namedBucketItem{ // remove from storage id index
name: smallBucketName(cnr, bucketName), name: smallBucketName(cnr, bucketName),
key: objKey, key: objKey,
}) }); err != nil {
delUniqueIndexItem(tx, namedBucketItem{ // remove from root index return err
}
if err := delUniqueIndexItem(tx, namedBucketItem{ // remove from root index
name: rootBucketName(cnr, bucketName), name: rootBucketName(cnr, bucketName),
key: objKey, key: objKey,
}) }); err != nil {
return err
}
if expEpoch, ok := hasExpirationEpoch(obj); ok { if expEpoch, ok := hasExpirationEpoch(obj); ok {
delUniqueIndexItem(tx, namedBucketItem{ if err := delUniqueIndexItem(tx, namedBucketItem{
name: expEpochToObjectBucketName, name: expEpochToObjectBucketName,
key: expirationEpochKey(expEpoch, cnr, addr.Object()), key: expirationEpochKey(expEpoch, cnr, addr.Object()),
}) }); err != nil {
delUniqueIndexItem(tx, namedBucketItem{ return err
}
if err := delUniqueIndexItem(tx, namedBucketItem{
name: objectToExpirationEpochBucketName(cnr, make([]byte, bucketKeySize)), name: objectToExpirationEpochBucketName(cnr, make([]byte, bucketKeySize)),
key: objKey, key: objKey,
}) }); err != nil {
return err
}
} }
return nil return nil
@ -535,10 +545,12 @@ func deleteECRelatedInfo(tx *bbolt.Tx, garbageBKT *bbolt.Bucket, obj *objectSDK.
// also drop EC parent root info if current EC chunk is the last one // also drop EC parent root info if current EC chunk is the last one
if !hasAnyChunks { if !hasAnyChunks {
delUniqueIndexItem(tx, namedBucketItem{ if err := delUniqueIndexItem(tx, namedBucketItem{
name: rootBucketName(cnr, make([]byte, bucketKeySize)), name: rootBucketName(cnr, make([]byte, bucketKeySize)),
key: objectKey(ech.Parent(), make([]byte, objectKeySize)), key: objectKey(ech.Parent(), make([]byte, objectKeySize)),
}) }); err != nil {
return err
}
} }
if ech.ParentSplitParentID() == nil { if ech.ParentSplitParentID() == nil {
@ -572,11 +584,10 @@ func deleteECRelatedInfo(tx *bbolt.Tx, garbageBKT *bbolt.Bucket, obj *objectSDK.
} }
// drop split info // drop split info
delUniqueIndexItem(tx, namedBucketItem{ return delUniqueIndexItem(tx, namedBucketItem{
name: rootBucketName(cnr, make([]byte, bucketKeySize)), name: rootBucketName(cnr, make([]byte, bucketKeySize)),
key: objectKey(*ech.ParentSplitParentID(), make([]byte, objectKeySize)), key: objectKey(*ech.ParentSplitParentID(), make([]byte, objectKeySize)),
}) })
return nil
} }
func hasAnyECChunks(tx *bbolt.Tx, ech *objectSDK.ECHeader, cnr cid.ID) bool { func hasAnyECChunks(tx *bbolt.Tx, ech *objectSDK.ECHeader, cnr cid.ID) bool {