From df909984bde4fb280d22846e8cf0fbd6223d6d9c Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 6 Apr 2021 17:07:42 +0300 Subject: [PATCH] [#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 --- pkg/local_object_storage/metabase/delete.go | 18 ++++++++++++++---- .../metabase/delete_test.go | 13 +++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pkg/local_object_storage/metabase/delete.go b/pkg/local_object_storage/metabase/delete.go index bc12eaeae..3b9099365 100644 --- a/pkg/local_object_storage/metabase/delete.go +++ b/pkg/local_object_storage/metabase/delete.go @@ -6,6 +6,7 @@ import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" + "github.com/pkg/errors" "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 { + // 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 obj, err := db.get(tx, addr, false, true) if err != nil { + if errors.Is(err, object.ErrNotFound) { + return nil + } + return err } @@ -257,10 +271,6 @@ func delUniqueIndexes(obj *object.Object, isParent bool) ([]namedBucketItem, err name: rootBucketName(addr.ContainerID()), key: objKey, }, - namedBucketItem{ // remove from graveyard index - name: graveyardBucketName, - key: addrKey, - }, namedBucketItem{ // remove from ToMoveIt index name: toMoveItBucketName, key: addrKey, diff --git a/pkg/local_object_storage/metabase/delete_test.go b/pkg/local_object_storage/metabase/delete_test.go index 25cde6b90..138b5bbf8 100644 --- a/pkg/local_object_storage/metabase/delete_test.go +++ b/pkg/local_object_storage/metabase/delete_test.go @@ -102,3 +102,16 @@ func TestDeleteAllChildren(t *testing.T) { require.NoError(t, err) 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)) +}