forked from TrueCloudLab/frostfs-node
[#1502] shard: Add IsLocked
method
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
4ed5dcd9c8
commit
049ab58336
2 changed files with 56 additions and 1 deletions
|
@ -3,6 +3,7 @@ package shard
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
)
|
||||
|
@ -28,3 +29,22 @@ func (s *Shard) Lock(idCnr cid.ID, locker oid.ID, locked []oid.ID) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsLocked checks object locking relation of the provided object. Not found object is
|
||||
// considered as not locked. Requires healthy metabase, returns ErrDegradedMode otherwise.
|
||||
func (s *Shard) IsLocked(addr oid.Address) (bool, error) {
|
||||
m := s.GetMode()
|
||||
if m.NoMetabase() {
|
||||
return false, ErrDegradedMode
|
||||
}
|
||||
|
||||
var prm meta.IsLockedPrm
|
||||
prm.SetAddress(addr)
|
||||
|
||||
res, err := s.metaBase.IsLocked(prm)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return res.Locked(), nil
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
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"
|
||||
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -138,5 +139,39 @@ func TestShard_Lock(t *testing.T) {
|
|||
_, err = sh.Get(getPrm)
|
||||
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestShard_IsLocked(t *testing.T) {
|
||||
sh := newShard(t, false)
|
||||
|
||||
cnr := cidtest.ID()
|
||||
obj := generateObjectWithCID(t, cnr)
|
||||
cnrID, _ := obj.ContainerID()
|
||||
objID, _ := obj.ID()
|
||||
|
||||
lockID := oidtest.ID()
|
||||
|
||||
// put the object
|
||||
|
||||
var putPrm shard.PutPrm
|
||||
putPrm.SetObject(obj)
|
||||
|
||||
_, err := sh.Put(putPrm)
|
||||
require.NoError(t, err)
|
||||
|
||||
// not locked object is not locked
|
||||
|
||||
locked, err := sh.IsLocked(objectcore.AddressOf(obj))
|
||||
require.NoError(t, err)
|
||||
|
||||
require.False(t, locked)
|
||||
|
||||
// locked object is locked
|
||||
|
||||
require.NoError(t, sh.Lock(cnrID, lockID, []oid.ID{objID}))
|
||||
|
||||
locked, err = sh.IsLocked(objectcore.AddressOf(obj))
|
||||
require.NoError(t, err)
|
||||
|
||||
require.True(t, locked)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue