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

cleanup duplicated code #5173

Merged
merged 1 commit into from
Sep 20, 2024
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
33 changes: 5 additions & 28 deletions pkg/chunk/disk_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ func (cache *cacheStore) checkErr(f func() error) error {
if !cache.available() {
return errCacheDown
}
cache.state.beforeCacheOp()
defer cache.state.afterCacheOp()
if err := cache.state.checkCacheOp(); err != nil {
return err
}

start := utils.Clock()
cache.opMu.Lock()
Expand Down Expand Up @@ -373,11 +378,6 @@ func (cache *cacheStore) refreshCacheKeys() {
}

func (cache *cacheStore) removeStage(key string) error {
cache.state.beforeCacheOp()
defer cache.state.afterCacheOp()
if err := cache.state.checkCacheOp(); err != nil {
return err
}
var err error
if err = cache.removeFile(cache.stagePath(key)); err == nil {
cache.m.stageBlocks.Sub(1)
Expand All @@ -391,11 +391,6 @@ func (cache *cacheStore) removeStage(key string) error {
}

func (cache *cacheStore) cache(key string, p *Page, force, dropCache bool) {
cache.state.beforeCacheOp()
defer cache.state.afterCacheOp()
if cache.state.checkCacheOp() != nil {
return
}
if cache.capacity == 0 {
return
}
Expand Down Expand Up @@ -555,12 +550,6 @@ func (cache *cacheStore) getPathFromKey(k cacheKey) string {
}

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

cache.Lock()
delete(cache.pages, key)
path := cache.cachePath(key)
Expand Down Expand Up @@ -592,12 +581,6 @@ func (cache *cacheStore) remove(key string, staging bool) {
}

func (cache *cacheStore) load(key string) (ReadCloser, error) {
cache.state.beforeCacheOp()
defer cache.state.afterCacheOp()
if err := cache.state.checkCacheOp(); err != nil {
return nil, err
}

cache.Lock()
defer cache.Unlock()
if p, ok := cache.pages[key]; ok {
Expand Down Expand Up @@ -685,12 +668,6 @@ func (cache *cacheStore) add(key string, size int32, atime uint32) {

func (cache *cacheStore) stage(key string, data []byte, keepCache bool) (string, error) {
stagingPath := cache.stagePath(key)

cache.state.beforeCacheOp()
defer cache.state.afterCacheOp()
if err := cache.state.checkCacheOp(); err != nil {
return stagingPath, err
}
if cache.stageFull {
return stagingPath, errStageFull
}
Expand Down
Loading