[#1693] storage: Replace conditional panics with asserts

Change-Id: I9d8ccde3c71fca716856c7bfc53da20ee0542f20
Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
Ekaterina Lebedeva 2025-04-08 16:47:52 +03:00
parent a285d8924f
commit fc6abe30b8
4 changed files with 17 additions and 26 deletions

View file

@ -2,6 +2,8 @@ package fstree
import (
"sync"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
)
// FileCounter used to count files in FSTree. The implementation must be thread-safe.
@ -52,16 +54,11 @@ func (c *SimpleCounter) Dec(size uint64) {
c.mtx.Lock()
defer c.mtx.Unlock()
if c.count > 0 {
c.count--
} else {
panic("fstree.SimpleCounter: invalid count")
}
if c.size >= size {
c.size -= size
} else {
panic("fstree.SimpleCounter: invalid size")
}
assert.True(c.count > 0, "fstree.SimpleCounter: invalid count")
c.count--
assert.True(c.size >= size, "fstree.SimpleCounter: invalid size")
c.size -= size
}
func (c *SimpleCounter) CountSize() (uint64, uint64) {

View file

@ -7,6 +7,7 @@ import (
"slices"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
@ -63,9 +64,7 @@ func (db *DB) Lock(ctx context.Context, cnr cid.ID, locker oid.ID, locked []oid.
return ErrReadOnlyMode
}
if len(locked) == 0 {
panic("empty locked list")
}
assert.False(len(locked) == 0, "empty locked list")
err := db.lockInternal(locked, cnr, locker)
success = err == nil

View file

@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
@ -278,9 +279,7 @@ func objectKey(obj oid.ID, key []byte) []byte {
//
// firstIrregularObjectType(tx, cnr, obj) usage allows getting object type.
func firstIrregularObjectType(tx *bbolt.Tx, idCnr cid.ID, objs ...[]byte) objectSDK.Type {
if len(objs) == 0 {
panic("empty object list in firstIrregularObjectType")
}
assert.False(len(objs) == 0, "empty object list in firstIrregularObjectType")
var keys [2][1 + cidSize]byte

View file

@ -3,6 +3,8 @@ package writecache
import (
"errors"
"sync"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
)
var errLimiterClosed = errors.New("acquire failed: limiter closed")
@ -45,17 +47,11 @@ func (l *flushLimiter) release(size uint64) {
l.cond.L.Lock()
defer l.cond.L.Unlock()
if l.size >= size {
l.size -= size
} else {
panic("flushLimiter: invalid size")
}
assert.True(l.size >= size, "flushLimiter: invalid size")
l.size -= size
if l.count > 0 {
l.count--
} else {
panic("flushLimiter: invalid count")
}
assert.True(l.count > 0, "flushLimiter: invalid count")
l.count--
l.cond.Broadcast()
}