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