Skip to content

gitserver: add heuristics to skip maintenance job if possible

Administrator requested to merge sh/skip-maintenance-if-possible into main

Created by: stefanhengl

Running git-repack on every cleanup is very expensive. This adds heuristics similar to those used by git and GitLab's gitaly. The goal is to skip the maintenance job most of the time.

There is a caveat for repos with a lot of unreachable loose objects: If a repo has enough loose objects, we trigger a repack. If a lot of those loose objects are unreachable, they will remain loose after the repack. This means we run repack every time until those unreachable objects are eventually pruned. We address this issue by setting the retention time of unreachable, loose objects to 0.

I will add panels for the new metrics in a separate PR.

Test plan

  • added unit tests
  • ran a local instance of sourcegraph and
    • inspected the Prometheus metrics
    • checked timestamp of packfiles to see if a repack occured

Merge request reports

Loading