2021-06-01 18:22:41 +00:00
|
|
|
package engineconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
|
|
|
shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard"
|
|
|
|
)
|
|
|
|
|
2021-10-08 13:25:56 +00:00
|
|
|
const (
|
|
|
|
subsection = "storage"
|
|
|
|
|
|
|
|
// ShardPoolSizeDefault is a default value of routine pool size per-shard to
|
|
|
|
// process object PUT operations in storage engine.
|
|
|
|
ShardPoolSizeDefault = 20
|
|
|
|
)
|
|
|
|
|
2021-06-01 18:22:41 +00:00
|
|
|
// IterateShards iterates over subsections ["0":"N") (N - "shard_num" value)
|
|
|
|
// of "shard" subsection of "storage" section of c, wrap them into
|
|
|
|
// shardconfig.Config and passes to f.
|
|
|
|
//
|
2021-11-12 10:15:14 +00:00
|
|
|
// Panics if N is not a positive number while shards are required.
|
|
|
|
func IterateShards(c *config.Config, required bool, f func(*shardconfig.Config)) {
|
2021-10-08 13:25:56 +00:00
|
|
|
c = c.Sub(subsection)
|
2021-06-01 18:22:41 +00:00
|
|
|
|
|
|
|
num := config.Uint(c, "shard_num")
|
|
|
|
if num == 0 {
|
2021-11-12 10:15:14 +00:00
|
|
|
if required {
|
|
|
|
panic("no shard configured")
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2021-06-01 18:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 13:38:04 +00:00
|
|
|
def := c.Sub("default")
|
2021-06-01 18:22:41 +00:00
|
|
|
c = c.Sub("shard")
|
|
|
|
|
|
|
|
for i := uint64(0); i < num; i++ {
|
|
|
|
si := strconv.FormatUint(i, 10)
|
|
|
|
|
|
|
|
sc := shardconfig.From(
|
|
|
|
c.Sub(si),
|
|
|
|
)
|
2021-10-18 13:38:04 +00:00
|
|
|
(*config.Config)(sc).SetDefault(def)
|
2021-06-01 18:22:41 +00:00
|
|
|
|
|
|
|
f(sc)
|
|
|
|
}
|
|
|
|
}
|
2021-10-08 13:25:56 +00:00
|
|
|
|
|
|
|
// ShardPoolSize returns value of "shard_pool_size" config parameter from "storage" section.
|
|
|
|
//
|
|
|
|
// Returns ShardPoolSizeDefault if value is not a positive number.
|
|
|
|
func ShardPoolSize(c *config.Config) uint32 {
|
|
|
|
v := config.Uint32Safe(c.Sub(subsection), "shard_pool_size")
|
|
|
|
if v > 0 {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
return ShardPoolSizeDefault
|
|
|
|
}
|
2022-02-01 08:15:54 +00:00
|
|
|
|
|
|
|
// ShardErrorThreshold returns value of "shard_ro_error_threshold" config parameter from "storage" section.
|
|
|
|
//
|
|
|
|
// Returns 0 if the value is missing.
|
|
|
|
func ShardErrorThreshold(c *config.Config) uint32 {
|
|
|
|
return config.Uint32Safe(c.Sub(subsection), "shard_ro_error_threshold")
|
|
|
|
}
|