forked from TrueCloudLab/frostfs-node
[#969] node: Do not require shard config in relay mode
Relay storage node doesn't exec local object operations, so it doesn't need shard configuration. Add `required` bool parameter to `engineconfig.IterateShards`. Make it to panic if it is `true`, and immediately return otherwise. Pass `false` if node is configured as relay in app (it also prevents panic). Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
95893927aa
commit
fb89d29574
3 changed files with 22 additions and 6 deletions
|
@ -367,7 +367,9 @@ func initLocalStorage(c *cfg) {
|
|||
func initShardOptions(c *cfg) {
|
||||
var opts [][]shard.Option
|
||||
|
||||
engineconfig.IterateShards(c.appCfg, func(sc *shardconfig.Config) {
|
||||
require := !nodeconfig.Relay(c.appCfg) // relay node does not require shards
|
||||
|
||||
engineconfig.IterateShards(c.appCfg, require, func(sc *shardconfig.Config) {
|
||||
var writeCacheOpts []writecache.Option
|
||||
|
||||
useWriteCache := sc.UseWriteCache()
|
||||
|
|
|
@ -19,15 +19,19 @@ const (
|
|||
// of "shard" subsection of "storage" section of c, wrap them into
|
||||
// shardconfig.Config and passes to f.
|
||||
//
|
||||
// Panics if N is not a positive number.
|
||||
func IterateShards(c *config.Config, f func(*shardconfig.Config)) {
|
||||
// Panics if N is not a positive number while shards are required.
|
||||
func IterateShards(c *config.Config, required bool, f func(*shardconfig.Config)) {
|
||||
c = c.Sub(subsection)
|
||||
|
||||
num := config.Uint(c, "shard_num")
|
||||
if num == 0 {
|
||||
if required {
|
||||
panic("no shard configured")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
def := c.Sub("default")
|
||||
c = c.Sub("shard")
|
||||
|
||||
|
|
|
@ -17,9 +17,19 @@ func TestEngineSection(t *testing.T) {
|
|||
empty := configtest.EmptyConfig()
|
||||
|
||||
require.Panics(t, func() {
|
||||
engineconfig.IterateShards(empty, nil)
|
||||
engineconfig.IterateShards(empty, true, nil)
|
||||
})
|
||||
|
||||
handlerCalled := false
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
engineconfig.IterateShards(empty, false, func(_ *shardconfig.Config) {
|
||||
handlerCalled = true
|
||||
})
|
||||
})
|
||||
|
||||
require.False(t, handlerCalled)
|
||||
|
||||
require.EqualValues(t, engineconfig.ShardPoolSizeDefault, engineconfig.ShardPoolSize(empty))
|
||||
})
|
||||
|
||||
|
@ -30,7 +40,7 @@ func TestEngineSection(t *testing.T) {
|
|||
|
||||
require.EqualValues(t, 15, engineconfig.ShardPoolSize(c))
|
||||
|
||||
engineconfig.IterateShards(c, func(sc *shardconfig.Config) {
|
||||
engineconfig.IterateShards(c, true, func(sc *shardconfig.Config) {
|
||||
defer func() {
|
||||
num++
|
||||
}()
|
||||
|
|
Loading…
Reference in a new issue