mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
swarm/storage: Fix iterator condition
This commit is contained in:
parent
d4944a3883
commit
26f6a509c7
2 changed files with 35 additions and 6 deletions
|
|
@ -604,15 +604,15 @@ func (s *LDBStore) CleanGCIndex() error {
|
|||
|
||||
it.Release()
|
||||
|
||||
//var idx dpaDBIndex
|
||||
var poPtrs [256]uint64
|
||||
var doneIterating bool
|
||||
lastIdxKey := []byte{keyIndex}
|
||||
for !doneIterating {
|
||||
var idxs []dpaDBIndex
|
||||
var chunkHashes [][]byte
|
||||
var pos []uint8
|
||||
it := s.db.NewIterator()
|
||||
it.Seek([]byte{keyIndex})
|
||||
it.Seek(lastIdxKey)
|
||||
for i := 0; i < 4096; i++ {
|
||||
if !it.Valid() {
|
||||
doneIterating = true
|
||||
|
|
@ -630,6 +630,7 @@ func (s *LDBStore) CleanGCIndex() error {
|
|||
return fmt.Errorf("corrupt index: %v", err)
|
||||
}
|
||||
po := s.po(chunkHash)
|
||||
lastIdxKey = it.Key()
|
||||
|
||||
// if we don't find the data key, remove the entry
|
||||
dataKey := getDataKey(idx.Idx, po)
|
||||
|
|
@ -637,9 +638,6 @@ func (s *LDBStore) CleanGCIndex() error {
|
|||
if err != nil {
|
||||
log.Warn("deleting inconsistent index (missing data)", "key", chunkHash)
|
||||
batch.Delete(it.Key())
|
||||
// if err := s.db.Delete(it.Key()); err != nil {
|
||||
// return err
|
||||
// }
|
||||
} else {
|
||||
idxs = append(idxs, idx)
|
||||
chunkHashes = append(chunkHashes, chunkHash)
|
||||
|
|
@ -669,7 +667,6 @@ func (s *LDBStore) CleanGCIndex() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
log.Debug("gc cleanup entries", "ok", okEntryCount, "total", totalEntryCount, "batchlen", batch.Len())
|
||||
|
|
|
|||
|
|
@ -761,6 +761,38 @@ func TestCleanIndex(t *testing.T) {
|
|||
t.Fatalf("expected sum of bin indices to be 3, was %d", binTotal)
|
||||
}
|
||||
}
|
||||
|
||||
// check that the iterator quits properly
|
||||
chunks, err = mputRandomChunks(ldb, 4100, 4096)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
po = ldb.po(chunks[4099].Address()[:])
|
||||
dataKey = make([]byte, 10)
|
||||
dataKey[0] = keyData
|
||||
dataKey[1] = byte(po)
|
||||
binary.BigEndian.PutUint64(dataKey[2:], 4099+3)
|
||||
if _, err := ldb.db.Get(dataKey); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ldb.db.Delete(dataKey); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := ldb.CleanGCIndex(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// entrycount should now be one less of added chunks
|
||||
c, err = ldb.db.Get(keyEntryCnt)
|
||||
if err != nil {
|
||||
t.Fatalf("expected gc 2 idx to be present: %v", idxKey)
|
||||
}
|
||||
entryCount = binary.BigEndian.Uint64(c)
|
||||
if entryCount != 4099+2 {
|
||||
t.Fatalf("expected entrycnt to be 2, was %d", c)
|
||||
}
|
||||
}
|
||||
|
||||
func waitGc(ctx context.Context, ldb *LDBStore) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue