[#168] node: Refactor shard opts initialization

Resolve funlen linter for shardOpts method

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-03-24 09:41:51 +03:00
parent c94372e6f9
commit dcd39f8fdd

View file

@ -708,11 +708,17 @@ type shardOptsWithID struct {
shOpts []shard.Option
}
// nolint: funlen
func (c *cfg) shardOpts() []shardOptsWithID {
shards := make([]shardOptsWithID, 0, len(c.EngineCfg.shards))
for _, shCfg := range c.EngineCfg.shards {
shards = append(shards, c.getShardOpts(shCfg))
}
return shards
}
func (c *cfg) getWriteCacheOpts(shCfg shardCfg) []writecache.Option {
var writeCacheOpts []writecache.Option
if wcRead := shCfg.writecacheCfg; wcRead.enabled {
writeCacheOpts = append(writeCacheOpts,
@ -727,7 +733,10 @@ func (c *cfg) shardOpts() []shardOptsWithID {
writecache.WithLogger(c.log),
)
}
return writeCacheOpts
}
func (c *cfg) getPiloramaOpts(shCfg shardCfg) []pilorama.Option {
var piloramaOpts []pilorama.Option
if prRead := shCfg.piloramaCfg; prRead.enabled {
piloramaOpts = append(piloramaOpts,
@ -738,7 +747,10 @@ func (c *cfg) shardOpts() []shardOptsWithID {
pilorama.WithMaxBatchDelay(prRead.maxBatchDelay),
)
}
return piloramaOpts
}
func (c *cfg) getSubstorageOpts(shCfg shardCfg) []blobstor.SubStorage {
var ss []blobstor.SubStorage
for _, sRead := range shCfg.subStorages {
switch sRead.typ {
@ -773,6 +785,13 @@ func (c *cfg) shardOpts() []shardOptsWithID {
// been handled: when the config was read
}
}
return ss
}
func (c *cfg) getShardOpts(shCfg shardCfg) shardOptsWithID {
writeCacheOpts := c.getWriteCacheOpts(shCfg)
piloramaOpts := c.getPiloramaOpts(shCfg)
ss := c.getSubstorageOpts(shCfg)
var sh shardOptsWithID
sh.configID = shCfg.id()
@ -813,11 +832,7 @@ func (c *cfg) shardOpts() []shardOptsWithID {
return pool
}),
}
shards = append(shards, sh)
}
return shards
return sh
}
func (c *cfg) loggerPrm() (*logger.Prm, error) {