mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
swarm/storage/localstore: use shed Iterate function
This commit is contained in:
parent
d54d7ae0f8
commit
67473be38a
2 changed files with 16 additions and 10 deletions
|
|
@ -78,7 +78,7 @@ func (db *DB) collectGarbage() (collectedCount int64, done bool, err error) {
|
|||
target := db.gcTarget()
|
||||
|
||||
done = true
|
||||
err = db.gcIndex.IterateAll(func(item shed.Item) (stop bool, err error) {
|
||||
err = db.gcIndex.Iterate(func(item shed.Item) (stop bool, err error) {
|
||||
gcSize := atomic.LoadInt64(&db.gcSize)
|
||||
if gcSize-collectedCount <= target {
|
||||
return true, nil
|
||||
|
|
@ -96,7 +96,7 @@ func (db *DB) collectGarbage() (collectedCount int64, done bool, err error) {
|
|||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return 0, false, err
|
||||
}
|
||||
|
|
@ -183,7 +183,7 @@ func (db *DB) writeGCSize(gcSize int64) (err error) {
|
|||
// use only one iterator as it acquires its snapshot
|
||||
// not to remove hashes from index that are added
|
||||
// after stored gc size is written
|
||||
err = db.gcUncountedHashesIndex.IterateAll(func(item shed.Item) (stop bool, err error) {
|
||||
err = db.gcUncountedHashesIndex.Iterate(func(item shed.Item) (stop bool, err error) {
|
||||
db.gcUncountedHashesIndex.DeleteInBatch(batch, item)
|
||||
batchSize++
|
||||
if batchSize >= maxBatchSize {
|
||||
|
|
@ -195,7 +195,7 @@ func (db *DB) writeGCSize(gcSize int64) (err error) {
|
|||
batchSize = 0
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -381,10 +381,13 @@ func newGCIndexTest(db *DB, chunk storage.Chunk, storeTimestamp, accessTimestamp
|
|||
func newItemsCountTest(i shed.Index, want int) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
var c int
|
||||
i.IterateAll(func(item shed.Item) (stop bool, err error) {
|
||||
err := i.Iterate(func(item shed.Item) (stop bool, err error) {
|
||||
c++
|
||||
return
|
||||
})
|
||||
}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c != want {
|
||||
t.Errorf("got %v items in index, want %v", c, want)
|
||||
}
|
||||
|
|
@ -396,10 +399,13 @@ func newItemsCountTest(i shed.Index, want int) func(t *testing.T) {
|
|||
func newIndexGCSizeTest(db *DB) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
var want int64
|
||||
db.gcIndex.IterateAll(func(item shed.Item) (stop bool, err error) {
|
||||
err := db.gcIndex.Iterate(func(item shed.Item) (stop bool, err error) {
|
||||
want++
|
||||
return
|
||||
})
|
||||
}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := atomic.LoadInt64(&db.gcSize)
|
||||
if got != want {
|
||||
t.Errorf("got gc size %v, want %v", got, want)
|
||||
|
|
@ -424,7 +430,7 @@ func testItemsOrder(t *testing.T, i shed.Index, chunks []testIndexChunk, sortFun
|
|||
}
|
||||
|
||||
var cursor int
|
||||
err := i.IterateAll(func(item shed.Item) (stop bool, err error) {
|
||||
err := i.Iterate(func(item shed.Item) (stop bool, err error) {
|
||||
want := chunks[cursor].Address()
|
||||
got := item.Address
|
||||
if !bytes.Equal(got, want) {
|
||||
|
|
@ -432,7 +438,7 @@ func testItemsOrder(t *testing.T, i shed.Index, chunks []testIndexChunk, sortFun
|
|||
}
|
||||
cursor++
|
||||
return false, nil
|
||||
})
|
||||
}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue