Skip to content

Commit

Permalink
Merge pull request #5744 from filecoin-project/feat/splitstore-gc
Browse files Browse the repository at this point in the history
garbage collect hotstore after compaction
  • Loading branch information
vyzo authored Mar 8, 2021
2 parents e85391b + 3bd7770 commit c52dae4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions blockstore/badger/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ func (b *Blockstore) Close() error {
return b.DB.Close()
}

// CollectGarbage runs garbage collection on the value log
func (b *Blockstore) CollectGarbage() error {
if atomic.LoadInt64(&b.state) != stateOpen {
return ErrBlockstoreClosed
}

err := b.DB.RunValueLogGC(0.125)
if err == badger.ErrNoRewrite {
// not really an error in this case
return nil
}

return err
}

// View implements blockstore.Viewer, which leverages zero-copy read-only
// access to values.
func (b *Blockstore) View(cid cid.Cid, fn func([]byte) error) error {
Expand Down
17 changes: 17 additions & 0 deletions blockstore/splitstore/splitstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,8 @@ func (s *SplitStore) compactSimple(curTs *types.TipSet) error {
return xerrors.Errorf("error syncing tracker: %w", err)
}

s.gcHotstore()

err = s.setBaseEpoch(coldEpoch)
if err != nil {
return xerrors.Errorf("error saving base epoch: %w", err)
Expand Down Expand Up @@ -795,6 +797,19 @@ func (s *SplitStore) purgeTracking(cids []cid.Cid) error {
return s.purgeBatch(cids, s.tracker.DeleteBatch)
}

func (s *SplitStore) gcHotstore() {
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)
} else {
log.Infow("garbage collection done", "took", time.Since(startGC))
}
}
}

func (s *SplitStore) compactFull(curTs *types.TipSet) error {
currentEpoch := curTs.Height()
coldEpoch := s.baseEpoch + CompactionCold
Expand Down Expand Up @@ -1005,6 +1020,8 @@ func (s *SplitStore) compactFull(curTs *types.TipSet) error {
return xerrors.Errorf("error syncing tracker: %w", err)
}

s.gcHotstore()

err = s.setBaseEpoch(coldEpoch)
if err != nil {
return xerrors.Errorf("error saving base epoch: %w", err)
Expand Down

0 comments on commit c52dae4

Please sign in to comment.