From 3d981320c6a034f886f43cca23b7c84ad5bf1ae7 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 4 Aug 2021 15:04:37 +0300 Subject: [PATCH] [#745] gc: Stop GC work on `Shard`'s `Close` Signed-off-by: Pavel Karpy --- pkg/local_object_storage/shard/control.go | 11 +++++++---- pkg/local_object_storage/shard/gc.go | 17 ++++++++++++++--- pkg/local_object_storage/shard/shard.go | 2 ++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index d2795412..12037444 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -39,9 +39,10 @@ func (s *Shard) Init() error { } } - gc := &gc{ - gcCfg: s.gcCfg, - remover: s.removeGarbage, + s.gc = &gc{ + gcCfg: s.gcCfg, + remover: s.removeGarbage, + stopChannel: make(chan struct{}), mEventHandler: map[eventType]*eventHandlers{ eventNewEpoch: { cancelFunc: func() {}, @@ -53,7 +54,7 @@ func (s *Shard) Init() error { }, } - gc.init() + s.gc.init() return nil } @@ -74,5 +75,7 @@ func (s *Shard) Close() error { } } + s.gc.stop() + return nil } diff --git a/pkg/local_object_storage/shard/gc.go b/pkg/local_object_storage/shard/gc.go index 9b916c1f..395d0d46 100644 --- a/pkg/local_object_storage/shard/gc.go +++ b/pkg/local_object_storage/shard/gc.go @@ -52,6 +52,8 @@ type eventHandlers struct { type gc struct { *gcCfg + stopChannel chan struct{} + workerPool util.WorkerPool remover func() @@ -146,12 +148,21 @@ func (gc *gc) tickRemover() { defer timer.Stop() for { - <-timer.C - gc.remover() - timer.Reset(gc.removerInterval) + select { + case <-gc.stopChannel: + gc.log.Debug("GC is stopped") + return + case <-timer.C: + gc.remover() + timer.Reset(gc.removerInterval) + } } } +func (gc *gc) stop() { + gc.stopChannel <- struct{}{} +} + // iterates over metabase graveyard and deletes objects // with GC-marked graves. func (s *Shard) removeGarbage() { diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index b85403e2..0f470728 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -18,6 +18,8 @@ import ( type Shard struct { *cfg + gc *gc + mode *atomic.Uint32 writeCache writecache.Cache