forked from TrueCloudLab/frostfs-node
101 lines
2.8 KiB
Go
101 lines
2.8 KiB
Go
package qos
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"math"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/limits"
|
|
)
|
|
|
|
var errWeightsMustBeSpecified = errors.New("invalid weights: weights must be specified for all tags or not specified for any")
|
|
|
|
type tagConfig struct {
|
|
Shares, Limit, Reserved *float64
|
|
}
|
|
|
|
func validateConfig(c *limits.Config) error {
|
|
if err := validateOpConfig(c.Read()); err != nil {
|
|
return fmt.Errorf("limits 'read' section validation error: %w", err)
|
|
}
|
|
if err := validateOpConfig(c.Write()); err != nil {
|
|
return fmt.Errorf("limits 'write' section validation error: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func validateOpConfig(c limits.OpConfig) error {
|
|
if c.MaxRunningOps <= 0 {
|
|
return fmt.Errorf("invalid 'max_running_ops = %d': must be greater than zero", c.MaxRunningOps)
|
|
}
|
|
if c.MaxWaitingOps <= 0 {
|
|
return fmt.Errorf("invalid 'max_waiting_ops = %d': must be greater than zero", c.MaxWaitingOps)
|
|
}
|
|
if c.IdleTimeout <= 0 {
|
|
return fmt.Errorf("invalid 'idle_timeout = %s': must be greater than zero", c.IdleTimeout.String())
|
|
}
|
|
if err := validateTags(c.Tags); err != nil {
|
|
return fmt.Errorf("'tags' config section validation error: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func validateTags(configTags []limits.IOTagConfig) error {
|
|
tags := map[IOTag]tagConfig{
|
|
IOTagClient: {},
|
|
IOTagInternal: {},
|
|
IOTagBackground: {},
|
|
IOTagWritecache: {},
|
|
IOTagPolicer: {},
|
|
}
|
|
for _, t := range configTags {
|
|
tag, err := FromRawString(t.Tag)
|
|
if err != nil {
|
|
return fmt.Errorf("invalid tag %s: %w", t.Tag, err)
|
|
}
|
|
if _, ok := tags[tag]; !ok {
|
|
return fmt.Errorf("tag %s is not configurable", t.Tag)
|
|
}
|
|
tags[tag] = tagConfig{
|
|
Shares: t.Weight,
|
|
Limit: t.LimitOps,
|
|
Reserved: t.ReservedOps,
|
|
}
|
|
}
|
|
idx := 0
|
|
var shares float64
|
|
for t, v := range tags {
|
|
if idx == 0 {
|
|
idx++
|
|
shares = float64Value(v.Shares)
|
|
} else if (shares != 0 && float64Value(v.Shares) == 0) || (shares == 0 && float64Value(v.Shares) != 0) {
|
|
return errWeightsMustBeSpecified
|
|
}
|
|
if float64Value(v.Shares) < 0 || math.IsNaN(float64Value(v.Shares)) {
|
|
return fmt.Errorf("invalid weight for tag %s: must be positive value", t.String())
|
|
}
|
|
if float64Value(v.Limit) < 0 || math.IsNaN(float64Value(v.Limit)) {
|
|
return fmt.Errorf("invalid limit_ops for tag %s: must be positive value", t.String())
|
|
}
|
|
if float64Value(v.Reserved) < 0 || math.IsNaN(float64Value(v.Reserved)) {
|
|
return fmt.Errorf("invalid reserved_ops for tag %s: must be positive value", t.String())
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func float64Value(f *float64) float64 {
|
|
if f == nil {
|
|
return 0.0
|
|
}
|
|
return *f
|
|
}
|
|
|
|
func isNoop(read, write limits.OpConfig) bool {
|
|
return read.MaxRunningOps == limits.NoLimit &&
|
|
read.MaxWaitingOps == limits.NoLimit &&
|
|
write.MaxRunningOps == limits.NoLimit &&
|
|
write.MaxWaitingOps == limits.NoLimit &&
|
|
len(read.Tags) == 0 &&
|
|
len(write.Tags) == 0
|
|
}
|