Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MerkleDB -- fix onEvictCache.Flush #1589

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: previously we didn't remove the value - which meant that values that were iterated over here may have been written twice (in addition to having the iterator terminate early incorrectly)

}
for {
_, node, exists := c.removeOldest()
if !exists {
// The cache is empty.
return errs.Err
}

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