[#1421] engine: Use LockPrm
to store Lock operation parameters
All checks were successful
DCO action / DCO (pull_request) Successful in 2m1s
Tests and linters / Run gofumpt (pull_request) Successful in 2m30s
Vulncheck / Vulncheck (pull_request) Successful in 4m1s
Build / Build Components (pull_request) Successful in 4m34s
Tests and linters / gopls check (pull_request) Successful in 4m37s
Pre-commit hooks / Pre-commit (pull_request) Successful in 5m38s
Tests and linters / Tests (pull_request) Successful in 5m40s
Tests and linters / Tests with -race (pull_request) Successful in 5m48s
Tests and linters / Staticcheck (pull_request) Successful in 5m45s
Tests and linters / Lint (pull_request) Successful in 5m57s
All checks were successful
DCO action / DCO (pull_request) Successful in 2m1s
Tests and linters / Run gofumpt (pull_request) Successful in 2m30s
Vulncheck / Vulncheck (pull_request) Successful in 4m1s
Build / Build Components (pull_request) Successful in 4m34s
Tests and linters / gopls check (pull_request) Successful in 4m37s
Pre-commit hooks / Pre-commit (pull_request) Successful in 5m38s
Tests and linters / Tests (pull_request) Successful in 5m40s
Tests and linters / Tests with -race (pull_request) Successful in 5m48s
Tests and linters / Staticcheck (pull_request) Successful in 5m45s
Tests and linters / Lint (pull_request) Successful in 5m57s
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
parent
edb2bc7b55
commit
fb5c4b0ad3
3 changed files with 54 additions and 15 deletions
|
@ -481,7 +481,12 @@ func (e engineWithoutNotifications) Delete(ctx context.Context, tombstone oid.Ad
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e engineWithoutNotifications) Lock(ctx context.Context, locker oid.Address, toLock []oid.ID) error {
|
func (e engineWithoutNotifications) Lock(ctx context.Context, locker oid.Address, toLock []oid.ID) error {
|
||||||
return e.engine.Lock(ctx, locker.Container(), locker.Object(), toLock)
|
var prm engine.LockPrm
|
||||||
|
prm.WithContainer(locker.Container())
|
||||||
|
prm.WithTarget(locker.Object(), toLock...)
|
||||||
|
|
||||||
|
_, err := e.engine.Lock(ctx, prm)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e engineWithoutNotifications) Put(ctx context.Context, o *objectSDK.Object, indexedContainer bool) error {
|
func (e engineWithoutNotifications) Put(ctx context.Context, o *objectSDK.Object, indexedContainer bool) error {
|
||||||
|
|
|
@ -16,6 +16,28 @@ import (
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LockPrm contains parameters for Lock operation.
|
||||||
|
type LockPrm struct {
|
||||||
|
cnt cid.ID
|
||||||
|
lock oid.ID
|
||||||
|
locked []oid.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithContainer sets the container ID for both the lock and locked objects
|
||||||
|
// since they must belong to the same container.
|
||||||
|
func (p *LockPrm) WithContainer(cnt cid.ID) {
|
||||||
|
p.cnt = cnt
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithTarget sets lock object ID and IDs of objects to be locked.
|
||||||
|
func (p *LockPrm) WithTarget(lock oid.ID, locked ...oid.ID) {
|
||||||
|
p.lock = lock
|
||||||
|
p.locked = locked
|
||||||
|
}
|
||||||
|
|
||||||
|
// LockPrm contains results for Lock operation.
|
||||||
|
type LockRes struct{}
|
||||||
|
|
||||||
var errLockFailed = errors.New("lock operation failed")
|
var errLockFailed = errors.New("lock operation failed")
|
||||||
|
|
||||||
// Lock marks objects as locked with another object. All objects from the
|
// Lock marks objects as locked with another object. All objects from the
|
||||||
|
@ -24,18 +46,18 @@ var errLockFailed = errors.New("lock operation failed")
|
||||||
// Allows locking regular objects only (otherwise returns apistatus.LockNonRegularObject).
|
// Allows locking regular objects only (otherwise returns apistatus.LockNonRegularObject).
|
||||||
//
|
//
|
||||||
// Locked list should be unique. Panics if it is empty.
|
// Locked list should be unique. Panics if it is empty.
|
||||||
func (e *StorageEngine) Lock(ctx context.Context, idCnr cid.ID, locker oid.ID, locked []oid.ID) error {
|
func (e *StorageEngine) Lock(ctx context.Context, prm LockPrm) (LockRes, error) {
|
||||||
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.Lock",
|
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.Lock",
|
||||||
trace.WithAttributes(
|
trace.WithAttributes(
|
||||||
attribute.String("container_id", idCnr.EncodeToString()),
|
attribute.String("container_id", prm.cnt.EncodeToString()),
|
||||||
attribute.String("locker", locker.EncodeToString()),
|
attribute.String("locker", prm.lock.EncodeToString()),
|
||||||
attribute.Int("locked_count", len(locked)),
|
attribute.Int("locked_count", len(prm.locked)),
|
||||||
))
|
))
|
||||||
defer span.End()
|
defer span.End()
|
||||||
defer elapsed("Lock", e.metrics.AddMethodDuration)()
|
defer elapsed("Lock", e.metrics.AddMethodDuration)()
|
||||||
|
|
||||||
return e.execIfNotBlocked(func() error {
|
return LockRes{}, e.execIfNotBlocked(func() error {
|
||||||
return e.lock(ctx, idCnr, locker, locked)
|
return e.lock(ctx, prm.cnt, prm.lock, prm.locked)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,11 @@ func TestLockUserScenario(t *testing.T) {
|
||||||
err = Put(context.Background(), e, lockerObj, false)
|
err = Put(context.Background(), e, lockerObj, false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = e.Lock(context.Background(), cnr, lockerID, []oid.ID{id})
|
var lockPrm LockPrm
|
||||||
|
lockPrm.WithContainer(cnr)
|
||||||
|
lockPrm.WithTarget(lockerID, id)
|
||||||
|
|
||||||
|
_, err = e.Lock(context.Background(), lockPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// 3.
|
// 3.
|
||||||
|
@ -191,7 +195,11 @@ func TestLockExpiration(t *testing.T) {
|
||||||
id, _ := obj.ID()
|
id, _ := obj.ID()
|
||||||
idLock, _ := lock.ID()
|
idLock, _ := lock.ID()
|
||||||
|
|
||||||
err = e.Lock(context.Background(), cnr, idLock, []oid.ID{id})
|
var lockPrm LockPrm
|
||||||
|
lockPrm.WithContainer(cnr)
|
||||||
|
lockPrm.WithTarget(idLock, id)
|
||||||
|
|
||||||
|
_, err = e.Lock(context.Background(), lockPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var inhumePrm InhumePrm
|
var inhumePrm InhumePrm
|
||||||
|
@ -262,7 +270,11 @@ func TestLockForceRemoval(t *testing.T) {
|
||||||
id, _ := obj.ID()
|
id, _ := obj.ID()
|
||||||
idLock, _ := lock.ID()
|
idLock, _ := lock.ID()
|
||||||
|
|
||||||
err = e.Lock(context.Background(), cnr, idLock, []oid.ID{id})
|
var lockPrm LockPrm
|
||||||
|
lockPrm.WithContainer(cnr)
|
||||||
|
lockPrm.WithTarget(idLock, id)
|
||||||
|
|
||||||
|
_, err = e.Lock(context.Background(), lockPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// 3.
|
// 3.
|
||||||
|
@ -327,11 +339,11 @@ func TestLockExpiredRegularObject(t *testing.T) {
|
||||||
require.ErrorAs(t, err, &errNotFound)
|
require.ErrorAs(t, err, &errNotFound)
|
||||||
|
|
||||||
t.Run("lock expired regular object", func(t *testing.T) {
|
t.Run("lock expired regular object", func(t *testing.T) {
|
||||||
err := engine.Lock(context.Background(),
|
var lockPrm LockPrm
|
||||||
address.Container(),
|
lockPrm.WithContainer(address.Container())
|
||||||
oidtest.ID(),
|
lockPrm.WithTarget(oidtest.ID(), address.Object())
|
||||||
[]oid.ID{address.Object()},
|
|
||||||
)
|
_, err := engine.Lock(context.Background(), lockPrm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
res, err := engine.IsLocked(context.Background(), objectcore.AddressOf(object))
|
res, err := engine.IsLocked(context.Background(), objectcore.AddressOf(object))
|
||||||
|
|
Loading…
Add table
Reference in a new issue