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