From 3bd77701d8acdb3f0eb304107452bcecbb71db50 Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 8 Mar 2021 19:46:21 +0200 Subject: [PATCH] deduplicate code --- blockstore/splitstore/splitstore.go | 35 +++++++++++++---------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index 4e20dd7d2..fb3e28803 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -710,16 +710,7 @@ func (s *SplitStore) compactSimple(curTs *types.TipSet) error { return xerrors.Errorf("error syncing tracker: %w", err) } - 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)) - } - } + s.gcHotstore() err = s.setBaseEpoch(coldEpoch) if err != nil { @@ -806,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 @@ -1016,16 +1020,7 @@ func (s *SplitStore) compactFull(curTs *types.TipSet) error { return xerrors.Errorf("error syncing tracker: %w", err) } - 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)) - } - } + s.gcHotstore() err = s.setBaseEpoch(coldEpoch) if err != nil {