From 25cd805bea861af631392edfe92961bc1d17fc93 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Mon, 16 Apr 2018 14:43:50 +0300 Subject: [PATCH] swarm/storage: fix garbage collection to run until we reach capacity --- swarm/storage/ldbstore.go | 3 ++- swarm/storage/memstore_lrucache.go | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/swarm/storage/ldbstore.go b/swarm/storage/ldbstore.go index ae5caf700d..8c18e88a12 100644 --- a/swarm/storage/ldbstore.go +++ b/swarm/storage/ldbstore.go @@ -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() } diff --git a/swarm/storage/memstore_lrucache.go b/swarm/storage/memstore_lrucache.go index 7e93a5a8e7..a66dcd0c22 100644 --- a/swarm/storage/memstore_lrucache.go +++ b/swarm/storage/memstore_lrucache.go @@ -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{