Skip to content

Commit

Permalink
MerkleDB -- fix onEvictCache.Flush (ava-labs#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Laine authored Jun 6, 2023
1 parent 268f5a9 commit 00e61d8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions x/merkledb/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ func (c *onEvictCache[K, V]) Flush() error {
c.lock.Unlock()
}()

// Note that we can't use [c.fifo]'s iterator because [c.onEviction]
// modifies [c.fifo], which violates the iterator's invariant.
var errs wrappers.Errs
iter := c.fifo.NewIterator()
for iter.Next() {
errs.Add(c.onEviction(iter.Value()))
}
for {
_, node, exists := c.removeOldest()
if !exists {
// The cache is empty.
return errs.Err
}

return errs.Err
errs.Add(c.onEviction(node))
}
}

0 comments on commit 00e61d8

Please sign in to comment.