top bug in cache refresh

This commit is contained in:
Todd Gruben 2017-02-17 15:18:38 -05:00
parent f8de3aeeea
commit 028539f10d
2 changed files with 12 additions and 6 deletions

View file

@ -22,6 +22,7 @@ type Cache interface {
// Updates the cache, if necessary.
Invalidate()
Refresh()
// Returns an ordered list of the top ranked bitmaps.
Top() []BitmapPair
@ -86,6 +87,8 @@ func (c *LRUCache) Top() []BitmapPair {
}
func (c *LRUCache) onEvicted(key lru.Key, _ interface{}) { delete(c.counts, key.(uint64)) }
func (c *LRUCache) Refresh() {
}
// Ensure LRUCache implements Cache.
var _ Cache = &LRUCache{}
@ -117,17 +120,17 @@ func (c *RankCache) Add(bitmapID uint64, n uint64) {
return
}
// Add to cache.
c.entries[bitmapID] = n
// If size is larger than the threshold then trim it.
if len(c.entries) > c.ThresholdLength {
c.update()
for id, n := range c.entries {
if n <= c.ThresholdValue {
delete(c.entries, id)
for id, n := range c.entries {
if n <= c.ThresholdValue {
delete(c.entries, id)
}
}
}
}
}
@ -154,6 +157,9 @@ func (c *RankCache) Invalidate() {
c.update()
}
}
func (c *RankCache) Refresh() {
c.update()
}
// update reorders the entries by rank.
func (c *RankCache) update() {

View file

@ -909,7 +909,7 @@ func (f *Fragment) Import(bitmapIDs, profileIDs []uint64) error {
f.cache.Add(bitmapID, f.bitmap(bitmapID).Count())
}
f.cache.Invalidate()
f.cache.Refresh()
return nil
}(); err != nil {
_ = f.closeStorage()