2021-06-01 18:22:41 +00:00
|
|
|
package shardconfig
|
|
|
|
|
|
|
|
import (
|
2021-12-27 11:04:46 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-06-01 18:22:41 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
|
|
|
blobstorconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/blobstor"
|
|
|
|
gcconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/gc"
|
|
|
|
metabaseconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/metabase"
|
2022-06-09 08:09:18 +00:00
|
|
|
piloramaconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/pilorama"
|
2021-06-01 18:22:41 +00:00
|
|
|
writecacheconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/writecache"
|
2022-06-28 14:05:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
2021-06-01 18:22:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config is a wrapper over the config section
|
|
|
|
// which provides access to Shard configurations.
|
|
|
|
type Config config.Config
|
|
|
|
|
2022-07-11 12:34:17 +00:00
|
|
|
// SmallSizeLimitDefault is a default limit of small objects payload in bytes.
|
|
|
|
const SmallSizeLimitDefault = 1 << 20
|
|
|
|
|
2021-06-01 18:22:41 +00:00
|
|
|
// From wraps config section into Config.
|
|
|
|
func From(c *config.Config) *Config {
|
|
|
|
return (*Config)(c)
|
|
|
|
}
|
|
|
|
|
2022-07-11 12:34:17 +00:00
|
|
|
// Compress returns the value of "compress" config parameter.
|
|
|
|
//
|
|
|
|
// Returns false if the value is not a valid bool.
|
|
|
|
func (x *Config) Compress() bool {
|
|
|
|
return config.BoolSafe(
|
|
|
|
(*config.Config)(x),
|
|
|
|
"compress",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UncompressableContentTypes returns the value of "compress_skip_content_types" config parameter.
|
|
|
|
//
|
|
|
|
// Returns nil if a the value is missing or is invalid.
|
|
|
|
func (x *Config) UncompressableContentTypes() []string {
|
|
|
|
return config.StringSliceSafe(
|
|
|
|
(*config.Config)(x),
|
|
|
|
"compression_exclude_content_types")
|
|
|
|
}
|
|
|
|
|
|
|
|
// SmallSizeLimit returns the value of "small_object_size" config parameter.
|
|
|
|
//
|
|
|
|
// Returns SmallSizeLimitDefault if the value is not a positive number.
|
|
|
|
func (x *Config) SmallSizeLimit() uint64 {
|
|
|
|
l := config.SizeInBytesSafe(
|
|
|
|
(*config.Config)(x),
|
|
|
|
"small_object_size",
|
|
|
|
)
|
|
|
|
|
|
|
|
if l > 0 {
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
return SmallSizeLimitDefault
|
|
|
|
}
|
|
|
|
|
2021-06-01 18:22:41 +00:00
|
|
|
// BlobStor returns "blobstor" subsection as a blobstorconfig.Config.
|
|
|
|
func (x *Config) BlobStor() *blobstorconfig.Config {
|
|
|
|
return blobstorconfig.From(
|
|
|
|
(*config.Config)(x).
|
|
|
|
Sub("blobstor"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Metabase returns "metabase" subsection as a metabaseconfig.Config.
|
|
|
|
func (x *Config) Metabase() *metabaseconfig.Config {
|
|
|
|
return metabaseconfig.From(
|
|
|
|
(*config.Config)(x).
|
|
|
|
Sub("metabase"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteCache returns "writecache" subsection as a writecacheconfig.Config.
|
|
|
|
func (x *Config) WriteCache() *writecacheconfig.Config {
|
|
|
|
return writecacheconfig.From(
|
|
|
|
(*config.Config)(x).
|
|
|
|
Sub("writecache"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-06-09 08:09:18 +00:00
|
|
|
// Pilorama returns "pilorama" subsection as a piloramaconfig.Config.
|
|
|
|
func (x *Config) Pilorama() *piloramaconfig.Config {
|
|
|
|
return piloramaconfig.From(
|
|
|
|
(*config.Config)(x).
|
|
|
|
Sub("pilorama"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-01 18:22:41 +00:00
|
|
|
// GC returns "gc" subsection as a gcconfig.Config.
|
|
|
|
func (x *Config) GC() *gcconfig.Config {
|
|
|
|
return gcconfig.From(
|
|
|
|
(*config.Config)(x).
|
|
|
|
Sub("gc"),
|
|
|
|
)
|
|
|
|
}
|
2021-09-13 13:58:05 +00:00
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// RefillMetabase returns the value of "resync_metabase" config parameter.
|
2021-09-13 13:58:05 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns false if the value is not a valid bool.
|
2021-09-13 13:58:05 +00:00
|
|
|
func (x *Config) RefillMetabase() bool {
|
|
|
|
return config.BoolSafe(
|
|
|
|
(*config.Config)(x),
|
2021-10-18 14:03:09 +00:00
|
|
|
"resync_metabase",
|
2021-09-13 13:58:05 +00:00
|
|
|
)
|
|
|
|
}
|
2021-12-27 11:04:46 +00:00
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Mode return the value of "mode" config parameter.
|
2021-12-27 11:04:46 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Panics if read the value is not one of predefined
|
2021-12-27 11:04:46 +00:00
|
|
|
// shard modes.
|
2022-06-28 14:05:08 +00:00
|
|
|
func (x *Config) Mode() (m mode.Mode) {
|
2021-12-27 11:04:46 +00:00
|
|
|
s := config.StringSafe(
|
|
|
|
(*config.Config)(x),
|
|
|
|
"mode",
|
|
|
|
)
|
|
|
|
|
|
|
|
switch s {
|
|
|
|
case "read-write", "":
|
2022-06-28 14:05:08 +00:00
|
|
|
m = mode.ReadWrite
|
2021-12-27 11:04:46 +00:00
|
|
|
case "read-only":
|
2022-06-28 14:05:08 +00:00
|
|
|
m = mode.ReadOnly
|
2022-03-17 11:55:25 +00:00
|
|
|
case "degraded":
|
2022-06-28 14:05:08 +00:00
|
|
|
m = mode.Degraded
|
2022-07-18 11:44:29 +00:00
|
|
|
case "degraded-read-only":
|
|
|
|
m = mode.DegradedReadOnly
|
2021-12-27 11:04:46 +00:00
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("unknown shard mode: %s", s))
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|