dnfjson: cache cleanup
Added CleanCache() method to the solver that deletes all the caches if the total size grows above a certain (configurable) limit (default: 500 MiB). The function is called externally to handle errors (usually log or ignore completely) and to avoid calling multiple times for multiple depsolves of a single request. The cleanup is extremely simple and is meant as a placeholder for more sophisticated cache management. The goal is to simply avoid ballooning cache sizes that might cause issues for users or our own services.
This commit is contained in:
parent
8b4607c94f
commit
9fda1ff55f
6 changed files with 77 additions and 0 deletions
|
|
@ -143,6 +143,11 @@ func main() {
|
|||
solver := dnfjson.NewSolver(d.ModulePlatformID(), d.Releasever(), arch.Name(), path.Join(home, ".cache/osbuild-composer/rpmmd"))
|
||||
solver.SetDNFJSONPath(findDnfJsonBin())
|
||||
|
||||
// Set cache size to 3 GiB
|
||||
// osbuild-pipeline is often used to generate a lot of manifests in a row
|
||||
// let the cache grow to fit much more repository metadata than we usually allow
|
||||
solver.SetMaxCacheSize(3 * 1024 * 1024 * 1024)
|
||||
|
||||
packageSets := imageType.PackageSets(composeRequest.Blueprint, repos)
|
||||
depsolvedSets := make(map[string][]rpmmd.PackageSpec)
|
||||
|
||||
|
|
@ -189,4 +194,8 @@ func main() {
|
|||
}
|
||||
}
|
||||
os.Stdout.Write(bytes)
|
||||
if err := solver.CleanCache(); err != nil {
|
||||
// print to stderr but don't exit with error
|
||||
fmt.Fprintf(os.Stderr, "Error during rpm repo cache cleanup: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ func (impl *DepsolveJobImpl) depsolve(packageSets map[string][]rpmmd.PackageSet,
|
|||
}
|
||||
depsolvedSets[name] = res
|
||||
}
|
||||
|
||||
return depsolvedSets, nil
|
||||
}
|
||||
|
||||
|
|
@ -66,6 +67,10 @@ func (impl *DepsolveJobImpl) Run(job worker.Job) error {
|
|||
logWithId.Errorf("rpmmd error in depsolve job: %v", err)
|
||||
}
|
||||
}
|
||||
if err := impl.Solver.CleanCache(); err != nil {
|
||||
// log and ignore
|
||||
logWithId.Errorf("Error during rpm repo cache cleanup: %s", err.Error())
|
||||
}
|
||||
|
||||
err = job.Update(&result)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue