use functional options for hotstore gc, rename MovingGC to FullGC

This commit is contained in:
vyzo 2021-07-27 09:53:22 +03:00
parent 96c1123c33
commit 9d25464703
5 changed files with 19 additions and 21 deletions

View File

@ -82,12 +82,12 @@ type Config struct {
// 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 uint64
// HotstoreFullGCFrequency indicates how frequently (in terms of compactions) to garbage collect
// the hotstore using full (moving) GC if supported by the hotstore.
// A value of 0 disables full GC entirely.
// A positive value is the number of compactions before a full GC is performed;
// a value of 1 will perform full GC in every compaction.
HotStoreFullGCFrequency uint64
}
// ChainAccessor allows the Splitstore to access the chain. It will most likely

View File

@ -8,11 +8,9 @@ import (
)
func (s *SplitStore) gcHotstore() {
var opts map[interface{}]interface{}
if s.cfg.HotStoreMovingGCFrequency > 0 && s.compactionIndex%int64(s.cfg.HotStoreMovingGCFrequency) == 0 {
opts = map[interface{}]interface{}{
bstore.BlockstoreMovingGC: true,
}
var opts []bstore.BlockstoreGCOption
if s.cfg.HotStoreFullGCFrequency > 0 && s.compactionIndex%int64(s.cfg.HotStoreFullGCFrequency) == 0 {
opts = append(opts, bstore.WithFullGC(true))
}
if err := s.gcBlockstore(s.hot, opts); err != nil {
@ -20,12 +18,12 @@ func (s *SplitStore) gcHotstore() {
}
}
func (s *SplitStore) gcBlockstore(b bstore.Blockstore, opts map[interface{}]interface{}) error {
func (s *SplitStore) gcBlockstore(b bstore.Blockstore, opts []bstore.BlockstoreGCOption) error {
if gc, ok := b.(bstore.BlockstoreGC); ok {
log.Info("garbage collecting blockstore")
startGC := time.Now()
if err := gc.CollectGarbage(opts); err != nil {
if err := gc.CollectGarbage(opts...); err != nil {
return err
}

View File

@ -73,7 +73,7 @@ func DefaultFullNode() *FullNode {
HotStoreType: "badger",
MarkSetType: "map",
HotStoreMovingGCFrequency: 20,
HotStoreFullGCFrequency: 20,
},
},
}

View File

@ -291,10 +291,10 @@ type Splitstore struct {
// HotStoreMessageRetention specifies the retention policy for messages, in finalities beyond
// the compaction boundary; default is 0.
HotStoreMessageRetention uint64
// HotStoreMovingGCFrequency specifies how often to perform moving GC on the hotstore.
// A value of 0 disables, while a value 1 will do moving GC in every compaction.
// HotStoreFullGCFrequency specifies how often to perform a full (moving) GC on the hotstore.
// A value of 0 disables, while a value 1 will do full GC in every compaction.
// Default is 20 (about once a week).
HotStoreMovingGCFrequency uint64
HotStoreFullGCFrequency uint64
}
// // Full Node

View File

@ -78,10 +78,10 @@ func SplitBlockstore(cfg *config.Chainstore) func(lc fx.Lifecycle, r repo.Locked
}
cfg := &splitstore.Config{
MarkSetType: cfg.Splitstore.MarkSetType,
DiscardColdBlocks: cfg.Splitstore.ColdStoreType == "discard",
HotStoreMessageRetention: cfg.Splitstore.HotStoreMessageRetention,
HotStoreMovingGCFrequency: cfg.Splitstore.HotStoreMovingGCFrequency,
MarkSetType: cfg.Splitstore.MarkSetType,
DiscardColdBlocks: cfg.Splitstore.ColdStoreType == "discard",
HotStoreMessageRetention: cfg.Splitstore.HotStoreMessageRetention,
HotStoreFullGCFrequency: cfg.Splitstore.HotStoreFullGCFrequency,
}
ss, err := splitstore.Open(path, ds, hot, cold, cfg)
if err != nil {