do hotstore moving GC in splitstore with a user-specified frequency

This commit is contained in:
vyzo 2021-07-23 22:55:03 +03:00
parent c747f2f1e2
commit fb3986226f
2 changed files with 18 additions and 4 deletions

View File

@ -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

View File

@ -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)
}