2022-02-15 22:20:44 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
meta "github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
2022-02-15 22:20:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Lock marks objects as locked with another object. All objects from the
|
|
|
|
// specified container.
|
|
|
|
//
|
2022-03-05 08:46:02 +00:00
|
|
|
// Allows locking regular objects only (otherwise returns apistatus.LockNonRegularObject).
|
2022-02-15 22:20:44 +00:00
|
|
|
//
|
|
|
|
// Locked list should be unique. Panics if it is empty.
|
|
|
|
func (s *Shard) Lock(idCnr cid.ID, locker oid.ID, locked []oid.ID) error {
|
2022-06-29 11:27:36 +00:00
|
|
|
m := s.GetMode()
|
|
|
|
if m.ReadOnly() {
|
2022-02-15 22:20:44 +00:00
|
|
|
return ErrReadOnlyMode
|
2022-06-29 11:27:36 +00:00
|
|
|
} else if m.NoMetabase() {
|
|
|
|
return ErrDegradedMode
|
2022-02-15 22:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err := s.metaBase.Lock(idCnr, locker, locked)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("metabase lock: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-11-12 11:59:58 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|