2021-06-01 21:22:41 +03:00
|
|
|
package shardconfig
|
|
|
|
|
|
|
|
import (
|
2021-12-27 14:04:46 +03:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 16:38:26 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
|
|
|
|
blobstorconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/blobstor"
|
|
|
|
gcconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/gc"
|
|
|
|
metabaseconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/metabase"
|
|
|
|
piloramaconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/pilorama"
|
|
|
|
writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/writecache"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
2021-06-01 21:22:41 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config is a wrapper over the config section
|
|
|
|
// which provides access to Shard configurations.
|
|
|
|
type Config config.Config
|
|
|
|
|
2023-10-31 14:45:22 +03:00
|
|
|
const (
|
|
|
|
// SmallSizeLimitDefault is a default limit of small objects payload in bytes.
|
|
|
|
SmallSizeLimitDefault = 1 << 20
|
|
|
|
EstimateCompressibilityThresholdDefault = 0.1
|
|
|
|
)
|
2022-07-11 15:34:17 +03:00
|
|
|
|
2021-06-01 21:22:41 +03:00
|
|
|
// From wraps config section into Config.
|
|
|
|
func From(c *config.Config) *Config {
|
|
|
|
return (*Config)(c)
|
|
|
|
}
|
|
|
|
|
2022-07-11 15:34:17 +03: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")
|
|
|
|
}
|
|
|
|
|
2023-10-31 14:45:22 +03:00
|
|
|
// EstimateCompressibility returns the value of "estimate_compressibility" config parameter.
|
|
|
|
//
|
|
|
|
// Returns false if the value is not a valid bool.
|
|
|
|
func (x *Config) EstimateCompressibility() bool {
|
|
|
|
return config.BoolSafe(
|
|
|
|
(*config.Config)(x),
|
|
|
|
"compression_estimate_compressibility",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EstimateCompressibilityThreshold returns the value of "estimate_compressibility_threshold" config parameter.
|
|
|
|
//
|
|
|
|
// Returns EstimateCompressibilityThresholdDefault if the value is not defined, not valid float or not in range [0.0; 1.0].
|
|
|
|
func (x *Config) EstimateCompressibilityThreshold() float64 {
|
|
|
|
v := config.FloatOrDefault(
|
|
|
|
(*config.Config)(x),
|
|
|
|
"compression_estimate_compressibility_threshold",
|
|
|
|
EstimateCompressibilityThresholdDefault)
|
|
|
|
if v < 0.0 || v > 1.0 {
|
|
|
|
return EstimateCompressibilityThresholdDefault
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2022-07-11 15:34:17 +03:00
|
|
|
// 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 21:22:41 +03: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 11:09:18 +03: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 21:22:41 +03: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 16:58:05 +03:00
|
|
|
|
2022-04-21 14:28:05 +03:00
|
|
|
// RefillMetabase returns the value of "resync_metabase" config parameter.
|
2021-09-13 16:58:05 +03:00
|
|
|
//
|
2022-04-21 14:28:05 +03:00
|
|
|
// Returns false if the value is not a valid bool.
|
2021-09-13 16:58:05 +03:00
|
|
|
func (x *Config) RefillMetabase() bool {
|
|
|
|
return config.BoolSafe(
|
|
|
|
(*config.Config)(x),
|
2021-10-18 17:03:09 +03:00
|
|
|
"resync_metabase",
|
2021-09-13 16:58:05 +03:00
|
|
|
)
|
|
|
|
}
|
2021-12-27 14:04:46 +03:00
|
|
|
|
2022-04-21 14:28:05 +03:00
|
|
|
// Mode return the value of "mode" config parameter.
|
2021-12-27 14:04:46 +03:00
|
|
|
//
|
2022-04-21 14:28:05 +03:00
|
|
|
// Panics if read the value is not one of predefined
|
2021-12-27 14:04:46 +03:00
|
|
|
// shard modes.
|
2022-06-28 17:05:08 +03:00
|
|
|
func (x *Config) Mode() (m mode.Mode) {
|
2021-12-27 14:04:46 +03:00
|
|
|
s := config.StringSafe(
|
|
|
|
(*config.Config)(x),
|
|
|
|
"mode",
|
|
|
|
)
|
|
|
|
|
|
|
|
switch s {
|
|
|
|
case "read-write", "":
|
2022-06-28 17:05:08 +03:00
|
|
|
m = mode.ReadWrite
|
2021-12-27 14:04:46 +03:00
|
|
|
case "read-only":
|
2022-06-28 17:05:08 +03:00
|
|
|
m = mode.ReadOnly
|
2022-03-17 14:55:25 +03:00
|
|
|
case "degraded":
|
2022-06-28 17:05:08 +03:00
|
|
|
m = mode.Degraded
|
2022-07-18 14:44:29 +03:00
|
|
|
case "degraded-read-only":
|
|
|
|
m = mode.DegradedReadOnly
|
2022-10-05 14:40:37 +03:00
|
|
|
case "disabled":
|
|
|
|
m = mode.Disabled
|
2021-12-27 14:04:46 +03:00
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("unknown shard mode: %s", s))
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|