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

disk-cache: disable state check when writeback enabled #4871

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion pkg/chunk/disk_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ func newCacheStore(m *cacheManagerMetrics, dir string, cacheSize int64, pendingP
opTs: make(map[time.Duration]func() error),
}
c.stateLock = sync.Mutex{}
c.state = newDCState(dcNormal, c)
if config.Writeback {
c.state = newDCState(dcUnchanged, c)
} else {
c.state = newDCState(dcNormal, c)
}

c.createDir(c.dir)
br, fr := c.curFreeRatio()
Expand Down
18 changes: 14 additions & 4 deletions pkg/chunk/disk_cache_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ var (
)

var diskStateNames = map[int]string{
dcUnknown: "unknown",
dcNormal: "normal",
dcUnstable: "unstable",
dcDown: "down",
dcUnknown: "unknown",
dcNormal: "normal",
dcUnstable: "unstable",
dcDown: "down",
dcUnchanged: "unchanged",
}

const (
dcUnknown = iota
dcNormal
dcUnstable
dcDown
dcUnchanged
)

const (
Expand Down Expand Up @@ -93,6 +95,8 @@ func newDCState(state int, cs *cacheStore) dcState {
s = &unstableDC{}
case dcDown:
s = &downDC{}
case dcUnchanged:
s = &unchangedDC{}
}
s.init(cs)
s.tick()
Expand All @@ -115,6 +119,12 @@ func (dc *baseDC) checkCacheOp() error { return nil }
func (dc *baseDC) beforeCacheOp() {}
func (dc *baseDC) afterCacheOp() {}

type unchangedDC struct {
baseDC
}

func (dc *unchangedDC) state() int { return dcUnchanged }

type normalDC struct {
baseDC
ioErrCnt uint32
Expand Down
Loading