mirror of
https://github.com/kopia/kopia.git
synced 2026-05-24 14:44:47 -04:00
cache: prevent metadata cache thrashing if working set exceeds max defined size (#1557)
This is done by protecting newly added cache items from being swept for X amount of time where X defaults to: * `metadata` - 24 hours (new) * `data` - 10 min (new) * `indexes` - 1 hours (same as today) Fixes #1540
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
"github.com/kopia/kopia/internal/units"
|
||||
"github.com/kopia/kopia/repo"
|
||||
"github.com/kopia/kopia/repo/content"
|
||||
)
|
||||
|
||||
type commandCacheSetParams struct {
|
||||
@@ -15,6 +16,9 @@ type commandCacheSetParams struct {
|
||||
contentCacheSizeMB int64
|
||||
maxMetadataCacheSizeMB int64
|
||||
maxListCacheDuration time.Duration
|
||||
contentMinSweepAge time.Duration
|
||||
metadataMinSweepAge time.Duration
|
||||
indexMinSweepAge time.Duration
|
||||
|
||||
svc appServices
|
||||
}
|
||||
@@ -22,9 +26,16 @@ type commandCacheSetParams struct {
|
||||
func (c *commandCacheSetParams) setup(svc appServices, parent commandParent) {
|
||||
cmd := parent.Command("set", "Sets parameters local caching of repository data")
|
||||
|
||||
c.contentMinSweepAge = -1
|
||||
c.metadataMinSweepAge = -1
|
||||
c.indexMinSweepAge = -1
|
||||
|
||||
cmd.Flag("cache-directory", "Directory where to store cache files").StringVar(&c.directory)
|
||||
cmd.Flag("content-cache-size-mb", "Size of local content cache").PlaceHolder("MB").Default("-1").Int64Var(&c.contentCacheSizeMB)
|
||||
cmd.Flag("content-min-sweep-age", "Minimal age of content cache item to be subject to sweeping").DurationVar(&c.contentMinSweepAge)
|
||||
cmd.Flag("metadata-cache-size-mb", "Size of local metadata cache").PlaceHolder("MB").Default("-1").Int64Var(&c.maxMetadataCacheSizeMB)
|
||||
cmd.Flag("metadata-min-sweep-age", "Minimal age of metadata cache item to be subject to sweeping").DurationVar(&c.metadataMinSweepAge)
|
||||
cmd.Flag("index-min-sweep-age", "Minimal age of index cache item to be subject to sweeping").DurationVar(&c.indexMinSweepAge)
|
||||
cmd.Flag("max-list-cache-duration", "Duration of index cache").Default("-1ns").DurationVar(&c.maxListCacheDuration)
|
||||
cmd.Action(svc.repositoryWriterAction(c.run))
|
||||
c.svc = svc
|
||||
@@ -60,7 +71,25 @@ func (c *commandCacheSetParams) run(ctx context.Context, rep repo.RepositoryWrit
|
||||
|
||||
if v := c.maxListCacheDuration; v != -1 {
|
||||
log(ctx).Infof("changing list cache duration to %v", v)
|
||||
opts.MaxListCacheDurationSec = int(v.Seconds())
|
||||
opts.MaxListCacheDuration = content.DurationSeconds(v.Seconds())
|
||||
changed++
|
||||
}
|
||||
|
||||
if v := c.metadataMinSweepAge; v != -1 {
|
||||
log(ctx).Infof("changing minimum metadata sweep age to %v", v)
|
||||
opts.MinMetadataSweepAge = content.DurationSeconds(v.Seconds())
|
||||
changed++
|
||||
}
|
||||
|
||||
if v := c.contentMinSweepAge; v != -1 {
|
||||
log(ctx).Infof("changing minimum content sweep age to %v", v)
|
||||
opts.MinContentSweepAge = content.DurationSeconds(v.Seconds())
|
||||
changed++
|
||||
}
|
||||
|
||||
if v := c.indexMinSweepAge; v != -1 {
|
||||
log(ctx).Infof("changing minimum index sweep age to %v", v)
|
||||
opts.MinIndexSweepAge = content.DurationSeconds(v.Seconds())
|
||||
changed++
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user