Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse bolt DB configuration in the tree service #1538

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,10 @@ func initShardOptions(c *cfg) {

piloramaOpts := []pilorama.Option{
pilorama.WithPath(piloramaPath),
pilorama.WithPerm(piloramaCfg.Perm()),
pilorama.WithNoSync(piloramaCfg.NoSync()),
pilorama.WithMaxBatchSize(piloramaCfg.MaxBatchSize()),
pilorama.WithMaxBatchDelay(piloramaCfg.MaxBatchDelay())}
pilorama.WithPerm(piloramaCfg.BoltDB().Perm()),
pilorama.WithNoSync(piloramaCfg.BoltDB().NoSync()),
pilorama.WithMaxBatchSize(piloramaCfg.BoltDB().MaxBatchSize()),
pilorama.WithMaxBatchDelay(piloramaCfg.BoltDB().MaxBatchDelay())}

metaPath := metabaseCfg.Path()
metaPerm := metabaseCfg.BoltDB().Perm()
Expand Down
18 changes: 9 additions & 9 deletions cmd/neofs-node/config/engine/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
engineconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine"
shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard"
piloramaconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/pilorama"
boltdbconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/boltdb"
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -60,10 +60,10 @@ func TestEngineSection(t *testing.T) {
switch num {
case 0:
require.Equal(t, "tmp/0/blob/pilorama.db", pl.Path())
require.Equal(t, fs.FileMode(piloramaconfig.PermDefault), pl.Perm())
require.False(t, pl.NoSync())
require.Equal(t, pl.MaxBatchDelay(), 10*time.Millisecond)
require.Equal(t, pl.MaxBatchSize(), 200)
require.Equal(t, fs.FileMode(boltdbconfig.PermDefault), pl.BoltDB().Perm())
require.False(t, pl.BoltDB().NoSync())
require.Equal(t, pl.BoltDB().MaxBatchDelay(), 10*time.Millisecond)
require.Equal(t, pl.BoltDB().MaxBatchSize(), 200)

require.Equal(t, false, wc.Enabled())

Expand Down Expand Up @@ -98,10 +98,10 @@ func TestEngineSection(t *testing.T) {
require.Equal(t, shard.ModeReadOnly, sc.Mode())
case 1:
require.Equal(t, "tmp/1/blob/pilorama.db", pl.Path())
require.Equal(t, fs.FileMode(0644), pl.Perm())
require.True(t, pl.NoSync())
require.Equal(t, 5*time.Millisecond, pl.MaxBatchDelay())
require.Equal(t, 100, pl.MaxBatchSize())
require.Equal(t, fs.FileMode(0644), pl.BoltDB().Perm())
require.True(t, pl.BoltDB().NoSync())
require.Equal(t, 5*time.Millisecond, pl.BoltDB().MaxBatchDelay())
require.Equal(t, 100, pl.BoltDB().MaxBatchSize())

require.Equal(t, true, wc.Enabled())

Expand Down
51 changes: 4 additions & 47 deletions cmd/neofs-node/config/engine/shard/pilorama/config.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package piloramaconfig

import (
"io/fs"
"time"

"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
// which provides access to Metabase configurations.
type Config config.Config

const (
// PermDefault is a default permission bits for metabase file.
PermDefault = 0660
)

// From wraps config section into Config.
func From(c *config.Config) *Config {
return (*Config)(c)
Expand All @@ -28,43 +21,7 @@ func (x *Config) Path() string {
return config.String((*config.Config)(x), "path")
}

// 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)
}

// NoSync returns the value of "no_sync" config parameter as a bool value.
//
// Returns false if the value is not a boolean.
func (x *Config) NoSync() bool {
return config.BoolSafe((*config.Config)(x), "no_sync")
}

// 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
// BoltDB returns config instance for querying bolt db specific parameters.
func (x *Config) BoltDB() *boltdbconfig.Config {
return (*boltdbconfig.Config)(x)
}