[#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:
parent
23fcacd3f2
commit
b585791d6e
2 changed files with 7 additions and 7 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue