do moving gc for hotstore every 20 compactions

that's about once a week
This commit is contained in:
vyzo 2021-07-12 11:14:36 +03:00
parent 818b8de182
commit 669b47cfc9

View File

@ -1,46 +1,57 @@
package splitstore package splitstore
import ( import (
"fmt"
"time" "time"
bstore "github.com/filecoin-project/lotus/blockstore" bstore "github.com/filecoin-project/lotus/blockstore"
cid "github.com/ipfs/go-cid"
) )
func (s *SplitStore) gcHotstore() { func (s *SplitStore) gcHotstore() {
// we only perform moving gc every 10 compactions as it can take a while // we only perform moving gc every 20 compactions (about once a week) as it can take a while
if s.compactionIndex%10 != 0 { if s.compactionIndex%20 == 0 {
goto online_gc if err := s.gcBlockstoreMoving(s.hot, "", nil); err != nil {
log.Warnf("error moving hotstore: %s", err)
// fallthrough to online gc
} else {
return
}
} }
// check if the hotstore is movable; if so, move it. if err := s.gcBlockstoreOnline(s.hot); err != nil {
if mover, ok := s.hot.(bstore.BlockstoreMover); ok { log.Warnf("error garbage collecting hostore: %s", err)
log.Info("moving hotstore") }
}
func (s *SplitStore) gcBlockstoreMoving(b bstore.Blockstore, path string, filter func(cid.Cid) bool) error {
if mover, ok := b.(bstore.BlockstoreMover); ok {
log.Info("moving blockstore")
startMove := time.Now() startMove := time.Now()
err := mover.MoveTo("", nil)
if err != nil { if err := mover.MoveTo(path, filter); err != nil {
log.Warnf("error moving hotstore: %s", err) return err
// try online gc
goto online_gc
} }
log.Infow("moving hotstore done", "took", time.Since(startMove)) log.Infow("moving hotstore done", "took", time.Since(startMove))
return return nil
} }
online_gc: return fmt.Errorf("blockstore doesn't support moving: %T", b)
// check if the hotstore supports online GC; if so, GC it. }
if gc, ok := s.hot.(bstore.BlockstoreGC); ok {
log.Info("garbage collecting hotstore") func (s *SplitStore) gcBlockstoreOnline(b bstore.Blockstore) error {
if gc, ok := b.(bstore.BlockstoreGC); ok {
log.Info("garbage collecting blockstore")
startGC := time.Now() startGC := time.Now()
err := gc.CollectGarbage()
if err != nil { if err := gc.CollectGarbage(); err != nil {
log.Warnf("error garbage collecting hotstore: %s", err) return err
return
} }
log.Infof("garbage collecting hotstore done", "took", time.Since(startGC)) log.Infow("garbage collecting hotstore done", "took", time.Since(startGC))
return return nil
} }
return return fmt.Errorf("blockstore doesn't support online gc: %T", b)
} }