[#461] metabase: Delete graves regardless of the presence of objects

`Inhume` operation can be performed on already deleted objects, and in this
case the entry will be added to the graveyard. `Delete` operation finishes
with error if object is not presented in metabase. However, the entry in the
cemetery must be deleted regardless of the presence of the object.

Additionally, now `Delete` does not return an error in the absence of an
object.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-04-06 17:07:42 +03:00 committed by Alex Vanin
parent 27cf6f5112
commit df909984bd
2 changed files with 27 additions and 4 deletions

View file

@ -6,6 +6,7 @@ import (
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/pkg/errors"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
) )
@ -74,9 +75,22 @@ func (db *DB) deleteGroup(tx *bbolt.Tx, addrs []*objectSDK.Address) error {
} }
func (db *DB) delete(tx *bbolt.Tx, addr *objectSDK.Address, refCounter referenceCounter) error { func (db *DB) delete(tx *bbolt.Tx, addr *objectSDK.Address, refCounter referenceCounter) error {
// remove record from graveyard
graveyard := tx.Bucket(graveyardBucketName)
if graveyard != nil {
err := graveyard.Delete(addressKey(addr))
if err != nil {
return errors.Wrap(err, "could not remove from graveyard")
}
}
// unmarshal object, work only with physically stored (raw == true) objects // unmarshal object, work only with physically stored (raw == true) objects
obj, err := db.get(tx, addr, false, true) obj, err := db.get(tx, addr, false, true)
if err != nil { if err != nil {
if errors.Is(err, object.ErrNotFound) {
return nil
}
return err return err
} }
@ -257,10 +271,6 @@ func delUniqueIndexes(obj *object.Object, isParent bool) ([]namedBucketItem, err
name: rootBucketName(addr.ContainerID()), name: rootBucketName(addr.ContainerID()),
key: objKey, key: objKey,
}, },
namedBucketItem{ // remove from graveyard index
name: graveyardBucketName,
key: addrKey,
},
namedBucketItem{ // remove from ToMoveIt index namedBucketItem{ // remove from ToMoveIt index
name: toMoveItBucketName, name: toMoveItBucketName,
key: addrKey, key: addrKey,

View file

@ -102,3 +102,16 @@ func TestDeleteAllChildren(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.False(t, ex) require.False(t, ex)
} }
func TestGraveOnlyDelete(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
addr := generateAddress()
// inhume non-existent object by address
require.NoError(t, meta.Inhume(db, addr, nil))
// delete the object data
require.NoError(t, meta.Delete(db, addr))
}