swarm/storage: fix garbage collection to run until we reach capacity

This commit is contained in:
Anton Evangelatov 2018-04-16 14:43:50 +03:00
parent b11804c2bc
commit 25cd805bea
2 changed files with 8 additions and 1 deletions

View file

@ -562,9 +562,10 @@ func (s *LDBStore) writeBatches() {
log.Error(fmt.Sprintf("spawn batch write (%d entries): %v", b.Len(), err))
}
close(c)
if e >= s.capacity {
for e > s.capacity {
log.Info("collecting garbage", "entryCnt", e, "capacity", s.capacity)
s.collectGarbage(gcArrayFreeRatio)
e = s.entryCnt
}
s.lock.Unlock()
}

View file

@ -31,6 +31,12 @@ type MemStore struct {
disabled bool
}
//NewMemStore is instantiating a MemStore cache. We are keeping a record of all outgoing requests for chunks, that
//should later be delivered by peer nodes, in the `requests` LRU cache. We are also keeping all frequently requested
//chunks in the `cache` LRU cache.
//
//`requests` LRU cache capacity should ideally never be reached, this is why for the time being it should be initialised
//with the same value as the LDBStore capacity.
func NewMemStore(params *StoreParams, _ *LDBStore) (m *MemStore) {
if params.CacheCapacity == 0 {
return &MemStore{