[#366] node: Stop GC once termination signal received

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2023-05-29 09:35:08 +03:00
parent 802168c0c6
commit 365a7ca0f4

View file

@ -76,7 +76,7 @@ type gc struct {
workerPool util.WorkerPool workerPool util.WorkerPool
remover func() remover func(context.Context)
eventChan chan Event eventChan chan Event
mEventHandler map[eventType]*eventHandlers mEventHandler map[eventType]*eventHandlers
@ -115,7 +115,7 @@ func (gc *gc) init(ctx context.Context) {
} }
gc.wg.Add(2) gc.wg.Add(2)
go gc.tickRemover() go gc.tickRemover(ctx)
go gc.listenEvents(ctx) go gc.listenEvents(ctx)
} }
@ -160,7 +160,7 @@ func (gc *gc) listenEvents(ctx context.Context) {
} }
} }
func (gc *gc) tickRemover() { func (gc *gc) tickRemover(ctx context.Context) {
defer gc.wg.Done() defer gc.wg.Done()
timer := time.NewTimer(gc.removerInterval) timer := time.NewTimer(gc.removerInterval)
@ -178,7 +178,7 @@ func (gc *gc) tickRemover() {
gc.log.Debug(logs.ShardGCIsStopped) gc.log.Debug(logs.ShardGCIsStopped)
return return
case <-timer.C: case <-timer.C:
gc.remover() gc.remover(ctx)
timer.Reset(gc.removerInterval) timer.Reset(gc.removerInterval)
} }
} }
@ -196,8 +196,8 @@ func (gc *gc) stop() {
// iterates over metabase and deletes objects // iterates over metabase and deletes objects
// with GC-marked graves. // with GC-marked graves.
// Does nothing if shard is in "read-only" mode. // Does nothing if shard is in "read-only" mode.
func (s *Shard) removeGarbage() { func (s *Shard) removeGarbage(pctx context.Context) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(pctx)
defer cancel() defer cancel()
s.gcCancel.Store(cancel) s.gcCancel.Store(cancel)