diff --git a/cmd/neofs-node/config/engine/config_test.go b/cmd/neofs-node/config/engine/config_test.go index 7853c09447..e3a737663e 100644 --- a/cmd/neofs-node/config/engine/config_test.go +++ b/cmd/neofs-node/config/engine/config_test.go @@ -9,6 +9,7 @@ import ( 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" 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" ) @@ -31,6 +32,7 @@ func TestEngineSection(t *testing.T) { require.False(t, handlerCalled) require.EqualValues(t, engineconfig.ShardPoolSizeDefault, engineconfig.ShardPoolSize(empty)) + require.EqualValues(t, shard.ModeReadWrite, shardconfig.From(empty).Mode()) }) 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, false, sc.RefillMetabase()) + require.Equal(t, shard.ModeReadOnly, sc.Mode()) case 1: 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, true, sc.RefillMetabase()) + require.Equal(t, shard.ModeReadWrite, sc.Mode()) } }) diff --git a/cmd/neofs-node/config/engine/shard/config.go b/cmd/neofs-node/config/engine/shard/config.go index 4eaded1f72..a4ce95e506 100644 --- a/cmd/neofs-node/config/engine/shard/config.go +++ b/cmd/neofs-node/config/engine/shard/config.go @@ -1,11 +1,14 @@ package shardconfig import ( + "fmt" + "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" 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" 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" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" ) // Config is a wrapper over the config section @@ -68,3 +71,25 @@ func (x *Config) RefillMetabase() bool { "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 +} diff --git a/config/example/node.env b/config/example/node.env index abb09d5df0..0ee9b28641 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -73,6 +73,8 @@ NEOFS_STORAGE_SHARD_NUM=2 ## 0 shard ### Flag to refill Metabase from BlobStor NEOFS_STORAGE_SHARD_0_RESYNC_METABASE=false +### Flag to set shard mode +NEOFS_STORAGE_SHARD_0_MODE=read-only ### Write cache config NEOFS_STORAGE_SHARD_0_USE_WRITE_CACHE=false NEOFS_STORAGE_SHARD_0_WRITECACHE_PATH=tmp/0/cache @@ -104,6 +106,8 @@ NEOFS_STORAGE_SHARD_0_GC_REMOVER_SLEEP_INTERVAL=2m ## 1 shard ### Flag to refill Metabase from BlobStor NEOFS_STORAGE_SHARD_1_RESYNC_METABASE=true +### Flag to set shard mode +NEOFS_STORAGE_SHARD_1_MODE=read-write ### Write cache config NEOFS_STORAGE_SHARD_1_USE_WRITE_CACHE=true NEOFS_STORAGE_SHARD_1_WRITECACHE_PATH=tmp/1/cache diff --git a/config/example/node.json b/config/example/node.json index fdb68dea4a..ca8b81122e 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -117,6 +117,7 @@ "shard_num": 2, "shard": { "0": { + "mode": "read-only", "resync_metabase": false, "use_write_cache": false, "writecache": { @@ -150,6 +151,7 @@ } }, "1": { + "mode": "read-write", "resync_metabase": true, "use_write_cache": true, "writecache": { diff --git a/config/example/node.yaml b/config/example/node.yaml index 569b49950d..69e5f84665 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -131,6 +131,7 @@ storage: shard: 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 use_write_cache: false # use write-cache