use the new traits for hotstore gc

This commit is contained in:
vyzo 2021-07-11 08:38:57 +03:00
parent 35180b4761
commit c93328b036
3 changed files with 40 additions and 25 deletions

View File

@ -180,7 +180,7 @@ func (b *Blockstore) CollectGarbage() error {
}
for err == nil {
err = b.db.RunValueLogGC(0.125)
err = b.DB.RunValueLogGC(0.125)
}
if err == badger.ErrNoRewrite {

View File

@ -1697,30 +1697,6 @@ func (s *SplitStore) waitForMissingRefs(markSet MarkSet) {
}
}
func (s *SplitStore) gcHotstore() {
if compact, ok := s.hot.(interface{ Compact() error }); ok {
log.Infof("compacting hotstore")
startCompact := time.Now()
err := compact.Compact()
if err != nil {
log.Warnf("error compacting hotstore: %s", err)
return
}
log.Infow("hotstore compaction done", "took", time.Since(startCompact))
}
if gc, ok := s.hot.(interface{ CollectGarbage() error }); ok {
log.Infof("garbage collecting hotstore")
startGC := time.Now()
err := gc.CollectGarbage()
if err != nil {
log.Warnf("error garbage collecting hotstore: %s", err)
return
}
log.Infow("hotstore garbage collection done", "took", time.Since(startGC))
}
}
func (s *SplitStore) setBaseEpoch(epoch abi.ChainEpoch) error {
s.baseEpoch = epoch
return s.ds.Put(baseEpochKey, epochToBytes(epoch))

View File

@ -0,0 +1,39 @@
package splitstore
import (
"time"
bstore "github.com/filecoin-project/lotus/blockstore"
)
func (s *SplitStore) gcHotstore() {
// check if the hotstore is movable; if so, move it.
if mover, ok := s.hot.(bstore.BlockstoreMover); ok {
log.Info("moving hotstore")
startMove := time.Now()
err := mover.MoveTo("", nil)
if err != nil {
log.Warnf("error moving hotstore: %s", err)
return
}
log.Infof("moving hotstore done", "took", time.Since(startMove))
return
}
// check if the hotstore supports online GC; if so, GC it.
if gc, ok := s.hot.(bstore.BlockstoreGC); ok {
log.Info("garbage collecting hotstore")
startGC := time.Now()
err := gc.CollectGarbage()
if err != nil {
log.Warnf("error garbage collecting hotstore: %s", err)
return
}
log.Infof("garbage collecting hotstore done", "took", time.Since(startGC))
return
}
return
}