forked from TrueCloudLab/frostfs-node
[#156] metabase: Make freePotentialLocks() pass linter checks
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
fb13902db9
commit
8014fdb21a
1 changed files with 38 additions and 38 deletions
|
@ -138,57 +138,57 @@ func objectLocked(tx *bbolt.Tx, idCnr cid.ID, idObj oid.ID) bool {
|
||||||
// Operation is very resource-intensive, which is caused by the admissibility
|
// Operation is very resource-intensive, which is caused by the admissibility
|
||||||
// of multiple locks. Also, if we knew what objects are locked, it would be
|
// of multiple locks. Also, if we knew what objects are locked, it would be
|
||||||
// possible to speed up the execution.
|
// possible to speed up the execution.
|
||||||
//
|
|
||||||
// nolint: gocognit
|
|
||||||
func freePotentialLocks(tx *bbolt.Tx, idCnr cid.ID, locker oid.ID) error {
|
func freePotentialLocks(tx *bbolt.Tx, idCnr cid.ID, locker oid.ID) error {
|
||||||
bucketLocked := tx.Bucket(bucketNameLocked)
|
bucketLocked := tx.Bucket(bucketNameLocked)
|
||||||
if bucketLocked != nil {
|
if bucketLocked == nil {
|
||||||
key := make([]byte, cidSize)
|
return nil
|
||||||
idCnr.Encode(key)
|
}
|
||||||
|
|
||||||
bucketLockedContainer := bucketLocked.Bucket(key)
|
key := make([]byte, cidSize)
|
||||||
if bucketLockedContainer != nil {
|
idCnr.Encode(key)
|
||||||
keyLocker := objectKey(locker, key)
|
|
||||||
return bucketLockedContainer.ForEach(func(k, v []byte) error {
|
|
||||||
keyLockers, err := decodeList(v)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("decode list of lockers in locked bucket: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range keyLockers {
|
bucketLockedContainer := bucketLocked.Bucket(key)
|
||||||
if bytes.Equal(keyLockers[i], keyLocker) {
|
if bucketLockedContainer == nil {
|
||||||
if len(keyLockers) == 1 {
|
return nil
|
||||||
// locker was all alone
|
}
|
||||||
err = bucketLockedContainer.Delete(k)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("delete locked object record from locked bucket: %w", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// exclude locker
|
|
||||||
keyLockers = append(keyLockers[:i], keyLockers[i+1:]...)
|
|
||||||
|
|
||||||
v, err = encodeList(keyLockers)
|
keyLocker := objectKey(locker, key)
|
||||||
if err != nil {
|
return bucketLockedContainer.ForEach(func(k, v []byte) error {
|
||||||
return fmt.Errorf("encode updated list of lockers: %w", err)
|
keyLockers, err := decodeList(v)
|
||||||
}
|
if err != nil {
|
||||||
|
return fmt.Errorf("decode list of lockers in locked bucket: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// update the record
|
for i := range keyLockers {
|
||||||
err = bucketLockedContainer.Put(k, v)
|
if bytes.Equal(keyLockers[i], keyLocker) {
|
||||||
if err != nil {
|
if len(keyLockers) == 1 {
|
||||||
return fmt.Errorf("update list of lockers: %w", err)
|
// locker was all alone
|
||||||
}
|
err = bucketLockedContainer.Delete(k)
|
||||||
}
|
if err != nil {
|
||||||
|
return fmt.Errorf("delete locked object record from locked bucket: %w", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// exclude locker
|
||||||
|
keyLockers = append(keyLockers[:i], keyLockers[i+1:]...)
|
||||||
|
|
||||||
return nil
|
v, err = encodeList(keyLockers)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("encode updated list of lockers: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the record
|
||||||
|
err = bucketLockedContainer.Put(k, v)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("update list of lockers: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLockedPrm groups the parameters of IsLocked operation.
|
// IsLockedPrm groups the parameters of IsLocked operation.
|
||||||
|
|
Loading…
Reference in a new issue