[#493] node/config: Implement sections of local object storage

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-01 21:22:41 +03:00 committed by Leonard Lyubich
parent e26dc0a6e3
commit f663a1c125
7 changed files with 530 additions and 0 deletions

View file

@ -0,0 +1,93 @@
package blobovniczaconfig
import (
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
)
// Config is a wrapper over the config section
// which provides access to Blobovnicza configurations.
type Config config.Config
// config defaults
const (
// SizeDefault is a default limit of estimates of Blobovnicza size.
SizeDefault = 1 << 30
// ShallowDepthDefault is a default shallow dir depth.
ShallowDepthDefault = 2
// ShallowWidthDefault is a default shallow dir width.
ShallowWidthDefault = 16
// OpenedCacheSizeDefault is a default cache size of opened Blobovnicza's.
OpenedCacheSizeDefault = 16
)
// From wraps config section into Config.
func From(c *config.Config) *Config {
return (*Config)(c)
}
// Size returns value of "size" config parameter.
//
// Returns SizeDefault if value is not a positive number.
func (x *Config) Size() uint64 {
s := config.UintSafe(
(*config.Config)(x),
"size",
)
if s > 0 {
return s
}
return SizeDefault
}
// ShallowDepth returns value of "shallow_depth" config parameter.
//
// Returns ShallowDepthDefault if value is not a positive number.
func (x *Config) ShallowDepth() uint64 {
d := config.UintSafe(
(*config.Config)(x),
"shallow_depth",
)
if d > 0 {
return d
}
return ShallowDepthDefault
}
// ShallowWidth returns value of "shallow_width" config parameter.
//
// Returns ShallowWidthDefault if value is not a positive number.
func (x *Config) ShallowWidth() uint64 {
d := config.UintSafe(
(*config.Config)(x),
"shallow_width",
)
if d > 0 {
return d
}
return ShallowWidthDefault
}
// OpenedCacheSize returns value of "opened_cache_size" config parameter.
//
// Returns OpenedCacheSizeDefault if value is not a positive number.
func (x *Config) OpenedCacheSize() int {
d := config.IntSafe(
(*config.Config)(x),
"opened_cache_size",
)
if d > 0 {
return int(d)
}
return OpenedCacheSizeDefault
}

View file

@ -0,0 +1,113 @@
package blobstorconfig
import (
"os"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
blobovniczaconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/blobstor/blobovnicza"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
)
// Config is a wrapper over the config section
// which provides access to BlobStor configurations.
type Config config.Config
// config defaults
const (
// PermDefault are default permission bits for BlobStor data.
PermDefault = 0700
// ShallowDepthDefault is a default shallow dir depth.
ShallowDepthDefault = 4
// SmallSizeLimitDefault is a default limit of small objects payload in bytes.
SmallSizeLimitDefault = 1 << 20
)
// From wraps config section into Config.
func From(c *config.Config) *Config {
return (*Config)(c)
}
// Path returns value of "path" config parameter.
//
// Panics if value is not a non-empty string.
func (x *Config) Path() string {
p := config.String(
(*config.Config)(x),
"path",
)
if p == "" {
panic("blobstor path not set")
}
return p
}
// Perm returns value of "perm" config parameter as a os.FileMode.
//
// Returns PermDefault if value is not a non-zero number.
func (x *Config) Perm() os.FileMode {
p := config.UintSafe(
(*config.Config)(x),
"perm",
)
if p == 0 {
p = PermDefault
}
return os.FileMode(p)
}
// ShallowDepth returns value of "shallow_depth" config parameter.
//
// Returns ShallowDepthDefault if value is out of
// [1:fstree.MaxDepth] range.
func (x *Config) ShallowDepth() int {
d := config.IntSafe(
(*config.Config)(x),
"shallow_depth",
)
if d >= 1 && d <= fstree.MaxDepth {
return int(d)
}
return ShallowDepthDefault
}
// Compress returns value of "compress" config parameter.
//
// Returns false if value is not a valid bool.
func (x *Config) Compress() bool {
return config.BoolSafe(
(*config.Config)(x),
"compress",
)
}
// SmallSizeLimit returns value of "small_size_limit" config parameter.
//
// Returns SmallSizeLimitDefault if value is not a positive number.
func (x *Config) SmallSizeLimit() uint64 {
l := config.UintSafe(
(*config.Config)(x),
"small_size_limit",
)
if l > 0 {
return l
}
return SmallSizeLimitDefault
}
// Blobovnicza returns "blobovnicza" subsection as a blobovniczaconfig.Config.
func (x *Config) Blobovnicza() *blobovniczaconfig.Config {
return blobovniczaconfig.From(
(*config.Config)(x).
Sub("blobovnicza"),
)
}