forked from TrueCloudLab/frostfs-node
[#1693] storage: Replace conditional panics with asserts
Change-Id: I9d8ccde3c71fca716856c7bfc53da20ee0542f20 Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
a285d8924f
commit
fc6abe30b8
4 changed files with 17 additions and 26 deletions
|
@ -2,6 +2,8 @@ package fstree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileCounter used to count files in FSTree. The implementation must be thread-safe.
|
// 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()
|
c.mtx.Lock()
|
||||||
defer c.mtx.Unlock()
|
defer c.mtx.Unlock()
|
||||||
|
|
||||||
if c.count > 0 {
|
assert.True(c.count > 0, "fstree.SimpleCounter: invalid count")
|
||||||
c.count--
|
c.count--
|
||||||
} else {
|
|
||||||
panic("fstree.SimpleCounter: invalid count")
|
assert.True(c.size >= size, "fstree.SimpleCounter: invalid size")
|
||||||
}
|
c.size -= size
|
||||||
if c.size >= size {
|
|
||||||
c.size -= size
|
|
||||||
} else {
|
|
||||||
panic("fstree.SimpleCounter: invalid size")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SimpleCounter) CountSize() (uint64, uint64) {
|
func (c *SimpleCounter) CountSize() (uint64, uint64) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"slices"
|
"slices"
|
||||||
"time"
|
"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/internal/metaerr"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
"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
|
return ErrReadOnlyMode
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(locked) == 0 {
|
assert.False(len(locked) == 0, "empty locked list")
|
||||||
panic("empty locked list")
|
|
||||||
}
|
|
||||||
|
|
||||||
err := db.lockInternal(locked, cnr, locker)
|
err := db.lockInternal(locked, cnr, locker)
|
||||||
success = err == nil
|
success = err == nil
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
|
||||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||||
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
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.
|
// firstIrregularObjectType(tx, cnr, obj) usage allows getting object type.
|
||||||
func firstIrregularObjectType(tx *bbolt.Tx, idCnr cid.ID, objs ...[]byte) objectSDK.Type {
|
func firstIrregularObjectType(tx *bbolt.Tx, idCnr cid.ID, objs ...[]byte) objectSDK.Type {
|
||||||
if len(objs) == 0 {
|
assert.False(len(objs) == 0, "empty object list in firstIrregularObjectType")
|
||||||
panic("empty object list in firstIrregularObjectType")
|
|
||||||
}
|
|
||||||
|
|
||||||
var keys [2][1 + cidSize]byte
|
var keys [2][1 + cidSize]byte
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package writecache
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errLimiterClosed = errors.New("acquire failed: limiter closed")
|
var errLimiterClosed = errors.New("acquire failed: limiter closed")
|
||||||
|
@ -45,17 +47,11 @@ func (l *flushLimiter) release(size uint64) {
|
||||||
l.cond.L.Lock()
|
l.cond.L.Lock()
|
||||||
defer l.cond.L.Unlock()
|
defer l.cond.L.Unlock()
|
||||||
|
|
||||||
if l.size >= size {
|
assert.True(l.size >= size, "flushLimiter: invalid size")
|
||||||
l.size -= size
|
l.size -= size
|
||||||
} else {
|
|
||||||
panic("flushLimiter: invalid size")
|
|
||||||
}
|
|
||||||
|
|
||||||
if l.count > 0 {
|
assert.True(l.count > 0, "flushLimiter: invalid count")
|
||||||
l.count--
|
l.count--
|
||||||
} else {
|
|
||||||
panic("flushLimiter: invalid count")
|
|
||||||
}
|
|
||||||
|
|
||||||
l.cond.Broadcast()
|
l.cond.Broadcast()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue