2021-06-01 18:22:41 +00:00
|
|
|
package writecacheconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
2022-06-16 15:07:02 +00:00
|
|
|
boltdbconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/boltdb"
|
2021-06-01 18:22:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config is a wrapper over the config section
|
|
|
|
// which provides access to WriteCache configurations.
|
|
|
|
type Config config.Config
|
|
|
|
|
|
|
|
// config defaults
|
|
|
|
const (
|
|
|
|
// MemSizeDefault is a default memory size.
|
|
|
|
MemSizeDefault = 1 << 30
|
|
|
|
|
|
|
|
// SmallSizeDefault is a default size of small objects.
|
|
|
|
SmallSizeDefault = 32 << 10
|
|
|
|
|
|
|
|
// MaxSizeDefault is a default value of the object payload size limit.
|
|
|
|
MaxSizeDefault = 64 << 20
|
|
|
|
|
|
|
|
// WorkersNumberDefault is a default number of workers.
|
|
|
|
WorkersNumberDefault = 20
|
2021-09-08 09:46:12 +00:00
|
|
|
|
|
|
|
// SizeLimitDefault is a default write-cache size limit.
|
|
|
|
SizeLimitDefault = 1 << 30
|
2021-06-01 18:22:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// From wraps config section into Config.
|
|
|
|
func From(c *config.Config) *Config {
|
|
|
|
return (*Config)(c)
|
|
|
|
}
|
|
|
|
|
2022-01-27 11:30:19 +00:00
|
|
|
// Enabled returns true if write-cache is enabled and false otherwise.
|
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Panics if the value is not a boolean.
|
2022-01-27 11:30:19 +00:00
|
|
|
func (x *Config) Enabled() bool {
|
|
|
|
return config.Bool((*config.Config)(x), "enabled")
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Path returns the value of "path" config parameter.
|
2021-06-01 18:22:41 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Panics if the value is not a non-empty string.
|
2021-06-01 18:22:41 +00:00
|
|
|
func (x *Config) Path() string {
|
|
|
|
p := config.String(
|
|
|
|
(*config.Config)(x),
|
|
|
|
"path",
|
|
|
|
)
|
|
|
|
|
|
|
|
if p == "" {
|
|
|
|
panic("write cache path not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// MemSize returns the value of "memcache_capacity" config parameter.
|
2021-06-01 18:22:41 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns MemSizeDefault if the value is not a positive number.
|
2021-06-01 18:22:41 +00:00
|
|
|
func (x *Config) MemSize() uint64 {
|
2021-10-07 16:17:07 +00:00
|
|
|
s := config.SizeInBytesSafe(
|
2021-06-01 18:22:41 +00:00
|
|
|
(*config.Config)(x),
|
2021-10-18 14:17:14 +00:00
|
|
|
"memcache_capacity",
|
2021-06-01 18:22:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if s > 0 {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
return MemSizeDefault
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SmallObjectSize returns the value of "small_object_size" config parameter.
|
2021-06-01 18:22:41 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns SmallSizeDefault if the value is not a positive number.
|
2021-06-01 18:22:41 +00:00
|
|
|
func (x *Config) SmallObjectSize() uint64 {
|
2021-10-07 16:17:07 +00:00
|
|
|
s := config.SizeInBytesSafe(
|
2021-06-01 18:22:41 +00:00
|
|
|
(*config.Config)(x),
|
2021-10-18 14:05:42 +00:00
|
|
|
"small_object_size",
|
2021-06-01 18:22:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if s > 0 {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
return SmallSizeDefault
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// MaxObjectSize returns the value of "max_object_size" config parameter.
|
2021-06-01 18:22:41 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns MaxSizeDefault if the value is not a positive number.
|
2021-06-01 18:22:41 +00:00
|
|
|
func (x *Config) MaxObjectSize() uint64 {
|
2021-10-07 16:17:07 +00:00
|
|
|
s := config.SizeInBytesSafe(
|
2021-06-01 18:22:41 +00:00
|
|
|
(*config.Config)(x),
|
2021-10-18 14:12:03 +00:00
|
|
|
"max_object_size",
|
2021-06-01 18:22:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if s > 0 {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
return MaxSizeDefault
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// WorkersNumber returns the value of "workers_number" config parameter.
|
2021-06-01 18:22:41 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns WorkersNumberDefault if the value is not a positive number.
|
2021-06-01 18:22:41 +00:00
|
|
|
func (x *Config) WorkersNumber() int {
|
|
|
|
c := config.IntSafe(
|
|
|
|
(*config.Config)(x),
|
|
|
|
"workers_number",
|
|
|
|
)
|
|
|
|
|
|
|
|
if c > 0 {
|
|
|
|
return int(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return WorkersNumberDefault
|
|
|
|
}
|
2021-09-08 09:46:12 +00:00
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SizeLimit returns the value of "capacity" config parameter.
|
2021-09-08 09:46:12 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns SizeLimitDefault if the value is not a positive number.
|
2021-09-08 09:46:12 +00:00
|
|
|
func (x *Config) SizeLimit() uint64 {
|
2021-10-07 16:17:07 +00:00
|
|
|
c := config.SizeInBytesSafe(
|
2021-09-08 09:46:12 +00:00
|
|
|
(*config.Config)(x),
|
2021-10-18 14:29:30 +00:00
|
|
|
"capacity",
|
2021-09-08 09:46:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if c > 0 {
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
return SizeLimitDefault
|
|
|
|
}
|
2022-06-16 15:07:02 +00:00
|
|
|
|
|
|
|
// BoltDB returns config instance for querying bolt db specific parameters.
|
|
|
|
func (x *Config) BoltDB() *boltdbconfig.Config {
|
|
|
|
return (*boltdbconfig.Config)(x)
|
|
|
|
}
|