[#745] gc: Stop GC work on Shard's Close

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-08-04 15:04:37 +03:00 committed by Alex Vanin
parent 6527f9157c
commit 3d981320c6
3 changed files with 23 additions and 7 deletions

View file

@ -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
}

View file

@ -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() {

View file

@ -18,6 +18,8 @@ import (
type Shard struct {
*cfg
gc *gc
mode *atomic.Uint32
writeCache writecache.Cache