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

warmup: evict sub command may remove stage incorrectly #5095

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion pkg/chunk/cached_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ func (store *cachedStore) EvictCache(id uint64, length uint32) error {
r := sliceForRead(id, int(length), store)
keys := r.keys()
for _, k := range keys {
store.bcache.remove(k)
store.bcache.removeReadCache(k)
}
return nil
}
Expand Down
49 changes: 41 additions & 8 deletions pkg/chunk/disk_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,38 @@ func (cache *cacheStore) remove(key string) {
return
}

path := cache.doRemove(key)
if path != "" {
if err := cache.removeFile(path); err != nil && !os.IsNotExist(err) {
logger.Warnf("remove %s failed: %s", path, err)
}
if err := cache.removeStage(key); err != nil && !os.IsNotExist(err) {
logger.Warnf("remove stage %s failed: %s", cache.stagePath(key), err)
}
}
}

func (cache *cacheStore) removeReadCache(key string) {
cache.state.beforeCacheOp()
defer cache.state.afterCacheOp()
if cache.state.checkCacheOp() != nil {
return
}

// skip stage
if utils.Exists(cache.stagePath(key)) {
return
}

path := cache.doRemove(key)
if path != "" {
if err := cache.removeFile(path); err != nil && !os.IsNotExist(err) {
logger.Warnf("remove %s failed: %s", path, err)
}
}
}

func (cache *cacheStore) doRemove(key string) string {
cache.Lock()
delete(cache.pages, key)
path := cache.cachePath(key)
Expand All @@ -574,14 +606,7 @@ func (cache *cacheStore) remove(key string) {
path = "" // not existed
}
cache.Unlock()
if path != "" {
if err := cache.removeFile(path); err != nil && !os.IsNotExist(err) {
logger.Warnf("remove %s failed: %s", path, err)
}
if err := cache.removeStage(key); err != nil && !os.IsNotExist(err) {
logger.Warnf("remove %s failed: %s", cache.stagePath(key), err)
}
}
return path
}

func (cache *cacheStore) load(key string) (ReadCloser, error) {
Expand Down Expand Up @@ -1005,6 +1030,7 @@ func expandDir(pattern string) []string {
type CacheManager interface {
cache(key string, p *Page, force, dropCache bool)
remove(key string)
removeReadCache(key string) // remove read cache only
Copy link
Contributor

Choose a reason for hiding this comment

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

it's better to add a flag in remove(key)

load(key string) (ReadCloser, error)
uploaded(key string, size int)
stage(key string, data []byte, keepCache bool) (string, error)
Expand Down Expand Up @@ -1192,6 +1218,13 @@ func (m *cacheManager) remove(key string) {
}
}

func (m *cacheManager) removeReadCache(key string) {
store := m.getStore(key)
if store != nil {
store.removeReadCache(key)
}
}

func (m *cacheManager) stage(key string, data []byte, keepCache bool) (string, error) {
store := m.getStore(key)
if store != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/chunk/mem_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (c *memcache) remove(key string) {
}
}

func (c *memcache) removeReadCache(key string) {
c.remove(key)
}

func (c *memcache) load(key string) (ReadCloser, error) {
c.Lock()
defer c.Unlock()
Expand Down
Loading