Skip to content

gitserver: support max retries for sg maintenance

Administrator requested to merge sh/sg-maintenance-retries into main

Created by: stefanhengl

So far, sg maintenance followed the same logic as git gc. If a log file (sgm.log or gc.log) is present and the repo is old enough, we reclone immediately.

However, recloning is expensive for monorepos and we want to avoid it as much as possible. Hence we switch sg maintenance to a different strategy.

Customers can now set the ENV var SRC_SGM_RETRIES which defines the number of times we retry sg maintenance before recloning. The default is "-1" which means "infinite".

This removes the tight coupling between repoTTLSGM and sgmLogExpire, which makes the process easier to reason about.

git gc remains unchanged to allow customers to fall back to the legacy setup.

Relates to https://github.com/sourcegraph/sourcegraph/pull/33432

Test plan

  • new unit test
  • manual testing:
    • Ran a local instance of Sourcegraph
    • corrupted a <repo> with touch ~/.sourcegraph/repos/github.com/<repo>/.git/refs/heads/deadbeaf
    • confirmed that sgm.log is created
    • confirmed that the counter increments
    • corrupted the sgm.log file and confirmed that the next cleanup run fixes the file with a count at 1
    • confirmed that the repo is recloned if failed > SRC_SGM_RETRIES
    • confirmed that sgm.log is gone and is not recreated

Merge request reports

Loading