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:
Achilleas Koutsou 2022-05-30 18:32:44 +02:00 committed by Tom Gundersen
parent 8b4607c94f
commit 9fda1ff55f
6 changed files with 77 additions and 0 deletions

View file

@ -1272,6 +1272,10 @@ func (api *API) modulesInfoHandler(writer http.ResponseWriter, request *http.Req
}
packageInfos[i].Dependencies = solved
}
if err := solver.CleanCache(); err != nil {
// log and ignore
log.Printf("Error during rpm repo cache cleanup: %s", err.Error())
}
}
if modulesRequested {
@ -1348,6 +1352,10 @@ func (api *API) projectsDepsolveHandler(writer http.ResponseWriter, request *htt
statusResponseError(writer, http.StatusBadRequest, errors)
return
}
if err := solver.CleanCache(); err != nil {
// log and ignore
log.Printf("Error during rpm repo cache cleanup: %s", err.Error())
}
err = json.NewEncoder(writer).Encode(reply{Projects: deps})
common.PanicOnError(err)
}
@ -2148,6 +2156,10 @@ func (api *API) depsolveBlueprintForImageType(bp blueprint.Blueprint, imageType
}
depsolvedSets[name] = res
}
if err := solver.CleanCache(); err != nil {
// log and ignore
log.Printf("Error during rpm repo cache cleanup: %s", err.Error())
}
return depsolvedSets, nil
}
@ -3120,6 +3132,10 @@ func (api *API) fetchPackageList(distroName string) (rpmmd.PackageList, error) {
if err != nil {
return nil, err
}
if err := solver.CleanCache(); err != nil {
// log and ignore
log.Printf("Error during rpm repo cache cleanup: %s", err.Error())
}
return packages, nil
}
@ -3190,6 +3206,10 @@ func (api *API) depsolveBlueprint(bp blueprint.Blueprint) ([]rpmmd.PackageSpec,
return nil, err
}
if err := solver.CleanCache(); err != nil {
// log and ignore
log.Printf("Error during rpm repo cache cleanup: %s", err.Error())
}
return solved, nil
}