From 6ed85ff1e1c2499f50b4f6c36d79849547a1696f Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 16 Feb 2022 01:20:44 +0300 Subject: [PATCH] [#1175] shard: Implement Lock operation Implement `Shard.Lock` method which required rw mode and calls `Lock` on underlying metabase. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/shard/lock.go | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 pkg/local_object_storage/shard/lock.go diff --git a/pkg/local_object_storage/shard/lock.go b/pkg/local_object_storage/shard/lock.go new file mode 100644 index 000000000..0ef064580 --- /dev/null +++ b/pkg/local_object_storage/shard/lock.go @@ -0,0 +1,27 @@ +package shard + +import ( + "fmt" + + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + oid "github.com/nspcc-dev/neofs-sdk-go/object/id" +) + +// Lock marks objects as locked with another object. All objects from the +// specified container. +// +// Allows locking regular objects only (otherwise returns apistatus.IrregularObjectLock). +// +// Locked list should be unique. Panics if it is empty. +func (s *Shard) Lock(idCnr cid.ID, locker oid.ID, locked []oid.ID) error { + if s.GetMode() == ModeReadOnly { + return ErrReadOnlyMode + } + + err := s.metaBase.Lock(idCnr, locker, locked) + if err != nil { + return fmt.Errorf("metabase lock: %w", err) + } + + return nil +}