From 6f3e02cbbd9fc94dcd2f98a0af07ab6d7a3e6ac4 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Fri, 17 Aug 2018 13:55:46 +0200 Subject: [PATCH] swarm/storage: remove redundant increments for dataIdx and entryCnt --- swarm/storage/ldbstore.go | 5 +---- swarm/storage/ldbstore_test.go | 17 +++++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/swarm/storage/ldbstore.go b/swarm/storage/ldbstore.go index 7920ee7674..f81bdc76ad 100644 --- a/swarm/storage/ldbstore.go +++ b/swarm/storage/ldbstore.go @@ -142,13 +142,10 @@ func NewLDBStore(params *LDBStoreParams) (s *LDBStore, err error) { } data, _ := s.db.Get(keyEntryCnt) s.entryCnt = BytesToU64(data) - s.entryCnt++ data, _ = s.db.Get(keyAccessCnt) s.accessCnt = BytesToU64(data) - s.accessCnt++ data, _ = s.db.Get(keyDataIdx) s.dataIdx = BytesToU64(data) - s.dataIdx++ return s, nil } @@ -581,13 +578,13 @@ mainLoop: close(done) }() - e = s.entryCnt select { case <-s.quit: s.lock.Unlock() break mainLoop case <-done: } + e = s.entryCnt } s.lock.Unlock() } diff --git a/swarm/storage/ldbstore_test.go b/swarm/storage/ldbstore_test.go index 5ee88baa51..16ac7ee2e4 100644 --- a/swarm/storage/ldbstore_test.go +++ b/swarm/storage/ldbstore_test.go @@ -209,7 +209,7 @@ func testIterator(t *testing.T, mock bool) { for poc = 0; poc <= 255; poc++ { err := db.SyncIterator(0, uint64(chunkkeys.Len()), uint8(poc), func(k Address, n uint64) bool { log.Trace(fmt.Sprintf("Got key %v number %d poc %d", k, n, uint8(poc))) - chunkkeys_results[n-1] = k + chunkkeys_results[n] = k i++ return true }) @@ -324,12 +324,12 @@ func TestLDBStoreWithoutCollectGarbage(t *testing.T) { log.Info("got back chunk", "chunk", ret) } - if ldb.entryCnt != uint64(n+1) { - t.Fatalf("expected entryCnt to be equal to %v, but got %v", n+1, ldb.entryCnt) + if ldb.entryCnt != uint64(n) { + t.Fatalf("expected entryCnt to be equal to %v, but got %v", n, ldb.entryCnt) } - if ldb.accessCnt != uint64(2*n+1) { - t.Fatalf("expected accessCnt to be equal to %v, but got %v", n+1, ldb.accessCnt) + if ldb.accessCnt != uint64(2*n) { + t.Fatalf("expected accessCnt to be equal to %v, but got %v", 2*n, ldb.accessCnt) } } @@ -452,12 +452,12 @@ func TestLDBStoreAddRemove(t *testing.T) { // TestLDBStoreRemoveThenCollectGarbage tests that we can delete chunks and that we can trigger garbage collection func TestLDBStoreRemoveThenCollectGarbage(t *testing.T) { - capacity := 10 + capacity := 11 ldb, cleanup := newLDBStore(t) ldb.setCapacity(uint64(capacity)) - n := 7 + n := 11 chunks := []*Chunk{} for i := 0; i < capacity; i++ { @@ -491,9 +491,10 @@ func TestLDBStoreRemoveThenCollectGarbage(t *testing.T) { cleanup() ldb, cleanup = newLDBStore(t) + capacity = 10 ldb.setCapacity(uint64(capacity)) - n = 10 + n = 11 for i := 0; i < n; i++ { ldb.Put(context.TODO(), chunks[i])