Skip to content

Commit

Permalink
Fix concurrent cache write (#5623)
Browse files Browse the repository at this point in the history
Signed-off-by: Changxin Miao <[email protected]>
  • Loading branch information
polyrabbit authored Feb 10, 2025
1 parent 08d5d82 commit ab17da2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/chunk/disk_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ func (cache *cacheStore) cache(key string, p *Page, force, dropCache bool) {
if _, ok := cache.pages[key]; ok {
return
}
k := cache.getCacheKey(key)
if _, ok := cache.keys[k]; ok {
return
}
p.Acquire()
cache.pages[key] = p
atomic.AddInt64(&cache.totalPages, int64(cap(p.Data)))
Expand Down
2 changes: 1 addition & 1 deletion pkg/chunk/mem_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (c *memcache) load(key string) (ReadCloser, error) {
c.pages[key] = memItem{time.Now(), item.page}
return NewPageReader(item.page), nil
}
return nil, errors.New("not found")
return nil, errNotCached
}

func (c *memcache) exist(key string) (string, bool) {
Expand Down

0 comments on commit ab17da2

Please sign in to comment.