2021-07-11 05:38:57 +00:00
|
|
|
package splitstore
|
|
|
|
|
|
|
|
import (
|
2021-07-12 08:14:36 +00:00
|
|
|
"fmt"
|
2021-07-11 05:38:57 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
bstore "github.com/filecoin-project/lotus/blockstore"
|
2021-07-12 08:14:36 +00:00
|
|
|
cid "github.com/ipfs/go-cid"
|
2021-07-11 05:38:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *SplitStore) gcHotstore() {
|
2021-07-12 08:14:36 +00:00
|
|
|
// we only perform moving gc every 20 compactions (about once a week) as it can take a while
|
|
|
|
if s.compactionIndex%20 == 0 {
|
|
|
|
if err := s.gcBlockstoreMoving(s.hot, "", nil); err != nil {
|
|
|
|
log.Warnf("error moving hotstore: %s", err)
|
|
|
|
// fallthrough to online gc
|
|
|
|
} else {
|
|
|
|
return
|
|
|
|
}
|
2021-07-12 05:39:12 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 08:14:36 +00:00
|
|
|
if err := s.gcBlockstoreOnline(s.hot); err != nil {
|
|
|
|
log.Warnf("error garbage collecting hostore: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
2021-07-11 05:38:57 +00:00
|
|
|
startMove := time.Now()
|
2021-07-12 08:14:36 +00:00
|
|
|
|
|
|
|
if err := mover.MoveTo(path, filter); err != nil {
|
|
|
|
return err
|
2021-07-11 05:38:57 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 05:39:12 +00:00
|
|
|
log.Infow("moving hotstore done", "took", time.Since(startMove))
|
2021-07-12 08:14:36 +00:00
|
|
|
return nil
|
2021-07-11 05:38:57 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 08:14:36 +00:00
|
|
|
return fmt.Errorf("blockstore doesn't support moving: %T", b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SplitStore) gcBlockstoreOnline(b bstore.Blockstore) error {
|
|
|
|
if gc, ok := b.(bstore.BlockstoreGC); ok {
|
|
|
|
log.Info("garbage collecting blockstore")
|
2021-07-11 05:38:57 +00:00
|
|
|
startGC := time.Now()
|
2021-07-12 08:14:36 +00:00
|
|
|
|
|
|
|
if err := gc.CollectGarbage(); err != nil {
|
|
|
|
return err
|
2021-07-11 05:38:57 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 08:14:36 +00:00
|
|
|
log.Infow("garbage collecting hotstore done", "took", time.Since(startGC))
|
|
|
|
return nil
|
2021-07-11 05:38:57 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 08:14:36 +00:00
|
|
|
return fmt.Errorf("blockstore doesn't support online gc: %T", b)
|
2021-07-11 05:38:57 +00:00
|
|
|
}
|