[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-02-16 01:17:40 +03:00 committed by LeL
parent 23fcacd3f2
commit b585791d6e
2 changed files with 7 additions and 7 deletions

View file

@ -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)

View file

@ -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)
}
}
})