mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
swarm/storage: remove redundant increments for dataIdx and entryCnt
This commit is contained in:
parent
2695fa2213
commit
6f3e02cbbd
2 changed files with 10 additions and 12 deletions
|
|
@ -142,13 +142,10 @@ func NewLDBStore(params *LDBStoreParams) (s *LDBStore, err error) {
|
||||||
}
|
}
|
||||||
data, _ := s.db.Get(keyEntryCnt)
|
data, _ := s.db.Get(keyEntryCnt)
|
||||||
s.entryCnt = BytesToU64(data)
|
s.entryCnt = BytesToU64(data)
|
||||||
s.entryCnt++
|
|
||||||
data, _ = s.db.Get(keyAccessCnt)
|
data, _ = s.db.Get(keyAccessCnt)
|
||||||
s.accessCnt = BytesToU64(data)
|
s.accessCnt = BytesToU64(data)
|
||||||
s.accessCnt++
|
|
||||||
data, _ = s.db.Get(keyDataIdx)
|
data, _ = s.db.Get(keyDataIdx)
|
||||||
s.dataIdx = BytesToU64(data)
|
s.dataIdx = BytesToU64(data)
|
||||||
s.dataIdx++
|
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
@ -581,13 +578,13 @@ mainLoop:
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
e = s.entryCnt
|
|
||||||
select {
|
select {
|
||||||
case <-s.quit:
|
case <-s.quit:
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
break mainLoop
|
break mainLoop
|
||||||
case <-done:
|
case <-done:
|
||||||
}
|
}
|
||||||
|
e = s.entryCnt
|
||||||
}
|
}
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ func testIterator(t *testing.T, mock bool) {
|
||||||
for poc = 0; poc <= 255; poc++ {
|
for poc = 0; poc <= 255; poc++ {
|
||||||
err := db.SyncIterator(0, uint64(chunkkeys.Len()), uint8(poc), func(k Address, n uint64) bool {
|
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)))
|
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++
|
i++
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
@ -324,12 +324,12 @@ func TestLDBStoreWithoutCollectGarbage(t *testing.T) {
|
||||||
log.Info("got back chunk", "chunk", ret)
|
log.Info("got back chunk", "chunk", ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ldb.entryCnt != uint64(n+1) {
|
if ldb.entryCnt != uint64(n) {
|
||||||
t.Fatalf("expected entryCnt to be equal to %v, but got %v", n+1, ldb.entryCnt)
|
t.Fatalf("expected entryCnt to be equal to %v, but got %v", n, ldb.entryCnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ldb.accessCnt != uint64(2*n+1) {
|
if ldb.accessCnt != uint64(2*n) {
|
||||||
t.Fatalf("expected accessCnt to be equal to %v, but got %v", n+1, ldb.accessCnt)
|
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
|
// TestLDBStoreRemoveThenCollectGarbage tests that we can delete chunks and that we can trigger garbage collection
|
||||||
func TestLDBStoreRemoveThenCollectGarbage(t *testing.T) {
|
func TestLDBStoreRemoveThenCollectGarbage(t *testing.T) {
|
||||||
capacity := 10
|
capacity := 11
|
||||||
|
|
||||||
ldb, cleanup := newLDBStore(t)
|
ldb, cleanup := newLDBStore(t)
|
||||||
ldb.setCapacity(uint64(capacity))
|
ldb.setCapacity(uint64(capacity))
|
||||||
|
|
||||||
n := 7
|
n := 11
|
||||||
|
|
||||||
chunks := []*Chunk{}
|
chunks := []*Chunk{}
|
||||||
for i := 0; i < capacity; i++ {
|
for i := 0; i < capacity; i++ {
|
||||||
|
|
@ -491,9 +491,10 @@ func TestLDBStoreRemoveThenCollectGarbage(t *testing.T) {
|
||||||
cleanup()
|
cleanup()
|
||||||
|
|
||||||
ldb, cleanup = newLDBStore(t)
|
ldb, cleanup = newLDBStore(t)
|
||||||
|
capacity = 10
|
||||||
ldb.setCapacity(uint64(capacity))
|
ldb.setCapacity(uint64(capacity))
|
||||||
|
|
||||||
n = 10
|
n = 11
|
||||||
|
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
ldb.Put(context.TODO(), chunks[i])
|
ldb.Put(context.TODO(), chunks[i])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue