Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
swarm/storage/localstore: use shed Iterate function
Browse files Browse the repository at this point in the history
  • Loading branch information
janos committed Dec 19, 2018
1 parent d54d7ae commit 67473be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions swarm/storage/localstore/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -195,7 +195,7 @@ func (db *DB) writeGCSize(gcSize int64) (err error) {
batchSize = 0
}
return false, nil
})
}, nil)
if err != nil {
return err
}
Expand Down
18 changes: 12 additions & 6 deletions swarm/storage/localstore/localstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand All @@ -424,15 +430,15 @@ 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) {
return true, fmt.Errorf("got address %x at position %v, want %x", got, cursor, want)
}
cursor++
return false, nil
})
}, nil)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 67473be

Please sign in to comment.