Skip to content

Commit 00e61d8

Browse files
author
Dan Laine
authored
MerkleDB -- fix onEvictCache.Flush (#1589)
1 parent 268f5a9 commit 00e61d8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

x/merkledb/cache.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,16 @@ func (c *onEvictCache[K, V]) Flush() error {
7171
c.lock.Unlock()
7272
}()
7373

74+
// Note that we can't use [c.fifo]'s iterator because [c.onEviction]
75+
// modifies [c.fifo], which violates the iterator's invariant.
7476
var errs wrappers.Errs
75-
iter := c.fifo.NewIterator()
76-
for iter.Next() {
77-
errs.Add(c.onEviction(iter.Value()))
78-
}
77+
for {
78+
_, node, exists := c.removeOldest()
79+
if !exists {
80+
// The cache is empty.
81+
return errs.Err
82+
}
7983

80-
return errs.Err
84+
errs.Add(c.onEviction(node))
85+
}
8186
}

0 commit comments

Comments
 (0)