From b585791d6e459f79862de49aa1732671f9f9c1f4 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 16 Feb 2022 01:17:40 +0300 Subject: [PATCH] [#1175] metabase: Return status error on Lock of irregular object Make `DB.Lock` to return `apistatus.IrregularObjectLock` if at least one of the locked objects is irregular (not of type REGULAR). Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/metabase/lock.go | 9 +++------ pkg/local_object_storage/metabase/lock_test.go | 5 ++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/local_object_storage/metabase/lock.go b/pkg/local_object_storage/metabase/lock.go index ecf14ec17..390e941ec 100644 --- a/pkg/local_object_storage/metabase/lock.go +++ b/pkg/local_object_storage/metabase/lock.go @@ -2,9 +2,9 @@ package meta import ( "bytes" - "errors" "fmt" + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -22,13 +22,10 @@ func bucketNameLockers(idCnr cid.ID) []byte { return []byte(idCnr.String() + bucketNameSuffixLockers) } -// ErrLockIrregularObject is returned when trying to lock an irregular object. -var ErrLockIrregularObject = errors.New("locking irregular object") - // Lock marks objects as locked with another object. All objects are from the // specified container. // -// Allows locking regular objects only (otherwise returns ErrLockIrregularObject). +// Allows locking regular objects only (otherwise returns apistatus.IrregularObjectLock). // // Locked list should be unique. Panics if it is empty. func (db *DB) Lock(cnr cid.ID, locker oid.ID, locked []oid.ID) error { @@ -45,7 +42,7 @@ func (db *DB) Lock(cnr cid.ID, locker oid.ID, locked []oid.ID) error { } if firstIrregularObjectType(tx, cnr, bucketKeysLocked...) != object.TypeRegular { - return ErrLockIrregularObject + return apistatus.IrregularObjectLock{} } bucketLocked, err := tx.CreateBucketIfNotExists(bucketNameLocked) diff --git a/pkg/local_object_storage/metabase/lock_test.go b/pkg/local_object_storage/metabase/lock_test.go index 8cea077a2..f787f6d07 100644 --- a/pkg/local_object_storage/metabase/lock_test.go +++ b/pkg/local_object_storage/metabase/lock_test.go @@ -4,6 +4,7 @@ import ( "testing" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" + apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" @@ -36,12 +37,14 @@ func TestDB_Lock(t *testing.T) { err := meta.Put(db, obj, nil) require.NoError(t, err, typ) + var e apistatus.IrregularObjectLock + // try to lock it err = db.Lock(cnr, *oidtest.ID(), []oid.ID{*obj.ID()}) if typ == object.TypeRegular { require.NoError(t, err, typ) } else { - require.ErrorIs(t, err, meta.ErrLockIrregularObject, typ) + require.ErrorAs(t, err, &e, typ) } } })