From 80ce7c3a0095e707e44accf30be6bf7f61bfacc4 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Wed, 31 Jul 2024 16:33:31 +0300 Subject: [PATCH] [#1284] shard: Resolve funlen linter Signed-off-by: Dmitrii Stepanov --- pkg/local_object_storage/shard/control.go | 71 +++++++++++++---------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index 210744702..936a506c0 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -99,12 +99,50 @@ func (x *metabaseSynchronizer) Init() error { // Init initializes all Shard's components. func (s *Shard) Init(ctx context.Context) error { + m := s.GetMode() + if err := s.initializeComponents(m); err != nil { + return err + } + + s.updateMetrics(ctx) + + s.gc = &gc{ + gcCfg: &s.gcCfg, + remover: s.removeGarbage, + stopChannel: make(chan struct{}), + eventChan: make(chan Event), + mEventHandler: map[eventType]*eventHandlers{ + eventNewEpoch: { + cancelFunc: func() {}, + handlers: []eventHandler{ + s.collectExpiredLocks, + s.collectExpiredObjects, + s.collectExpiredTombstones, + s.collectExpiredMetrics, + }, + }, + }, + } + if s.gc.metrics != nil { + s.gc.metrics.SetShardID(s.info.ID.String()) + } + + s.gc.init(ctx) + + s.rb = newRebuilder(s.rebuildLimiter) + if !m.NoMetabase() { + s.rb.Start(ctx, s.blobStor, s.metaBase, s.log) + } + s.writecacheSealCancel.Store(dummyCancel) + return nil +} + +func (s *Shard) initializeComponents(m mode.Mode) error { type initializer interface { Init() error } var components []initializer - m := s.GetMode() if !m.NoMetabase() { var initMetabase initializer @@ -148,37 +186,6 @@ func (s *Shard) Init(ctx context.Context) error { return fmt.Errorf("could not initialize %T: %w", component, err) } } - - s.updateMetrics(ctx) - - s.gc = &gc{ - gcCfg: &s.gcCfg, - remover: s.removeGarbage, - stopChannel: make(chan struct{}), - eventChan: make(chan Event), - mEventHandler: map[eventType]*eventHandlers{ - eventNewEpoch: { - cancelFunc: func() {}, - handlers: []eventHandler{ - s.collectExpiredLocks, - s.collectExpiredObjects, - s.collectExpiredTombstones, - s.collectExpiredMetrics, - }, - }, - }, - } - if s.gc.metrics != nil { - s.gc.metrics.SetShardID(s.info.ID.String()) - } - - s.gc.init(ctx) - - s.rb = newRebuilder(s.rebuildLimiter) - if !m.NoMetabase() { - s.rb.Start(ctx, s.blobStor, s.metaBase, s.log) - } - s.writecacheSealCancel.Store(dummyCancel) return nil }