From c93328b036a1d7fcf122cd8c5ca750271b11bf65 Mon Sep 17 00:00:00 2001 From: vyzo Date: Sun, 11 Jul 2021 08:38:57 +0300 Subject: [PATCH] use the new traits for hotstore gc --- blockstore/badger/blockstore.go | 2 +- blockstore/splitstore/splitstore.go | 24 ---------------- blockstore/splitstore/splitstore_gc.go | 39 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 blockstore/splitstore/splitstore_gc.go diff --git a/blockstore/badger/blockstore.go b/blockstore/badger/blockstore.go index 9bd982287..82f0e3360 100644 --- a/blockstore/badger/blockstore.go +++ b/blockstore/badger/blockstore.go @@ -180,7 +180,7 @@ func (b *Blockstore) CollectGarbage() error { } for err == nil { - err = b.db.RunValueLogGC(0.125) + err = b.DB.RunValueLogGC(0.125) } if err == badger.ErrNoRewrite { diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index 75989b53c..e995e666d 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -1697,30 +1697,6 @@ func (s *SplitStore) waitForMissingRefs(markSet MarkSet) { } } -func (s *SplitStore) gcHotstore() { - if compact, ok := s.hot.(interface{ Compact() error }); ok { - log.Infof("compacting hotstore") - startCompact := time.Now() - err := compact.Compact() - if err != nil { - log.Warnf("error compacting hotstore: %s", err) - return - } - log.Infow("hotstore compaction done", "took", time.Since(startCompact)) - } - - 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) - return - } - log.Infow("hotstore garbage collection done", "took", time.Since(startGC)) - } -} - func (s *SplitStore) setBaseEpoch(epoch abi.ChainEpoch) error { s.baseEpoch = epoch return s.ds.Put(baseEpochKey, epochToBytes(epoch)) diff --git a/blockstore/splitstore/splitstore_gc.go b/blockstore/splitstore/splitstore_gc.go new file mode 100644 index 000000000..a7dab7410 --- /dev/null +++ b/blockstore/splitstore/splitstore_gc.go @@ -0,0 +1,39 @@ +package splitstore + +import ( + "time" + + bstore "github.com/filecoin-project/lotus/blockstore" +) + +func (s *SplitStore) gcHotstore() { + // check if the hotstore is movable; if so, move it. + if mover, ok := s.hot.(bstore.BlockstoreMover); ok { + log.Info("moving hotstore") + startMove := time.Now() + err := mover.MoveTo("", nil) + if err != nil { + log.Warnf("error moving hotstore: %s", err) + return + } + + log.Infof("moving hotstore done", "took", time.Since(startMove)) + return + } + + // check if the hotstore supports online GC; if so, GC it. + if gc, ok := s.hot.(bstore.BlockstoreGC); ok { + log.Info("garbage collecting hotstore") + startGC := time.Now() + err := gc.CollectGarbage() + if err != nil { + log.Warnf("error garbage collecting hotstore: %s", err) + return + } + + log.Infof("garbage collecting hotstore done", "took", time.Since(startGC)) + return + } + + return +}