Skip to content

Commit

Permalink
refactor gcHotstore to break out components and cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Jul 13, 2021
1 parent 23555c9 commit 2e5635c
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions blockstore/splitstore/splitstore_gc.go
Original file line number Diff line number Diff line change
@@ -1,46 +1,57 @@
package splitstore

import (
"fmt"
"time"

bstore "github.com/filecoin-project/lotus/blockstore"
cid "github.com/ipfs/go-cid"
)

func (s *SplitStore) gcHotstore() {
// we only perform moving gc every 20 compactions (about once a week) as it can take a while
if s.compactionIndex%20 != 0 {
goto online_gc
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
}
}

// check if the hotstore is movable; if so, move it.
if mover, ok := s.hot.(bstore.BlockstoreMover); ok {
log.Info("moving hotstore")
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")
startMove := time.Now()
err := mover.MoveTo("", nil)
if err != nil {
log.Warnf("error moving hotstore: %s", err)
// try online gc
goto online_gc

if err := mover.MoveTo(path, filter); err != nil {
return err
}

log.Infow("moving hotstore done", "took", time.Since(startMove))
return
return nil
}

online_gc:
// check if the hotstore supports online GC; if so, GC it.
if gc, ok := s.hot.(bstore.BlockstoreGC); ok {
log.Info("garbage collecting hotstore")
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")
startGC := time.Now()
err := gc.CollectGarbage()
if err != nil {
log.Warnf("error garbage collecting hotstore: %s", err)
return

if err := gc.CollectGarbage(); err != nil {
return err
}

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)
}

0 comments on commit 2e5635c

Please sign in to comment.