[#1057] node/config: Add shard mode config param

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-12-27 14:04:46 +03:00 committed by Pavel Karpy
parent 93bd6be743
commit 8b8a815fb3
5 changed files with 36 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import (
engineconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine" 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" shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard"
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test" 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" "github.com/stretchr/testify/require"
) )
@ -31,6 +32,7 @@ func TestEngineSection(t *testing.T) {
require.False(t, handlerCalled) require.False(t, handlerCalled)
require.EqualValues(t, engineconfig.ShardPoolSizeDefault, engineconfig.ShardPoolSize(empty)) require.EqualValues(t, engineconfig.ShardPoolSizeDefault, engineconfig.ShardPoolSize(empty))
require.EqualValues(t, shard.ModeReadWrite, shardconfig.From(empty).Mode())
}) })
const path = "../../../../config/example/node" const path = "../../../../config/example/node"
@ -80,6 +82,7 @@ func TestEngineSection(t *testing.T) {
require.Equal(t, 2*time.Minute, gc.RemoverSleepInterval()) require.Equal(t, 2*time.Minute, gc.RemoverSleepInterval())
require.Equal(t, false, sc.RefillMetabase()) require.Equal(t, false, sc.RefillMetabase())
require.Equal(t, shard.ModeReadOnly, sc.Mode())
case 1: case 1:
require.Equal(t, true, sc.UseWriteCache()) require.Equal(t, true, sc.UseWriteCache())
@ -108,6 +111,7 @@ func TestEngineSection(t *testing.T) {
require.Equal(t, 5*time.Minute, gc.RemoverSleepInterval()) require.Equal(t, 5*time.Minute, gc.RemoverSleepInterval())
require.Equal(t, true, sc.RefillMetabase()) require.Equal(t, true, sc.RefillMetabase())
require.Equal(t, shard.ModeReadWrite, sc.Mode())
} }
}) })

View file

@ -1,11 +1,14 @@
package shardconfig package shardconfig
import ( import (
"fmt"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
blobstorconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/blobstor" 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" 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" metabaseconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/metabase"
writecacheconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/writecache" writecacheconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/writecache"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
) )
// Config is a wrapper over the config section // Config is a wrapper over the config section
@ -68,3 +71,25 @@ func (x *Config) RefillMetabase() bool {
"resync_metabase", "resync_metabase",
) )
} }
// Mode return value of "mode" config parameter.
//
// Panics if read value is not one of predefined
// shard modes.
func (x *Config) Mode() (m shard.Mode) {
s := config.StringSafe(
(*config.Config)(x),
"mode",
)
switch s {
case "read-write", "":
m = shard.ModeReadWrite
case "read-only":
m = shard.ModeReadOnly
default:
panic(fmt.Sprintf("unknown shard mode: %s", s))
}
return
}

View file

@ -73,6 +73,8 @@ NEOFS_STORAGE_SHARD_NUM=2
## 0 shard ## 0 shard
### Flag to refill Metabase from BlobStor ### Flag to refill Metabase from BlobStor
NEOFS_STORAGE_SHARD_0_RESYNC_METABASE=false NEOFS_STORAGE_SHARD_0_RESYNC_METABASE=false
### Flag to set shard mode
NEOFS_STORAGE_SHARD_0_MODE=read-only
### Write cache config ### Write cache config
NEOFS_STORAGE_SHARD_0_USE_WRITE_CACHE=false NEOFS_STORAGE_SHARD_0_USE_WRITE_CACHE=false
NEOFS_STORAGE_SHARD_0_WRITECACHE_PATH=tmp/0/cache NEOFS_STORAGE_SHARD_0_WRITECACHE_PATH=tmp/0/cache
@ -104,6 +106,8 @@ NEOFS_STORAGE_SHARD_0_GC_REMOVER_SLEEP_INTERVAL=2m
## 1 shard ## 1 shard
### Flag to refill Metabase from BlobStor ### Flag to refill Metabase from BlobStor
NEOFS_STORAGE_SHARD_1_RESYNC_METABASE=true NEOFS_STORAGE_SHARD_1_RESYNC_METABASE=true
### Flag to set shard mode
NEOFS_STORAGE_SHARD_1_MODE=read-write
### Write cache config ### Write cache config
NEOFS_STORAGE_SHARD_1_USE_WRITE_CACHE=true NEOFS_STORAGE_SHARD_1_USE_WRITE_CACHE=true
NEOFS_STORAGE_SHARD_1_WRITECACHE_PATH=tmp/1/cache NEOFS_STORAGE_SHARD_1_WRITECACHE_PATH=tmp/1/cache

View file

@ -117,6 +117,7 @@
"shard_num": 2, "shard_num": 2,
"shard": { "shard": {
"0": { "0": {
"mode": "read-only",
"resync_metabase": false, "resync_metabase": false,
"use_write_cache": false, "use_write_cache": false,
"writecache": { "writecache": {
@ -150,6 +151,7 @@
} }
}, },
"1": { "1": {
"mode": "read-write",
"resync_metabase": true, "resync_metabase": true,
"use_write_cache": true, "use_write_cache": true,
"writecache": { "writecache": {

View file

@ -131,6 +131,7 @@ storage:
shard: shard:
0: 0:
mode: "read-only" # mode of the shard, must be one of the: "read-write" (default), "read-only"
resync_metabase: false # sync metabase with blobstor on start, expensive, leave false until complete understanding resync_metabase: false # sync metabase with blobstor on start, expensive, leave false until complete understanding
use_write_cache: false # use write-cache use_write_cache: false # use write-cache