[#1693] services: Replace conditional panics with asserts
Change-Id: Ic79609e6ad867caa88ad245b3014aa7fc32e05a8 Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
fc6abe30b8
commit
bc045b29e2
4 changed files with 14 additions and 13 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/version"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/version"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util/response"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util/response"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/netmap"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/netmap"
|
||||||
|
@ -46,10 +47,12 @@ type NetworkInfo interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExecutionService(s NodeState, v versionsdk.Version, netInfo NetworkInfo, respSvc *response.Service) Server {
|
func NewExecutionService(s NodeState, v versionsdk.Version, netInfo NetworkInfo, respSvc *response.Service) Server {
|
||||||
if s == nil || netInfo == nil || !version.IsValid(v) || respSvc == nil {
|
// this should never happen, otherwise it's a programmer's bug
|
||||||
// this should never happen, otherwise it programmers bug
|
msg := "BUG: can't create netmap execution service"
|
||||||
panic("can't create netmap execution service")
|
assert.False(s == nil, msg, "node state is nil")
|
||||||
}
|
assert.False(netInfo == nil, msg, "network info is nil")
|
||||||
|
assert.False(respSvc == nil, msg, "response service is nil")
|
||||||
|
assert.True(version.IsValid(v), msg, "invalid version")
|
||||||
|
|
||||||
res := &executorSvc{
|
res := &executorSvc{
|
||||||
state: s,
|
state: s,
|
||||||
|
|
|
@ -3,6 +3,7 @@ package tombstone
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||||||
lru "github.com/hashicorp/golang-lru/v2"
|
lru "github.com/hashicorp/golang-lru/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -49,9 +50,7 @@ func NewChecker(oo ...Option) *ExpirationChecker {
|
||||||
panicOnNil(cfg.tsSource, "Tombstone source")
|
panicOnNil(cfg.tsSource, "Tombstone source")
|
||||||
|
|
||||||
cache, err := lru.New[string, uint64](cfg.cacheSize)
|
cache, err := lru.New[string, uint64](cfg.cacheSize)
|
||||||
if err != nil {
|
assert.NoError(err, fmt.Sprintf("could not create LRU cache with %d size", cfg.cacheSize))
|
||||||
panic(fmt.Errorf("could not create LRU cache with %d size: %w", cfg.cacheSize, err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ExpirationChecker{
|
return &ExpirationChecker{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
|
||||||
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
|
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
||||||
|
@ -38,9 +39,7 @@ func (s *TombstoneSourcePrm) SetGetService(v *getsvc.Service) {
|
||||||
// Panics if any of the provided options does not allow
|
// Panics if any of the provided options does not allow
|
||||||
// constructing a valid tombstone local Source.
|
// constructing a valid tombstone local Source.
|
||||||
func NewSource(p TombstoneSourcePrm) Source {
|
func NewSource(p TombstoneSourcePrm) Source {
|
||||||
if p.s == nil {
|
assert.False(p.s == nil, "Tombstone source: nil object service")
|
||||||
panic("Tombstone source: nil object service")
|
|
||||||
}
|
|
||||||
|
|
||||||
return Source(p)
|
return Source(p)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package policer
|
package policer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/assert"
|
||||||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||||
lru "github.com/hashicorp/golang-lru/v2"
|
lru "github.com/hashicorp/golang-lru/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -57,9 +59,7 @@ func New(opts ...Option) *Policer {
|
||||||
c.log = c.log.With(zap.String("component", "Object Policer"))
|
c.log = c.log.With(zap.String("component", "Object Policer"))
|
||||||
|
|
||||||
cache, err := lru.New[oid.Address, time.Time](int(c.cacheSize))
|
cache, err := lru.New[oid.Address, time.Time](int(c.cacheSize))
|
||||||
if err != nil {
|
assert.NoError(err, fmt.Sprintf("could not create LRU cache with %d size", c.cacheSize))
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Policer{
|
return &Policer{
|
||||||
cfg: c,
|
cfg: c,
|
||||||
|
|
Loading…
Add table
Reference in a new issue