[#1524] neofs-node: Reuse boltdb config for different components

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-06-16 18:07:02 +03:00 committed by LeL
parent 0408acc40e
commit d6043abc24
6 changed files with 82 additions and 25 deletions

View file

@ -417,7 +417,7 @@ func initShardOptions(c *cfg) {
gcCfg := sc.GC() gcCfg := sc.GC()
metaPath := metabaseCfg.Path() metaPath := metabaseCfg.Path()
metaPerm := metabaseCfg.Perm() metaPerm := metabaseCfg.BoltDB().Perm()
fatalOnErr(util.MkdirAllX(filepath.Dir(metaPath), metaPerm)) fatalOnErr(util.MkdirAllX(filepath.Dir(metaPath), metaPerm))
gcEventChannel := make(chan shard.Event) gcEventChannel := make(chan shard.Event)

View file

@ -67,7 +67,7 @@ func TestEngineSection(t *testing.T) {
require.EqualValues(t, 3221225472, wc.SizeLimit()) require.EqualValues(t, 3221225472, wc.SizeLimit())
require.Equal(t, "tmp/0/meta", meta.Path()) require.Equal(t, "tmp/0/meta", meta.Path())
require.Equal(t, fs.FileMode(0644), meta.Perm()) require.Equal(t, fs.FileMode(0644), meta.BoltDB().Perm())
require.Equal(t, "tmp/0/blob", blob.Path()) require.Equal(t, "tmp/0/blob", blob.Path())
require.EqualValues(t, 0644, blob.Perm()) require.EqualValues(t, 0644, blob.Perm())
@ -97,7 +97,7 @@ func TestEngineSection(t *testing.T) {
require.EqualValues(t, 4294967296, wc.SizeLimit()) require.EqualValues(t, 4294967296, wc.SizeLimit())
require.Equal(t, "tmp/1/meta", meta.Path()) require.Equal(t, "tmp/1/meta", meta.Path())
require.Equal(t, fs.FileMode(0644), meta.Perm()) require.Equal(t, fs.FileMode(0644), meta.BoltDB().Perm())
require.Equal(t, "tmp/1/blob", blob.Path()) require.Equal(t, "tmp/1/blob", blob.Path())
require.EqualValues(t, 0644, blob.Perm()) require.EqualValues(t, 0644, blob.Perm())

View file

@ -2,6 +2,7 @@ package blobovniczaconfig
import ( import (
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
boltdbconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/boltdb"
) )
// Config is a wrapper over the config section // Config is a wrapper over the config section
@ -91,3 +92,8 @@ func (x *Config) OpenedCacheSize() int {
return OpenedCacheSizeDefault return OpenedCacheSizeDefault
} }
// BoltDB returns config instance for querying bolt db specific parameters.
func (x *Config) BoltDB() *boltdbconfig.Config {
return (*boltdbconfig.Config)(x)
}

View file

@ -0,0 +1,63 @@
package boltdbconfig
import (
"io/fs"
"time"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
)
// Config is a wrapper over the config section
// which provides access to boltdb specific parameters.
type Config config.Config
// config defaults
const (
// PermDefault is a default permission bits for metabase file.
PermDefault = 0660
)
// Perm returns the value of "perm" config parameter as a fs.FileMode.
//
// Returns PermDefault if the value is not a positive number.
func (x *Config) Perm() fs.FileMode {
p := config.UintSafe(
(*config.Config)(x),
"perm",
)
if p == 0 {
p = PermDefault
}
return fs.FileMode(p)
}
// MaxBatchDelay returns the value of "max_batch_delay" config parameter.
//
// Returns 0 if the value is not a positive number.
func (x *Config) MaxBatchDelay() time.Duration {
d := config.DurationSafe((*config.Config)(x), "max_batch_delay")
if d < 0 {
d = 0
}
return d
}
// MaxBatchSize returns the value of "max_batch_size" config parameter.
//
// Returns 0 if the value is not a positive number.
func (x *Config) MaxBatchSize() int {
s := int(config.IntSafe((*config.Config)(x), "max_batch_size"))
if s < 0 {
s = 0
}
return s
}
// NoSync returns the value of "no_sync" config parameter.
//
// Returns false if the value is not a boolean.
func (x *Config) NoSync() bool {
return config.BoolSafe((*config.Config)(x), "no_sync")
}

View file

@ -1,21 +1,14 @@
package metabaseconfig package metabaseconfig
import ( import (
"io/fs"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
boltdbconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/boltdb"
) )
// Config is a wrapper over the config section // Config is a wrapper over the config section
// which provides access to Metabase configurations. // which provides access to Metabase configurations.
type Config config.Config type Config config.Config
// config defaults
const (
// PermDefault is a default permission bits for metabase file.
PermDefault = 0660
)
// From wraps config section into Config. // From wraps config section into Config.
func From(c *config.Config) *Config { func From(c *config.Config) *Config {
return (*Config)(c) return (*Config)(c)
@ -37,18 +30,7 @@ func (x *Config) Path() string {
return p return p
} }
// Perm returns the value of "perm" config parameter as a fs.FileMode. // BoltDB returns config instance for querying bolt db specific parameters.
// func (x *Config) BoltDB() *boltdbconfig.Config {
// Returns PermDefault if the value is not a positive number. return (*boltdbconfig.Config)(x)
func (x *Config) Perm() fs.FileMode {
p := config.UintSafe(
(*config.Config)(x),
"perm",
)
if p == 0 {
p = PermDefault
}
return fs.FileMode(p)
} }

View file

@ -2,6 +2,7 @@ package writecacheconfig
import ( import (
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
boltdbconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/boltdb"
) )
// Config is a wrapper over the config section // Config is a wrapper over the config section
@ -133,3 +134,8 @@ func (x *Config) SizeLimit() uint64 {
return SizeLimitDefault return SizeLimitDefault
} }
// BoltDB returns config instance for querying bolt db specific parameters.
func (x *Config) BoltDB() *boltdbconfig.Config {
return (*boltdbconfig.Config)(x)
}