From fb3986226f9f57b09565acc1e51d2f89e423aae7 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 23 Jul 2021 22:55:03 +0300 Subject: [PATCH] do hotstore moving GC in splitstore with a user-specified frequency --- blockstore/splitstore/splitstore.go | 7 +++++++ blockstore/splitstore/splitstore_gc.go | 15 +++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index 7a2abf9a8..07f211be2 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -81,6 +81,13 @@ type Config struct { // - a positive integer indicates the number of finalities, outside the compaction boundary, // for which messages will be retained in the hotstore. HotStoreMessageRetention uint64 + + // HotstoreMovingGCFrequency indicates how frequently to garbage collect the hotstore using + // moving GC (if supported by the hotstore). + // A value of 0 disables moving GC entirely. + // A positive value is the number of compactions before a moving GC is performed; + // a value of 1 will perform moving GC in every compaction. + HotStoreMovingGCFrequency uint } // ChainAccessor allows the Splitstore to access the chain. It will most likely diff --git a/blockstore/splitstore/splitstore_gc.go b/blockstore/splitstore/splitstore_gc.go index 46668167c..cd7703963 100644 --- a/blockstore/splitstore/splitstore_gc.go +++ b/blockstore/splitstore/splitstore_gc.go @@ -8,17 +8,24 @@ import ( ) func (s *SplitStore) gcHotstore() { - if err := s.gcBlockstoreOnline(s.hot); err != nil { + var opts map[interface{}]interface{} + if s.cfg.HotStoreMovingGCFrequency > 0 && s.compactionIndex%int64(s.cfg.HotStoreMovingGCFrequency) == 0 { + opts = map[interface{}]interface{}{ + bstore.BlockstoreMovingGC: true, + } + } + + if err := s.gcBlockstore(s.hot, opts); err != nil { log.Warnf("error garbage collecting hostore: %s", err) } } -func (s *SplitStore) gcBlockstoreOnline(b bstore.Blockstore) error { +func (s *SplitStore) gcBlockstore(b bstore.Blockstore, opts map[interface{}]interface{}) error { if gc, ok := b.(bstore.BlockstoreGC); ok { log.Info("garbage collecting blockstore") startGC := time.Now() - if err := gc.CollectGarbage(); err != nil { + if err := gc.CollectGarbage(opts); err != nil { return err } @@ -26,5 +33,5 @@ func (s *SplitStore) gcBlockstoreOnline(b bstore.Blockstore) error { return nil } - return fmt.Errorf("blockstore doesn't support online gc: %T", b) + return fmt.Errorf("blockstore doesn't support garbage collection: %T", b) }