From 8562a9bb8208b70fcdf151852d1e0dde5e1f99e8 Mon Sep 17 00:00:00 2001 From: vyzo <vyzo@hackzen.org> Date: Mon, 8 Mar 2021 18:12:09 +0200 Subject: [PATCH] garbage collect hotstore after compaction --- blockstore/badger/blockstore.go | 9 +++++++++ blockstore/splitstore/splitstore.go | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/blockstore/badger/blockstore.go b/blockstore/badger/blockstore.go index cd740e650..7c249880c 100644 --- a/blockstore/badger/blockstore.go +++ b/blockstore/badger/blockstore.go @@ -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 { + if atomic.LoadInt64(&b.state) != stateOpen { + return ErrBlockstoreClosed + } + + return b.DB.RunValueLogGC(0.125) +} + // 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 { diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index 5ed64b54e..c69e26cc2 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -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)