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"
|
|
|
|
)
|
|
|
|
|
2023-03-03 16:14:52 +00:00
|
|
|
func (s *SplitStore) gcHotAfterCompaction() {
|
2021-07-27 06:53:22 +00:00
|
|
|
var opts []bstore.BlockstoreGCOption
|
|
|
|
if s.cfg.HotStoreFullGCFrequency > 0 && s.compactionIndex%int64(s.cfg.HotStoreFullGCFrequency) == 0 {
|
|
|
|
opts = append(opts, bstore.WithFullGC(true))
|
2021-07-23 19:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-27 06:53:22 +00:00
|
|
|
func (s *SplitStore) gcBlockstore(b bstore.Blockstore, opts []bstore.BlockstoreGCOption) 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
|
|
|
|
2023-03-03 16:14:52 +00:00
|
|
|
if err := gc.CollectGarbage(s.ctx, opts...); err != nil {
|
2021-07-12 08:14:36 +00:00
|
|
|
return err
|
2021-07-11 05:38:57 +00:00
|
|
|
}
|
|
|
|
|
2022-08-05 20:34:16 +00:00
|
|
|
log.Infow("garbage collecting blockstore done", "took", time.Since(startGC))
|
2021-07-12 08:14:36 +00:00
|
|
|
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
|
|
|
}
|
2023-03-03 16:14:52 +00:00
|
|
|
|
|
|
|
func (s *SplitStore) gcBlockstoreOnce(b bstore.Blockstore, opts []bstore.BlockstoreGCOption) error {
|
|
|
|
if gc, ok := b.(bstore.BlockstoreGCOnce); ok {
|
|
|
|
log.Debug("gc blockstore once")
|
|
|
|
startGC := time.Now()
|
|
|
|
|
|
|
|
if err := gc.GCOnce(s.ctx, opts...); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debugw("gc blockstore once done", "took", time.Since(startGC))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("blockstore doesn't support gc once: %T", b)
|
|
|
|
}
|