Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

garbage collect hotstore after compaction #5744

Merged
merged 4 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions blockstore/badger/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ func (b *Blockstore) Close() error {
return b.DB.Close()
}

// GC runs garbage collection on the value log
func (b *Blockstore) GC() error {
vyzo marked this conversation as resolved.
Show resolved Hide resolved
if atomic.LoadInt64(&b.state) != stateOpen {
return ErrBlockstoreClosed
}

return b.DB.RunValueLogGC(0.125)
vyzo marked this conversation as resolved.
Show resolved Hide resolved
}

// 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
22 changes: 22 additions & 0 deletions blockstore/splitstore/splitstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,17 @@ func (s *SplitStore) compactSimple(curTs *types.TipSet) error {
return xerrors.Errorf("error syncing tracker: %w", err)
}

if gc, ok := s.hot.(interface{ GC() error }); ok {
log.Infof("garbage collecting hotstore")
startGC := time.Now()
err = gc.GC()
if err != nil {
log.Warnf("error garbage collecting hotstore: %s", err)
} else {
log.Infow("garbage collecting done", "took", time.Since(startGC))
}
}

err = s.setBaseEpoch(coldEpoch)
if err != nil {
return xerrors.Errorf("error saving base epoch: %w", err)
Expand Down Expand Up @@ -1005,6 +1016,17 @@ func (s *SplitStore) compactFull(curTs *types.TipSet) error {
return xerrors.Errorf("error syncing tracker: %w", err)
}

if gc, ok := s.hot.(interface{ GC() error }); ok {
log.Infof("garbage collecting hotstore")
startGC := time.Now()
err = gc.GC()
if err != nil {
log.Warnf("error garbage collecting hotstore: %s", err)
} else {
log.Infow("garbage collecting done", "took", time.Since(startGC))
}
}

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