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"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *SplitStore) gcHotstore() {
|
2021-07-23 19:55:03 +00:00
|
|
|
var opts map[interface{}]interface{}
|
|
|
|
if s.cfg.HotStoreMovingGCFrequency > 0 && s.compactionIndex%int64(s.cfg.HotStoreMovingGCFrequency) == 0 {
|
|
|
|
opts = map[interface{}]interface{}{
|
|
|
|
bstore.BlockstoreMovingGC: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.gcBlockstore(s.hot, opts); err != nil {
|
2021-07-12 08:14:36 +00:00
|
|
|
log.Warnf("error garbage collecting hostore: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 19:55:03 +00:00
|
|
|
func (s *SplitStore) gcBlockstore(b bstore.Blockstore, opts map[interface{}]interface{}) error {
|
2021-07-12 08:14:36 +00:00
|
|
|
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
|
|
|
|
2021-07-23 19:55:03 +00:00
|
|
|
if err := gc.CollectGarbage(opts); err != nil {
|
2021-07-12 08:14:36 +00:00
|
|
|
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-23 19:55:03 +00:00
|
|
|
return fmt.Errorf("blockstore doesn't support garbage collection: %T", b)
|
2021-07-11 05:38:57 +00:00
|
|
|
}
|