From 18ec5d7c8e14c4129fa9edb7155c650bbeab0336 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 6 Jun 2022 17:44:37 +0300 Subject: [PATCH] [#1461] meta: Return error on lock object removal Signed-off-by: Pavel Karpy --- pkg/local_object_storage/engine/inhume.go | 15 +++++++++++---- pkg/local_object_storage/engine/lock_test.go | 3 ++- pkg/local_object_storage/metabase/inhume.go | 6 +++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pkg/local_object_storage/engine/inhume.go b/pkg/local_object_storage/engine/inhume.go index 3d99ffe62..3323a6f9f 100644 --- a/pkg/local_object_storage/engine/inhume.go +++ b/pkg/local_object_storage/engine/inhume.go @@ -75,6 +75,8 @@ func (e *StorageEngine) inhume(prm InhumePrm) (InhumeRes, error) { } switch e.inhumeAddr(prm.addrs[i], shPrm, true) { + case 2: + return InhumeRes{}, meta.ErrLockObjectRemoval case 1: return InhumeRes{}, apistatus.ObjectLocked{} case 0: @@ -93,7 +95,8 @@ func (e *StorageEngine) inhume(prm InhumePrm) (InhumeRes, error) { // Returns: // 0 - fail // 1 - object locked -// 2 - ok +// 2 - lock object removal +// 3 - ok func (e *StorageEngine) inhumeAddr(addr oid.Address, prm shard.InhumePrm, checkExists bool) (status uint8) { root := false var errLocked apistatus.ObjectLocked @@ -114,7 +117,7 @@ func (e *StorageEngine) inhumeAddr(addr oid.Address, prm shard.InhumePrm, checkE if err != nil { if shard.IsErrRemoved(err) { // inhumed once - no need to be inhumed again - status = 2 + status = 3 return true } @@ -134,15 +137,19 @@ func (e *StorageEngine) inhumeAddr(addr oid.Address, prm shard.InhumePrm, checkE if err != nil { e.reportShardError(sh, "could not inhume object in shard", err) - if errors.As(err, &errLocked) { + switch { + case errors.As(err, &errLocked): status = 1 return true + case errors.Is(err, meta.ErrLockObjectRemoval): + status = 2 + return true } return false } - status = 2 + status = 3 return true }) diff --git a/pkg/local_object_storage/engine/lock_test.go b/pkg/local_object_storage/engine/lock_test.go index 651efcaaa..ba1582a46 100644 --- a/pkg/local_object_storage/engine/lock_test.go +++ b/pkg/local_object_storage/engine/lock_test.go @@ -9,6 +9,7 @@ import ( objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" objectcore "github.com/nspcc-dev/neofs-node/pkg/core/object" + meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/nspcc-dev/neofs-node/pkg/util" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" @@ -133,7 +134,7 @@ func TestLockUserScenario(t *testing.T) { inhumePrm.WithTarget(tombForLockAddr, lockerAddr) _, err = e.Inhume(inhumePrm) - require.NoError(t, err, new(apistatus.ObjectLocked)) + require.ErrorIs(t, err, meta.ErrLockObjectRemoval) // 5. for i := range chEvents { diff --git a/pkg/local_object_storage/metabase/inhume.go b/pkg/local_object_storage/metabase/inhume.go index 2c20fdee0..81140ee25 100644 --- a/pkg/local_object_storage/metabase/inhume.go +++ b/pkg/local_object_storage/metabase/inhume.go @@ -93,6 +93,10 @@ func Inhume(db *DB, target, tomb oid.Address) error { var errBreakBucketForEach = errors.New("bucket ForEach break") +// ErrLockObjectRemoval is returned when inhume operation is being +// performed on lock object, and it is not a forced object removal. +var ErrLockObjectRemoval = errors.New("lock object removal") + // Inhume marks objects as removed but not removes it from metabase. // // Allows inhuming non-locked objects only. Returns apistatus.ObjectLocked @@ -149,7 +153,7 @@ func (db *DB) Inhume(prm InhumePrm) (res InhumeRes, err error) { // `WithForceGCMark` option if !prm.forceRemoval { if isLockObject(tx, cnr, id) { - return fmt.Errorf("lock object removal, CID: %s, OID: %s", cnr, id) + return ErrLockObjectRemoval } lockWasChecked = true